Skip to content

Commit

Permalink
Add ENL
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Oct 6, 2023
1 parent c277d58 commit 739b536
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,12 @@ export class IndicatorCoefficientsDto {
@IsNotEmpty()
@IsNumber()
[INDICATOR_NAME_CODES.FLIL]: number;

@ApiPropertyOptional()
@IsOptional()
@Max(1000000)
@Min(0)
@IsNotEmpty()
@IsNumber()
[INDICATOR_NAME_CODES.ENL]: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class QueryPropertyTypes {
[INDICATOR_NAME_CODES.NL]: number;
[INDICATOR_NAME_CODES.FLIL]: number;
[INDICATOR_NAME_CODES.NCE]: number;
[INDICATOR_NAME_CODES.ENL]: number;
}

export const QueryPropertyNames: QueryPropertyNamesType = {
Expand Down Expand Up @@ -109,4 +110,12 @@ export const INDICATOR_NAME_CODE_TO_QUERY_MAP: {
[INDICATOR_NAME_CODES.FLIL]: (nameCode: INDICATOR_NAME_CODES) =>
`${get_annual_commodity_weighted_impact_over_georegion}($1, '${nameCode}', $2, 'producer') as "${INDICATOR_NAME_CODES.FLIL}"`,
},
[INDICATOR_NAME_CODES.ENL]: {
production: () =>
`sum_material_over_georegion($1, $2, 'producer') as "${QueryPropertyNames.production}"`,
[INDICATOR_NAME_CODES.ENL]: (nameCode: INDICATOR_NAME_CODES) =>
`${get_annual_commodity_weighted_impact_over_georegion}('${nameCode}', $3, $2) as "${INDICATOR_NAME_CODES.ENL}"`,
[INDICATOR_NAME_CODES.NL]: (nameCode: INDICATOR_NAME_CODES) =>
`${get_annual_commodity_weighted_impact_over_georegion}('${nameCode}', $3, $2) as "${INDICATOR_NAME_CODES.NL}"`,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ export class ImpactCalculator {
newIndicatorCoefficients[INDICATOR_NAME_CODES.UWU] *
sourcingData.tonnage,
);
const nutrientLoad: number = calculatedIndicatorValues.values.get(
INDICATOR_NAME_CODES.NL,
)!;
calculatedIndicatorValues.values.set(
INDICATOR_NAME_CODES.ENL,
nutrientLoad *
newIndicatorCoefficients[INDICATOR_NAME_CODES.ENL] *
sourcingData.tonnage,
);

return calculatedIndicatorValues;
}
Expand Down Expand Up @@ -362,7 +371,7 @@ export class ImpactCalculator {
return preProcessed * getLF();
},
[INDICATOR_NAME_CODES.WU]: () => {
return rawData[INDICATOR_NAME_CODES.WU] * tonnage ?? 0;
return rawData[INDICATOR_NAME_CODES.WU] * tonnage || 0;
},
[INDICATOR_NAME_CODES.UWU]: () => {
const waterUseValue: number =
Expand All @@ -375,6 +384,14 @@ export class ImpactCalculator {
[INDICATOR_NAME_CODES.NL]: () => {
return rawData[INDICATOR_NAME_CODES.NL] * tonnage || 0;
},
[INDICATOR_NAME_CODES.ENL]: () => {
const nutrientLoad: number =
rawData[INDICATOR_NAME_CODES.NL] * tonnage || 0;
return (
(rawData[INDICATOR_NAME_CODES.ENL] * nutrientLoad) /
(100 * rawData.production) || 0
);
},
};

for (const [key, value] of Object.entries(calculations)) {
Expand Down
3 changes: 1 addition & 2 deletions api/src/modules/indicators/indicator.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export enum INDICATOR_NAME_CODES {
NL = 'NL',
// GHG_FARM pending implementation
// GHG_FARM = 'GHG_FARM',
// MISSING COMPUTATION in notebook
// ENL = 'ENL',
ENL = 'ENL',
NCE = 'NCE',
FLIL = 'FLIL',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ describe('Impact Calculator Tests', () => {
[INDICATOR_NAME_CODES.NL]: 0.7,
[INDICATOR_NAME_CODES.NCE]: 0.4,
[INDICATOR_NAME_CODES.FLIL]: 0.3,
[INDICATOR_NAME_CODES.ENL]: 0.1,
};

//ACT
Expand Down

0 comments on commit 739b536

Please sign in to comment.