diff --git a/api/src/modules/indicator-coefficients/dto/indicator-coefficients.dto.ts b/api/src/modules/indicator-coefficients/dto/indicator-coefficients.dto.ts index 9f37d6d06..03922a8ad 100644 --- a/api/src/modules/indicator-coefficients/dto/indicator-coefficients.dto.ts +++ b/api/src/modules/indicator-coefficients/dto/indicator-coefficients.dto.ts @@ -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; } diff --git a/api/src/modules/indicator-records/services/impact-calculation.dependencies.ts b/api/src/modules/indicator-records/services/impact-calculation.dependencies.ts index c079d5863..24d03bc3e 100644 --- a/api/src/modules/indicator-records/services/impact-calculation.dependencies.ts +++ b/api/src/modules/indicator-records/services/impact-calculation.dependencies.ts @@ -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 = { @@ -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}"`, + }, }; diff --git a/api/src/modules/indicator-records/services/impact-calculator.service.ts b/api/src/modules/indicator-records/services/impact-calculator.service.ts index 1cc95a2fa..a28f37037 100644 --- a/api/src/modules/indicator-records/services/impact-calculator.service.ts +++ b/api/src/modules/indicator-records/services/impact-calculator.service.ts @@ -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; } @@ -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 = @@ -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)) { diff --git a/api/src/modules/indicators/indicator.entity.ts b/api/src/modules/indicators/indicator.entity.ts index 69d94ad60..bcf25a046 100644 --- a/api/src/modules/indicators/indicator.entity.ts +++ b/api/src/modules/indicators/indicator.entity.ts @@ -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', } diff --git a/api/test/integration/indicator-record/calculations/indicator-records.service.spec.ts b/api/test/integration/indicator-record/calculations/indicator-records.service.spec.ts index b59d80795..14523866c 100644 --- a/api/test/integration/indicator-record/calculations/indicator-records.service.spec.ts +++ b/api/test/integration/indicator-record/calculations/indicator-records.service.spec.ts @@ -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