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 03922a8adc..1b28604163 100644 --- a/api/src/modules/indicator-coefficients/dto/indicator-coefficients.dto.ts +++ b/api/src/modules/indicator-coefficients/dto/indicator-coefficients.dto.ts @@ -73,4 +73,12 @@ export class IndicatorCoefficientsDto { @IsNotEmpty() @IsNumber() [INDICATOR_NAME_CODES.ENL]: number; + + @ApiPropertyOptional() + @IsOptional() + @Max(1000000) + @Min(0) + @IsNotEmpty() + @IsNumber() + [INDICATOR_NAME_CODES.GHG_FARM]: 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 2038a151d1..d91aec8b6a 100644 --- a/api/src/modules/indicator-records/services/impact-calculation.dependencies.ts +++ b/api/src/modules/indicator-records/services/impact-calculation.dependencies.ts @@ -22,6 +22,7 @@ export class QueryPropertyNamesType { [INDICATOR_NAME_CODES.NL]: INDICATOR_NAME_CODES.NL; [INDICATOR_NAME_CODES.NCE]: INDICATOR_NAME_CODES.NCE; [INDICATOR_NAME_CODES.FLIL]: INDICATOR_NAME_CODES.FLIL; + [INDICATOR_NAME_CODES.GHG_FARM]: INDICATOR_NAME_CODES.GHG_FARM; } export class QueryPropertyTypes { @@ -36,6 +37,7 @@ export class QueryPropertyTypes { [INDICATOR_NAME_CODES.FLIL]: number; [INDICATOR_NAME_CODES.NCE]: number; [INDICATOR_NAME_CODES.ENL]: number; + [INDICATOR_NAME_CODES.GHG_FARM]: number; } export const QueryPropertyNames: QueryPropertyNamesType = { @@ -49,6 +51,7 @@ export const QueryPropertyNames: QueryPropertyNamesType = { [INDICATOR_NAME_CODES.NL]: INDICATOR_NAME_CODES.NL, [INDICATOR_NAME_CODES.NCE]: INDICATOR_NAME_CODES.NCE, [INDICATOR_NAME_CODES.FLIL]: INDICATOR_NAME_CODES.FLIL, + [INDICATOR_NAME_CODES.GHG_FARM]: INDICATOR_NAME_CODES.GHG_FARM, } as const; export type ImpactQueryPropertyName = @@ -56,9 +59,7 @@ export type ImpactQueryPropertyName = export type ImpactQueryExpression = string; -export type ImpactPropertyToQueryFunction = - | ((nameCode: INDICATOR_NAME_CODES) => ImpactQueryExpression) - | (() => ImpactQueryExpression); +export type ImpactPropertyToQueryFunction = () => ImpactQueryExpression; export const INDICATOR_NAME_CODE_TO_QUERY_MAP: { [key in INDICATOR_NAME_CODES]: { @@ -74,32 +75,32 @@ export const INDICATOR_NAME_CODE_TO_QUERY_MAP: { [INDICATOR_NAME_CODES.DF_SLUC]: { production: () => `sum_material_over_georegion($1, $2, 'producer') as "${QueryPropertyNames.production}"`, - [INDICATOR_NAME_CODES.DF_SLUC]: (nameCode: INDICATOR_NAME_CODES) => + [INDICATOR_NAME_CODES.DF_SLUC]: () => `${get_annual_commodity_weighted_impact_over_georegion}($1, '${INDICATOR_NAME_CODES.DF_SLUC}', $2, 'producer') as "${INDICATOR_NAME_CODES.DF_SLUC}"`, }, [INDICATOR_NAME_CODES.GHG_DEF_SLUC]: { production: () => `sum_material_over_georegion($1, $2, 'producer') as "${QueryPropertyNames.production}"`, - [INDICATOR_NAME_CODES.GHG_DEF_SLUC]: (nameCode: INDICATOR_NAME_CODES) => + [INDICATOR_NAME_CODES.GHG_DEF_SLUC]: () => `${get_annual_commodity_weighted_impact_over_georegion}($1,'${INDICATOR_NAME_CODES.GHG_DEF_SLUC}', $2, 'producer') as "${INDICATOR_NAME_CODES.GHG_DEF_SLUC}"`, }, [INDICATOR_NAME_CODES.UWU]: { - [INDICATOR_NAME_CODES.UWU]: (nameCode: INDICATOR_NAME_CODES) => + [INDICATOR_NAME_CODES.UWU]: () => `${get_annual_commodity_weighted_impact_over_georegion}($1,'${INDICATOR_NAME_CODES.UWU}', $2, 'producer') as "${INDICATOR_NAME_CODES.UWU}"`, }, [INDICATOR_NAME_CODES.WU]: { - [INDICATOR_NAME_CODES.WU]: (nameCode: INDICATOR_NAME_CODES) => + [INDICATOR_NAME_CODES.WU]: () => `${get_indicator_coefficient_impact}('${INDICATOR_NAME_CODES.WU}', $3, $2) as "${INDICATOR_NAME_CODES.WU}"`, }, [INDICATOR_NAME_CODES.NL]: { - [INDICATOR_NAME_CODES.NL]: (nameCode: INDICATOR_NAME_CODES) => + [INDICATOR_NAME_CODES.NL]: () => `${get_indicator_coefficient_impact}('${INDICATOR_NAME_CODES.NL}', $3, $2) as "${INDICATOR_NAME_CODES.NL}"`, }, [INDICATOR_NAME_CODES.NCE]: { production: () => `sum_material_over_georegion($1, $2, 'producer') as "${QueryPropertyNames.production}"`, - [INDICATOR_NAME_CODES.NCE]: (nameCode: INDICATOR_NAME_CODES) => + [INDICATOR_NAME_CODES.NCE]: () => `${get_annual_commodity_weighted_impact_over_georegion}($1, '${INDICATOR_NAME_CODES.NCE}', $2, 'producer') as "${INDICATOR_NAME_CODES.NCE}"`, }, [INDICATOR_NAME_CODES.FLIL]: { @@ -107,15 +108,23 @@ export const INDICATOR_NAME_CODE_TO_QUERY_MAP: { `sum_material_over_georegion($1, $2, 'producer') as "${QueryPropertyNames.production}"`, harvest: () => `sum_material_over_georegion($1, $2, 'harvest') as "${QueryPropertyNames.harvest}"`, - [INDICATOR_NAME_CODES.FLIL]: (nameCode: INDICATOR_NAME_CODES) => + [INDICATOR_NAME_CODES.FLIL]: () => `${get_annual_commodity_weighted_impact_over_georegion}($1, '${INDICATOR_NAME_CODES.FLIL}', $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) => + [INDICATOR_NAME_CODES.ENL]: () => `${get_annual_commodity_weighted_impact_over_georegion}($1, '${INDICATOR_NAME_CODES.ENL}', $2, 'producer') as "${INDICATOR_NAME_CODES.ENL}"`, - [INDICATOR_NAME_CODES.NL]: (nameCode: INDICATOR_NAME_CODES) => + [INDICATOR_NAME_CODES.NL]: () => `${get_indicator_coefficient_impact}('${INDICATOR_NAME_CODES.NL}', $3, $2) as "${INDICATOR_NAME_CODES.NL}"`, }, + [INDICATOR_NAME_CODES.GHG_FARM]: { + production: () => + `sum_material_over_georegion($1, $2, 'producer') as "${QueryPropertyNames.production}"`, + harvest: () => + `sum_material_over_georegion($1, $2, 'harvest') as "${QueryPropertyNames.harvest}"`, + [INDICATOR_NAME_CODES.GHG_FARM]: () => + `${get_annual_commodity_weighted_impact_over_georegion}($1, '${INDICATOR_NAME_CODES.GHG_FARM}', $2, 'producer') as "${INDICATOR_NAME_CODES.GHG_FARM}"`, + }, }; 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 3f8934de5e..257c294c60 100644 --- a/api/src/modules/indicator-records/services/impact-calculator.service.ts +++ b/api/src/modules/indicator-records/services/impact-calculator.service.ts @@ -370,6 +370,12 @@ export class ImpactCalculator { const preProcessed: number = getPreprocessed(INDICATOR_NAME_CODES.FLIL); return preProcessed * getLF(); }, + [INDICATOR_NAME_CODES.GHG_FARM]: () => { + const preProcessed: number = getPreprocessed( + INDICATOR_NAME_CODES.GHG_FARM, + ); + return preProcessed * getLF(); + }, [INDICATOR_NAME_CODES.WU]: () => { return rawData[INDICATOR_NAME_CODES.WU] * tonnage || 0; }, diff --git a/api/src/modules/indicators/indicator.entity.ts b/api/src/modules/indicators/indicator.entity.ts index 41fa874460..721094e127 100644 --- a/api/src/modules/indicators/indicator.entity.ts +++ b/api/src/modules/indicators/indicator.entity.ts @@ -27,8 +27,7 @@ export enum INDICATOR_NAME_CODES { WU = 'WU', UWU = 'UWU', NL = 'NL', - // GHG_FARM pending implementation - // GHG_FARM = 'GHG_FARM', + GHG_FARM = 'GHG_FARM', ENL = 'ENL', NCE = 'NCE', FLIL = 'FLIL',