Similar code was used in the function calculateTotalAmount(). This code is not correct and gives wrong results when the startTimeSlot is also the endTimeSlot.
Steps to Reproduce
Just observe the Dashboard. The total on the donut, 110,5 tCO2eq is supposedly equal to sum of the 24 monthly consumptions on the bar chart. But even a single bar is labeled in ktCO2eq. Considering emission flows of roughly 0.002 kgCO2eq/s and 2600000s/month the correct value is around 5200 kgCO2eq/month, which gives 124800 kgCO2eq for 24 months (the period displayed). This approximation is close enough to the real value of 110,5 tCO2eq which takes into account the decrease of emissions with time.
Therefore the absolute value of bar height roughly 2000000 kgCO2eq (2 ktCO2eq) for one month is completely through the roof and wrong.
Expected Behavior
In that case, the correct calculation is to assert that endEmissionPercentage is greater than (1 - startEmissionPercentage), and if the test passes, to compute the difference : endEmissionPercentage - (1 - startEmissionPercentage), and to multiply that percentage difference by the emissionIntensity * currentSlotDelta
The most likely culprit for the huge error is currentSlotDelta because the value is returned in milliseconds when emissionIntensity is in kgCO2eq per second, but dividing the values by 1000 (tons instead of kilotons) yields monthly totals on the order to 2 tons, and this is less than one half of the expected value, so there is another error.
https://github.com/Natixar/natixar-frontend/blob/ead8cd58e471085638f3ef84d520788ce85e8a27/src/data/domain/transformers/EmissionTransformers.ts#L220
Problem
Similar code was used in the function
calculateTotalAmount()
. This code is not correct and gives wrong results when thestartTimeSlot
is also theendTimeSlot
.Steps to Reproduce
Just observe the Dashboard. The total on the donut, 110,5 tCO2eq is supposedly equal to sum of the 24 monthly consumptions on the bar chart. But even a single bar is labeled in ktCO2eq. Considering emission flows of roughly 0.002 kgCO2eq/s and 2600000s/month the correct value is around 5200 kgCO2eq/month, which gives 124800 kgCO2eq for 24 months (the period displayed). This approximation is close enough to the real value of 110,5 tCO2eq which takes into account the decrease of emissions with time.
Therefore the absolute value of bar height roughly 2000000 kgCO2eq (2 ktCO2eq) for one month is completely through the roof and wrong.
Expected Behavior
In that case, the correct calculation is to assert that
endEmissionPercentage
is greater than(1 - startEmissionPercentage)
, and if the test passes, to compute the difference :endEmissionPercentage - (1 - startEmissionPercentage)
, and to multiply that percentage difference by theemissionIntensity * currentSlotDelta
The most likely culprit for the huge error is
currentSlotDelta
because the value is returned in milliseconds whenemissionIntensity
is in kgCO2eq per second, but dividing the values by 1000 (tons instead of kilotons) yields monthly totals on the order to 2 tons, and this is less than one half of the expected value, so there is another error.