Skip to content

Commit

Permalink
fix: fully negative day resulted in bad ratio calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperiio committed Oct 20, 2024
1 parent 8ab8b06 commit 573ca90
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ def price_daily_average_ratio(self):
if not day_prices:
return 1

negative = all(p.price < 0 for p in day_prices)
day_average = sum(p.price for p in day_prices) / len(day_prices)
return self.price / day_average if day_average else 1
ratio = self.price / day_average if day_average else 1
return -ratio if negative else ratio

@price_daily_average_ratio.expression
def price_daily_average_ratio(cls):
Expand Down

0 comments on commit 573ca90

Please sign in to comment.