Skip to content

Commit

Permalink
chore(indicatorrecord): Adds a feature toggle to indicator record cal…
Browse files Browse the repository at this point in the history
…culation

Now, wether the old stored functions, or the new API generated SQL queries are used for the calculations of indicator records at import time, is toggable via environment variable, SIMPLE_IMPORT_CALCULATIONS
  • Loading branch information
KevSanchez committed Aug 30, 2022
1 parent 4b15ffa commit 8fa4631
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
3 changes: 3 additions & 0 deletions api/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@
},
"map": {
"distributed": "DISTRIBUTED_MAP"
},
"featureFlags": {
"simpleImportCalculations": "SIMPLE_IMPORT_CALCULATIONS"
}
}
3 changes: 3 additions & 0 deletions api/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@

"map": {
"distributed": true
},
"featureFlags": {
"simpleImportCalculations": "false"
}
}
3 changes: 3 additions & 0 deletions api/config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
},
"geolocation": {
"gmapsApiKey": "myVeryBadJWTSecretForTests"
},
"featureFlags": {
"simpleImportCalculations": "true"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ export class IndicatorRecordsService extends AppBaseService<
INDICATOR_TYPES.BIODIVERSITY_LOSS,
];

const rawData: SourcingRecordsWithIndicatorRawDataDto[] =
//await this.indicatorRecordRepository.getIndicatorRawDataForAllSourcingRecords();
await this.impactCalculatorService.calculateAllSourcingRecords();
const rawData: SourcingRecordsWithIndicatorRawDataDto[] = config.get(
'featureFlags.simpleImportCalculations',
)
? await this.indicatorRecordRepository.getIndicatorRawDataForAllSourcingRecords()
: await this.impactCalculatorService.calculateAllSourcingRecords();

const calculatedData2: IndicatorRecordCalculatedValuesDto[] = rawData.map(
(sourcingRecordData: SourcingRecordsWithIndicatorRawDataDto) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,10 @@ describe('Indicator Records Service', () => {
expect(indicatorRecords.length).toEqual(1);
expect(indicatorRecords[0].sourcingRecordId).toEqual(sourcingRecordId);
expect(indicatorRecords[0].status).toEqual(INDICATOR_RECORD_STATUS.SUCCESS);
expect(indicatorRecords[0].value).toEqual(recordValue);
expect(indicatorRecords[0].scaler).toEqual(scalerValue);
expect(indicatorRecords[0].value).toBeCloseTo(recordValue, 5);
if (scalerValue) {
expect(indicatorRecords[0].scaler).toBeCloseTo(scalerValue, 5);
}
expect(indicatorRecords[0].materialH3DataId).toEqual(
materialH3Data.h3DataId,
);
Expand All @@ -843,7 +845,7 @@ describe('Indicator Records Service', () => {
expect(cachedData).toBeDefined();
expect(cachedData?.data).toBeDefined();
expect(cachedData?.type).toEqual(type);
expect((cachedData?.data as CachedRawValue).rawValue).toEqual(value);
expect((cachedData?.data as CachedRawValue).rawValue).toBeCloseTo(value, 5);
}

async function createPreconditions(): Promise<any> {
Expand Down

0 comments on commit 8fa4631

Please sign in to comment.