diff --git a/api/src/migrations/1695954091382-AddNewImpactStoredProcedure.ts b/api/src/migrations/1695954091382-AddNewImpactStoredProcedure.ts index 234f320f69..aa53e9e68e 100644 --- a/api/src/migrations/1695954091382-AddNewImpactStoredProcedure.ts +++ b/api/src/migrations/1695954091382-AddNewImpactStoredProcedure.ts @@ -57,8 +57,8 @@ LANGUAGE plpgsql; await queryRunner.query(` CREATE OR REPLACE FUNCTION get_indicator_coefficient_impact( - nameCode text, - adminRegionId uuid, + name_code text, + admin_region_id uuid, material_id uuid) RETURNS float AS $$ @@ -69,7 +69,7 @@ LANGUAGE plpgsql; --get indicatorId SELECT "id" INTO indicator_id FROM "indicator" - WHERE "nameCode" = nameCode; + WHERE "nameCode" = name_code; -- get water footprint value by location, material and indicator EXECUTE format( @@ -93,7 +93,7 @@ LANGUAGE plpgsql; ) ) AS value;' ) - USING adminRegionId, material_id, indicator_id + USING admin_region_id, material_id, indicator_id INTO value; RETURN value; END; diff --git a/api/src/modules/indicator-records/dto/indicator-record-calculated-values.dto.ts b/api/src/modules/indicator-records/dto/indicator-record-calculated-values.dto.ts index 758852ec4a..93ab81458d 100644 --- a/api/src/modules/indicator-records/dto/indicator-record-calculated-values.dto.ts +++ b/api/src/modules/indicator-records/dto/indicator-record-calculated-values.dto.ts @@ -9,8 +9,5 @@ export class IndicatorRecordCalculatedValuesDto { sourcingRecordId: string; production: number; materialH3DataId: string; - - landPerTon: number; - landUse: number; values: Map; } 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..83fa487b9e 100644 --- a/api/src/modules/indicator-records/services/impact-calculator.service.ts +++ b/api/src/modules/indicator-records/services/impact-calculator.service.ts @@ -268,59 +268,13 @@ export class ImpactCalculator { calculatedIndicatorValues.sourcingRecordId = sourcingData.sourcingRecordId; calculatedIndicatorValues.materialH3DataId = materialH3DataId; calculatedIndicatorValues.values = new Map(); - calculatedIndicatorValues.values.set( - INDICATOR_NAME_CODES.LF, - newIndicatorCoefficients[INDICATOR_NAME_CODES.LF] * - sourcingData.tonnage || 0, - ); - calculatedIndicatorValues.values.set( - INDICATOR_NAME_CODES.DF_SLUC, - newIndicatorCoefficients[INDICATOR_NAME_CODES.DF_SLUC] * - sourcingData.tonnage || 0, - ); - calculatedIndicatorValues.values.set( - INDICATOR_NAME_CODES.GHG_DEF_SLUC, - newIndicatorCoefficients[INDICATOR_NAME_CODES.GHG_DEF_SLUC] * - sourcingData.tonnage || 0, - ); - calculatedIndicatorValues.values.set( - INDICATOR_NAME_CODES.WU, - newIndicatorCoefficients[INDICATOR_NAME_CODES.WU] * - sourcingData.tonnage || 0, - ); - calculatedIndicatorValues.values.set( - INDICATOR_NAME_CODES.NL, - newIndicatorCoefficients[INDICATOR_NAME_CODES.NL] * - sourcingData.tonnage || 0, - ); - calculatedIndicatorValues.values.set( - INDICATOR_NAME_CODES.NCE, - newIndicatorCoefficients[INDICATOR_NAME_CODES.NCE] * - sourcingData.tonnage || 0, - ); - calculatedIndicatorValues.values.set( - INDICATOR_NAME_CODES.FLIL, - newIndicatorCoefficients[INDICATOR_NAME_CODES.FLIL] * - sourcingData.tonnage || 0, - ); - const waterUseValue: number = calculatedIndicatorValues.values.get( - INDICATOR_NAME_CODES.WU, - )!; - calculatedIndicatorValues.values.set( - INDICATOR_NAME_CODES.UWU, - waterUseValue * - 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 || 0, - ); + Object.keys(INDICATOR_NAME_CODES).forEach((nameCode: string) => { + calculatedIndicatorValues.values.set( + nameCode as INDICATOR_NAME_CODES, + newIndicatorCoefficients[nameCode as INDICATOR_NAME_CODES] * + sourcingData.tonnage || 0, + ); + }); return calculatedIndicatorValues; }