Skip to content

Commit

Permalink
add WW and WC value processing to impact-calculator.service.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Dec 13, 2024
1 parent b037cef commit 1dd95b6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@ export class ImpactCalculator {
(100 * rawData.production) || 0
);
},
[INDICATOR_NAME_CODES.WW]: () => {
return rawData[INDICATOR_NAME_CODES.WU] * tonnage || 0;
},
[INDICATOR_NAME_CODES.WC]: () => {
return rawData[INDICATOR_NAME_CODES.WU] * tonnage || 0;
},
};

for (const [key, value] of Object.entries(calculations)) {
Expand Down Expand Up @@ -423,39 +429,35 @@ export class ImpactCalculator {
// indicator value calculation has not been refactored. It remains to be reworked
const response: any = await this.dataSource.query(
`
SELECT
-- TODO: Hack to retrieve 1 materialH3Id for each sourcingRecord. This should include a year fallback strategy in the stored procedures
-- used below
distinct on (sr.id)
sr.id as "sourcingRecordId",
sr.tonnage,
sr.year,
slwithmaterialh3data.id as "sourcingLocationId",
slwithmaterialh3data."materialH3DataId",
${params}
FROM
sourcing_records sr
INNER JOIN
(
SELECT
sourcing_location.id,
"scenarioInterventionId",
"interventionType",
mth."h3DataId" as "materialH3DataId",
${query}
FROM
sourcing_location
inner join
material_to_h3 mth
on
mth."materialId" = sourcing_location."materialId"
WHERE "scenarioInterventionId" IS NULL
AND "interventionType" IS NULL
and mth."type" = 'producer'
) as slwithmaterialh3data
on sr."sourcingLocationId" = slwithmaterialh3data.id`,
SELECT
-- TODO: Hack to retrieve 1 materialH3Id for each sourcingRecord. This should include a year fallback strategy in the stored procedures
-- used below
distinct
on (sr.id)
sr.id as "sourcingRecordId",
sr.tonnage,
sr.year,
slwithmaterialh3data.id as "sourcingLocationId",
slwithmaterialh3data."materialH3DataId",
${params}
FROM
sourcing_records sr
INNER JOIN
(
SELECT
sourcing_location.id, "scenarioInterventionId", "interventionType", mth."h3DataId" as "materialH3DataId", ${query}
FROM
sourcing_location
inner join
material_to_h3 mth
on
mth."materialId" = sourcing_location."materialId"
WHERE "scenarioInterventionId" IS NULL
AND "interventionType" IS NULL
and mth."type" = 'producer'
) as slwithmaterialh3data
on sr."sourcingLocationId" = slwithmaterialh3data.id`,
);
if (!response.length)
this.logger.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ describe('Impact Calculator Tests', () => {
[INDICATOR_NAME_CODES.FLIL]: 0.3,
[INDICATOR_NAME_CODES.ENL]: 0.1,
[INDICATOR_NAME_CODES.GHG_FARM]: 0.2,
[INDICATOR_NAME_CODES.WW]: 0.3,
[INDICATOR_NAME_CODES.WC]: 0.4,
};

//ACT
Expand Down

0 comments on commit 1dd95b6

Please sign in to comment.