]> mj.ucw.cz Git - home-hw.git/commitdiff
Auto: Better handling of missing values when averaging
authorMartin Mares <mj@ucw.cz>
Sun, 10 Nov 2019 16:19:24 +0000 (17:19 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 10 Nov 2019 16:19:24 +0000 (17:19 +0100)
auto/burrow-auto

index 4dba420893cf3d4c081d5c86f0afb616fb50d441..2adea5ae1bd0b2dca1e75cf3c85db390a3709ee4 100755 (executable)
@@ -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()