Skip to content

Commit f0e7f1f

Browse files
committed
fix(Impact Maps): Division by 0 on Relative comparison maps
Fixes the way the relative difference is calculated so that no division by 0 occurs because of the sum of negative and relative values
1 parent a08ea4d commit f0e7f1f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

api/src/modules/h3-data/h3-data-map.repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class H3DataMapRepository extends Repository<H3Data> {
213213

214214
if (dto.relative) {
215215
// TODO "edge" case when sumDataWithoutScenario is 0, the result will always be 200%, pending to search for a more accurate formula by Elena
216-
aggregateExpression = `100 * ( ${sumDataWithScenario} - ${sumDataWithoutScenario}) / ( ( ${sumDataWithScenario} + ${sumDataWithoutScenario} ) / 2 ) / ir.scaler `;
216+
aggregateExpression = `100 * ( ABS(${sumDataWithScenario}) - ABS(${sumDataWithoutScenario}) ) / ( ( ABS(${sumDataWithScenario}) + ABS(${sumDataWithoutScenario}) ) / 2 ) / ir.scaler `;
217217
} else {
218218
aggregateExpression = `( ${sumDataWithScenario} - ${sumDataWithoutScenario} ) / ir.scaler `;
219219
}
@@ -270,7 +270,7 @@ export class H3DataMapRepository extends Repository<H3Data> {
270270

271271
if (dto.relative) {
272272
// TODO "edge" case when sumDataWithoutScenario is 0, the result will always be 200%, pending to search for a more accurate formula by Elena
273-
aggregateExpression = `100 * (${sumDataWitComparedScenario} - ${sumDataWithBaseScenario}) / ( ( ${sumDataWitComparedScenario} + ${sumDataWithBaseScenario} ) / 2 ) / ir.scaler `;
273+
aggregateExpression = `100 * ( ABS(${sumDataWitComparedScenario}) - ABS(${sumDataWithBaseScenario}) ) / ( ( ABS(${sumDataWitComparedScenario}) + ABS(${sumDataWithBaseScenario}) ) / 2 ) / ir.scaler `;
274274
} else {
275275
aggregateExpression = `( ${sumDataWitComparedScenario} - ${sumDataWithBaseScenario} ) / ir.scaler `;
276276
}

0 commit comments

Comments
 (0)