Wrong delta percentage if previous value is negative
Created by: nayakrahul
Describe the bug Delta percentage is wrong in deltabar graphs if previous value is negative. As you can see in the screenshot, the last 3 delta percentage is wrong.
- For May 17, cases decreased from -17 to -26, so percentage delta should be negative but it is shown positive.
- For May 18, cases increased from -26 to -18, so percentage delta should be positive but it is shown negative.
- For May 19, cases increased from -18 to 7, so percentage delta should be positive but it is shown negative.
This is happening because we are using wrong formula to calculate delta percentage. The current formula does not work if previous value is negative.
Current formula is: (current_value - previous_value)/previous_value --> (incorrect) Correct formula should be: (current_value - previous_value)/abs(previous_value)
We should take absolute value in denominator which will give correct result in all scenarios.
To Reproduce Steps to reproduce the behavior:
- Go to state page of Haryana
- See the deltabar graph for active cases. I have explained above what is wrong here (if it is seen today).
Expected behavior
Correct delta percentage if negative numbers come into action.