Skip to content

Commit

Permalink
add distributed impact use for UWU and ENL
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Feb 24, 2025
1 parent bb84890 commit 3c07b56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,23 @@ export class ImpactCalculator {
[INDICATOR_NAME_CODES.UWU]: () => {
const waterUseValue: number =
rawData[INDICATOR_NAME_CODES.WU] * tonnage;
return (
(rawData[INDICATOR_NAME_CODES.UWU] * waterUseValue) /
(100 * rawData.production) || 0
);
return rawData.production > 0
? (rawData[INDICATOR_NAME_CODES.UWU] * waterUseValue) /
(100 * rawData.production) || 0
: (rawData.distributedImpact?.[INDICATOR_NAME_CODES.UWU] ?? 0) *
(waterUseValue / 100) || 0;
},
[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
);
return rawData.production > 0
? (rawData[INDICATOR_NAME_CODES.ENL] * nutrientLoad) /
(100 * rawData.production) || 0
: (rawData.distributedImpact?.[INDICATOR_NAME_CODES.ENL] ?? 0) *
(nutrientLoad / 100) || 0;
},
[INDICATOR_NAME_CODES.WW]: () => {
return rawData[INDICATOR_NAME_CODES.WW] * tonnage || 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('ImpactCalculator.updateDistributedImpactOverGeoRegion', () => {

// Define the indicators to use
const activeIndicators = [
{ nameCode: INDICATOR_NAME_CODES.WGUWU },
{ nameCode: INDICATOR_NAME_CODES.ENL },
{ nameCode: INDICATOR_NAME_CODES.WU },
] as Indicator[];

Expand Down Expand Up @@ -141,8 +141,7 @@ describe('ImpactCalculator.updateDistributedImpactOverGeoRegion', () => {
recordsWithDistributedImpact.forEach(
(record: SourcingRecordsWithIndicatorRawData) => {
expect(record.distributedImpact).toEqual({
[INDICATOR_NAME_CODES.WGUWU]: 42,
[INDICATOR_NAME_CODES.WU]: 42,
[INDICATOR_NAME_CODES.ENL]: 42,
});
},
);
Expand Down

0 comments on commit 3c07b56

Please sign in to comment.