insert_last_known_values for expired=True
This commit is contained in:
30
influxdb.py
30
influxdb.py
@@ -360,7 +360,8 @@ 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.
|
||||||
parameter (str) : the parameter of the variable to get the values from
|
parameter (str) : the parameter of the variable to get the values from
|
||||||
@@ -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:
|
||||||
value = record.get_value()
|
t = round(datetime.timestamp(record.get_time()), 3)
|
||||||
try:
|
value = None
|
||||||
value = PrettyFloat(value)
|
if record["expired"] == "False":
|
||||||
except:
|
value = record.get_value()
|
||||||
value = None
|
try:
|
||||||
curve.insert(0, [time[0], value])
|
value = PrettyFloat(value)
|
||||||
|
except:
|
||||||
|
value = None
|
||||||
|
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):
|
||||||
|
|||||||
Reference in New Issue
Block a user