Skip to content

Commit

Permalink
fix(Impact Maps): Division by 0 on Relative comparison maps
Browse files Browse the repository at this point in the history
Fixes the way the relative difference is calculated so that no division by 0 occurs because of the sum of negative and relative values
  • Loading branch information
KevSanchez committed Nov 25, 2022
1 parent a08ea4d commit f0e7f1f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api/src/modules/h3-data/h3-data-map.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class H3DataMapRepository extends Repository<H3Data> {

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

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

0 comments on commit f0e7f1f

Please sign in to comment.