From 24e79ec7dbe46b9a967154d59c25d6b75b9e276a Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 10 Nov 2019 17:19:24 +0100 Subject: [PATCH] Auto: Better handling of missing values when averaging --- auto/burrow-auto | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/auto/burrow-auto b/auto/burrow-auto index 4dba420..2adea5a 100755 --- a/auto/burrow-auto +++ b/auto/burrow-auto @@ -109,13 +109,18 @@ class State: avg = None self.running_averages[key] = (history, sum, count, avg) - debug("= avg {:.6} ({} samples, {} non-null)".format(avg, len(history), count)) - if avg is not None: + if avg is None: + debug("= avg NONE ({} samples, {} non-null)".format(len(history), count)) + else: + debug("= avg {:.6} ({} samples, {} non-null)".format(avg, len(history), count)) self.set("avg/" + key, "{:.6} {}".format(avg, int(self.now))) def get_sensor_avg(self, key): val = self.running_averages[key][3] - debug("< {} = avg {:.6}".format(key, val)) + if val is None: + debug("< {} = avg NONE".format(key)) + else: + debug("< {} = avg {:.6}".format(key, val)) return val st = State() -- 2.39.2