Compare commits

..

1 Commits

Author SHA1 Message Date
Jean-Marc Collin
8719349241 Don't store datetime of fake datapoint 2023-11-28 22:19:16 +00:00

View File

@@ -48,13 +48,13 @@ class WindowOpenDetectionAlgorithm:
delta_t_sec = float((datetime_now - self._last_datetime).total_seconds()) / 60.0 delta_t_sec = float((datetime_now - self._last_datetime).total_seconds()) / 60.0
if delta_t_sec >= MAX_DURATION_MIN: if delta_t_sec >= MAX_DURATION_MIN:
return self.add_temp_measurement(temperature, datetime_now) return self.add_temp_measurement(temperature, datetime_now, False)
else: else:
# do nothing # do nothing
return self._last_slope return self._last_slope
def add_temp_measurement( def add_temp_measurement(
self, temperature: float, datetime_measure: datetime self, temperature: float, datetime_measure: datetime, store_date: bool = True
) -> float: ) -> float:
"""Add a new temperature measurement """Add a new temperature measurement
returns the last slope returns the last slope
@@ -98,7 +98,11 @@ class WindowOpenDetectionAlgorithm:
else: else:
self._last_slope = round((0.2 * self._last_slope) + (0.8 * new_slope), 4) self._last_slope = round((0.2 * self._last_slope) + (0.8 * new_slope), 4)
self._last_datetime = datetime_measure # if we are in cycle check and so adding a fake datapoint, we don't store the event datetime
# so that, when we will receive a real temperature point we will not calculate a wrong slope
if store_date:
self._last_datetime = datetime_measure
self._last_temperature = temperature self._last_temperature = temperature
self._nb_point = self._nb_point + 1 self._nb_point = self._nb_point + 1