From ec53f98ded2cfe919fe4b6fe2f2c9336d35954c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Balzarotti?= Date: Tue, 21 Feb 2023 22:53:22 +0100 Subject: [PATCH] fix couple of problems in the smooth --- sensors.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sensors.py b/sensors.py index 1fb6b96..82290a0 100644 --- a/sensors.py +++ b/sensors.py @@ -33,8 +33,8 @@ WINDOW_SIZE_S = 5 class Sensor(): def __init__(self, autocorr=0.7): - # We won't sample at more than 10Hz, so this is safe - self.history = deque([], int(WINDOW_SIZE_S * 10)) + # FIXME: DEPENDS ON SAMPLING RATE + self.history = deque([], int(WINDOW_SIZE_S * 2)) ## This is just for debugging self.prevval = random() * 100 @@ -72,8 +72,13 @@ class GPIOState(Sensor): print(f"Could not read pin {self.pin}") self.value = 0 self.time = perf_counter() - - return self.store(self.time, self.transform(self.value)) + + # Even if we don't need to return the smoothed value, we still smooth it + # to get the percentage of use over the period (if it will be needed) + value = self.transform(self.value) + self.store(self.time, value) + + return (self.time, value) class Temperature1W(Sensor): def __init__(self, address):