From 0595c19de90f44c3b99eaddc96e90be7ca7dde94 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Fri, 30 Dec 2022 21:31:50 +0100 Subject: [PATCH] Avoid division by 0 Not quite sure how that could happen but it did. --- ltsdb_json.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ltsdb_json.py b/ltsdb_json.py index 4537dcb..b70a3b5 100644 --- a/ltsdb_json.py +++ b/ltsdb_json.py @@ -54,7 +54,8 @@ class LTS: data = self.data n = len(data) t_last = data[-1][0] - dt = (t_last - data[-5][0]) / 4 + dt = max((t_last - data[-5][0]) / 4, 1) + log.debug("dt = %s, n = %s", dt, n) k = math.log((t_last - data[0][0]) / dt / n + 1) for i in range(1, n): t_ideal = (math.exp(k * (n - i)/n) - 1) * (n * dt)