Skip to content

Commit

Permalink
Fix indicator name and code
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Aug 28, 2023
1 parent baa900e commit 8b78189
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ export class IndicatorCoefficientsDto {
@Min(0)
@IsNotEmpty()
@IsNumber()
[INDICATOR_NAME_CODES.WATER_QUALITY_RISK]: number;
[INDICATOR_NAME_CODES.WATER_QUALITY]: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const INDICATOR_NAME_CODE_TO_QUERY_MAP: {
rawGHGEmissions: (nameCode: INDICATOR_NAME_CODES) =>
`get_annual_landscape_impact_over_georegion($1,'${nameCode}', $2, 'producer') as "${QueryPropertyNames.rawGHGEmissions}"`,
},
[INDICATOR_NAME_CODES.WATER_QUALITY_RISK]: {
[INDICATOR_NAME_CODES.WATER_QUALITY]: {
rawWaterQuality: (nameCode: INDICATOR_NAME_CODES) =>
`get_indicator_coefficient_impact('${nameCode}', $3, $2) as "${QueryPropertyNames.rawWaterQuality}"`,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { IndicatorRecordRepository } from 'modules/indicator-records/indicator-r
import { SourcingRecordsWithIndicatorRawData } from 'modules/sourcing-records/dto/sourcing-records-with-indicator-raw-data.dto';
import {
Indicator,
INDICATOR_STATUS,
INDICATOR_NAME_CODES,
INDICATOR_STATUS,
} from 'modules/indicators/indicator.entity';
import { DataSource } from 'typeorm';
import {
Expand Down Expand Up @@ -345,20 +345,22 @@ export class ImpactCalculator {
const waterUse: number = rawData.rawWaterUse * tonnage;
const unsustainableWaterUse: number =
waterUse * rawData.rawUnsustainableWaterUse;
const waterQuality: number = rawData.rawWaterQuality * tonnage;

const map: Map<INDICATOR_NAME_CODES, number> = new Map();
map.set(INDICATOR_NAME_CODES.CLIMATE_RISK, climateRisk);
map.set(INDICATOR_NAME_CODES.DEFORESTATION_RISK, deforestation);
map.set(INDICATOR_NAME_CODES.WATER_USE, waterUse);
map.set(INDICATOR_NAME_CODES.CLIMATE_RISK, climateRisk);
map.set(
INDICATOR_NAME_CODES.NATURAL_ECOSYSTEM_CONVERSION_RISK,
naturalRisk,
);
map.set(
INDICATOR_NAME_CODES.UNSUSTAINABLE_WATER_USE,
unsustainableWaterUse,
);
map.set(INDICATOR_NAME_CODES.WATER_USE, waterUse);
map.set(INDICATOR_NAME_CODES.WATER_QUALITY, waterQuality);
map.set(INDICATOR_NAME_CODES.LAND_USE, landUse);
map.set(
INDICATOR_NAME_CODES.NATURAL_ECOSYSTEM_CONVERSION_RISK,
naturalRisk,
);
map.set(
INDICATOR_NAME_CODES.SATELLIGENCE_DEFORESTATION,
rawData.satDeforestation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class IndicatorQueryDependencyManager {
queries.push(querySegment);
}
}
console.log(queries);
return [...new Set(queries)].join(', ');
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/modules/indicators/indicator.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export enum INDICATOR_NAME_CODES {
WATER_USE = 'UWU_T',
UNSUSTAINABLE_WATER_USE = 'UWUSR_T',
NATURAL_ECOSYSTEM_CONVERSION_RISK = 'NECR',
WATER_QUALITY_RISK = 'WQR',
WATER_QUALITY = 'WQ',
SATELLIGENCE_DEFORESTATION = 'SAT_DF',
SATELLIGENCE_DEFORESTATION_RISK = 'SAT_DF_R',
}
Expand Down
9 changes: 7 additions & 2 deletions api/test/entity-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { Material, MATERIALS_STATUS } from 'modules/materials/material.entity';
import { Supplier } from 'modules/suppliers/supplier.entity';
import { SourcingRecord } from 'modules/sourcing-records/sourcing-record.entity';
import { IndicatorRecord } from 'modules/indicator-records/indicator-record.entity';
import { Indicator } from 'modules/indicators/indicator.entity';
import {
Indicator,
INDICATOR_NAME_CODES,
} from 'modules/indicators/indicator.entity';
import { SourcingLocation } from 'modules/sourcing-locations/sourcing-location.entity';
import { SourcingLocationGroup } from 'modules/sourcing-location-groups/sourcing-location-group.entity';
import { Unit } from 'modules/units/unit.entity';
Expand Down Expand Up @@ -426,7 +429,9 @@ async function createTarget(
): Promise<Target> {
const indicator: Indicator = await createIndicator({
name: (Math.random() + 1).toString(30).substring(6),
nameCode: (Math.random() + 1).toString(30).substring(6),
nameCode: (Math.random() + 1)
.toString(30)
.substring(6) as INDICATOR_NAME_CODES,
});
const defaultData: DeepPartial<Target> = {
baseLineYear: 2020,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ describe('Impact Calculator Tests', () => {
[INDICATOR_NAME_CODES.WATER_USE]: 0.6,
[INDICATOR_NAME_CODES.SATELLIGENCE_DEFORESTATION]: 0.3,
[INDICATOR_NAME_CODES.SATELLIGENCE_DEFORESTATION_RISK]: 0.5,
[INDICATOR_NAME_CODES.NATURAL_ECOSYSTEM_CONVERSION_RISK]: 0.7,
[INDICATOR_NAME_CODES.WATER_QUALITY]: 0.8,
};

//ACT
Expand Down

0 comments on commit 8b78189

Please sign in to comment.