insert_last_known_values for expired=True

This commit is contained in:
l_samenv
2024-08-23 13:56:11 +02:00
parent 0ffa3cf466
commit 9e012ac740

View File

@@ -360,6 +360,7 @@ class InfluxDataGetter:
def _insert_last_known_value(self, variable, parameter, curve, time): def _insert_last_known_value(self, variable, parameter, curve, time):
""" """
Adds the last known value as the first point in the curve if the last known value is outside the viewing window, for the given variable and parameter. Adds the last known value as the first point in the curve if the last known value is outside the viewing window, for the given variable and parameter.
The point is added only if it is not expired.
Parameters : Parameters :
variable (str) : the name (Influx) of the variable we want the values of. variable (str) : the name (Influx) of the variable we want the values of.
@@ -376,21 +377,28 @@ class InfluxDataGetter:
from(bucket: "{self._bucket}") from(bucket: "{self._bucket}")
|> range(start: 0, stop: {time[0]+1}) |> range(start: 0, stop: {time[0]+1})
|> filter(fn : (r) => r._measurement == "{variable}") |> filter(fn : (r) => r._measurement == "{variable}")
|> filter(fn : (r) => r._field == "{parameter+"_float"}" and r.expired == "False") |> filter(fn : (r) => r._field == "{parameter+"_float"}")
|> last() |> last()
|> keep(columns: ["_value"]) |> keep(columns: ["_time", "_value", "expired"])
|> yield(name: "res") |> yield(name: "res")
""" """
tables = self._db.query(query) tables = self._db.query(query)
pair_to_insert = []
for table in tables: for table in tables:
for record in table.records: for record in table.records:
t = round(datetime.timestamp(record.get_time()), 3)
value = None
if record["expired"] == "False":
value = record.get_value() value = record.get_value()
try: try:
value = PrettyFloat(value) value = PrettyFloat(value)
except: except:
value = None value = None
curve.insert(0, [time[0], value]) if len(pair_to_insert) == 0 or t >= pair_to_insert[0]:
pair_to_insert = [t, value]
if len(pair_to_insert)==2 and pair_to_insert[1] != None:
curve.insert(0, [time[0], pair_to_insert[1]])
return curve return curve
def _get_last_values(self, variable, parameter, start_time, end_time): def _get_last_values(self, variable, parameter, start_time, end_time):