Sampling data (aggregateWindow) for responsitivity + fixed old values not shown bug + readme
This commit is contained in:
30
influxdb.py
30
influxdb.py
@@ -72,13 +72,14 @@ class InfluxDataGetter:
|
||||
|
||||
return res
|
||||
|
||||
def get_curves_in_timerange(self, variables, time):
|
||||
def get_curves_in_timerange(self, variables, time, interval = None):
|
||||
"""
|
||||
Gets the curves for the given variables within a timerange.
|
||||
|
||||
Parameters :
|
||||
variables ([(str)]) : an array of variable names (Influx) to get the curves for
|
||||
time ([int]) : the timerange we want the values in. It consists of two values which are Unix timestamps in seconds, first included, second excluded.
|
||||
interval (int) : the interval (resolution) of the values to get (in nanoseconds)
|
||||
|
||||
Returns :
|
||||
{(str):[[(int), (float)]]} : a dictionnary of curves. The key is the name of the influx variable, and the value is an array of pairs (also arrays), the first value being the Unix timestamp in second (x), the seconds being the value (y).
|
||||
@@ -91,8 +92,8 @@ class InfluxDataGetter:
|
||||
if variable_name_for_query.endswith(".target"):
|
||||
variable_name_for_query = variable_name_for_query[:-len(".target")]
|
||||
is_target = True
|
||||
|
||||
curve = self._get_curve(variable_name_for_query, is_target, time)
|
||||
|
||||
curve = self._get_curve(variable_name_for_query, is_target, time, interval)
|
||||
if len(curve) > 0:
|
||||
res[variable] = curve
|
||||
|
||||
@@ -300,7 +301,7 @@ class InfluxDataGetter:
|
||||
"color":""
|
||||
})
|
||||
|
||||
def _get_curve(self, variable, is_target, time):
|
||||
def _get_curve(self, variable, is_target, time, interval=None):
|
||||
"""
|
||||
Gets the points (curve) within a timerange for the given variable.
|
||||
|
||||
@@ -308,7 +309,8 @@ class InfluxDataGetter:
|
||||
variable (str) : the name (Influx) of the variable we want the values of.
|
||||
is_target (bool) : tells if the given variable is a target, or not (if variable is "nicos/se_t_chip.target", then is_target has to be set to True)
|
||||
time ([(int)]) : the timerange we want the values in. It consists of two values which are Unix timestamps in seconds, first included, second excluded.
|
||||
|
||||
interval (int) : the interval (resolution) of the values to get (in nanoseconds)
|
||||
|
||||
Returns :
|
||||
[[(int), (float)]] : an array of pairs (also arrays), the first value being the Unix timestamp in second (x), the seconds being the value (y)
|
||||
"""
|
||||
@@ -318,6 +320,7 @@ class InfluxDataGetter:
|
||||
|> range(start: {time[0]}, stop: {time[1] + 1})
|
||||
|> filter(fn : (r) => r._measurement == "{variable}")
|
||||
|> filter(fn : (r) => r._field == "{"target_float" if is_target else "value_float"}")
|
||||
{"|> aggregateWindow(every: duration(v:"+str(interval)+"), fn: last, createEmpty:false)" if interval else ""}
|
||||
|> keep(columns: ["_time","_value"])
|
||||
|> yield(name: "res")
|
||||
"""
|
||||
@@ -358,13 +361,16 @@ class InfluxDataGetter:
|
||||
|> keep(columns: ["_value"])
|
||||
|> yield(name: "res")
|
||||
"""
|
||||
record = self._db.query(query)[0].records[0]
|
||||
value = record.get_value()
|
||||
try:
|
||||
value = PrettyFloat(value)
|
||||
except:
|
||||
value = None
|
||||
curve.insert(0, [time[0], value])
|
||||
tables = self._db.query(query)
|
||||
|
||||
for table in tables:
|
||||
for record in table.records:
|
||||
value = record.get_value()
|
||||
try:
|
||||
value = PrettyFloat(value)
|
||||
except:
|
||||
value = None
|
||||
curve.insert(0, [time[0], value])
|
||||
return curve
|
||||
|
||||
def _get_last_values(self, variable, is_target, time):
|
||||
|
||||
Reference in New Issue
Block a user