fix couple of problems in the smooth

master
Nicolò Balzarotti 2023-02-21 22:53:22 +01:00
parent f11fa59dcc
commit ec53f98ded
1 changed files with 9 additions and 4 deletions

View File

@ -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):