From: Martin Mares Date: Sun, 10 Nov 2019 16:19:24 +0000 (+0100) Subject: Auto: Better handling of missing values when averaging X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=24e79ec7dbe46b9a967154d59c25d6b75b9e276a;p=home-hw.git Auto: Better handling of missing values when averaging --- 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()