From d7ad61557b4c62f39c26c6e32704c5647b0b691d Mon Sep 17 00:00:00 2001 From: Timotheus Pokorra Date: Sun, 29 May 2022 20:37:09 +0200 Subject: [PATCH] avoid startRate of 0 division error --- apps/monitor/calc.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/monitor/calc.py b/apps/monitor/calc.py index fb2e6dc..db1fa66 100644 --- a/apps/monitor/calc.py +++ b/apps/monitor/calc.py @@ -49,11 +49,14 @@ class Calc: ORDER BY rate ASC LIMIT 1""" cursor.execute(sql, [Crypto, Fiat, startDate, endDate]) minRate = cursor.fetchone() + diffPercentage = -1 + if startRate[1] > 0: + diffPercentage = (Decimal(endRate[1])-Decimal(startRate[1]))/Decimal(startRate[1])*100 return {"startdate": startRate[0], "startvalue": startRate[1], "curdate": endRate[0], "curvalue": endRate[1], "mindate": minRate[0], "minvalue": minRate[1], "maxdate": maxRate[0], "maxvalue": maxRate[1], - "diffPercentage": (Decimal(endRate[1])-Decimal(startRate[1]))/Decimal(startRate[1])*100} + "diffPercentage": diffPercentage} return None