Removed reduced + original_color for influx, doc for influxgraph
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
from influxdb import InfluxDB, InfluxDataGetter
|
||||
import time
|
||||
import logging
|
||||
from colors import assign_colors_to_curves
|
||||
@ -11,18 +10,18 @@ class InfluxGraph:
|
||||
Class implementing the logic of the different routes that are called by the client to retrieve graph data with InfluxDB.
|
||||
|
||||
Global constants :
|
||||
HISTORICAL (int) : value that represents the "historical" visualisation mode, meaning that the most recent point is not in the visualisation window.
|
||||
ACTUAL (int) : value that represents the "actual" visualisation mode, meaning that the curves stay in place, but new data is being added to the right (expansion in the future).
|
||||
LIVE (int) : value that represents the "live" visualisation mode, meaning that the curves move with the most recent point always at the same place.
|
||||
HISTORICAL (int) : value that represents the "historical" visualization mode, meaning that the most recent point is not in the visualisation window (no live data is sent).
|
||||
ACTUAL (int) : value that represents the "actual" visualization mode, wihch is an intermediate state used before going for live mode (the requested time window includes now)
|
||||
LIVE (int) : value that represents the "live" visualization mode, meaning that new points are sent to the client.
|
||||
|
||||
Attributes :
|
||||
db (InfluxDB) : the InfluxDB instance that holds the connection with InfluxDB.
|
||||
influx_data_getter (InfluxDataGetter) : the InfluxDataGetter instance that allows to get data out of InfluxDB.
|
||||
livemode (int) : the type of visualisation the user is currently in. Can be HISTORICAL, ACTUAL or LIVE.
|
||||
time ([(int)]) : an array of unix timestamp in seconds, where the first value is the last most recent requested point in time,
|
||||
and the second value is the current most recent requested point in time.
|
||||
chart_configs ([ChartConfig]) : an array of chart configuration to apply when /getvars is called
|
||||
livemode (int) : the type of visualization the user is currently in. Can be HISTORICAL, ACTUAL or LIVE.
|
||||
end_query (int) : the unix timestamp in seconds of the most recent requested point in time of the last query or update.
|
||||
lastvalues ({(str):((int), (float))}) : a dictionnary where the keys are the variable names, and the values are tuples, where the first
|
||||
value is the unix timestamp of the most recent value known for this variable, and the second value its corresponding value
|
||||
value is the unix timestamp of the most recent value known for this variable, and the second value its corresponding value
|
||||
variables ({(str):(str)}) : a dictionnary of the current available variables requested by the client. The key is the InfluxDB name of the curve, and the value is its label in the GUI.
|
||||
"""
|
||||
HISTORICAL = 0
|
||||
ACTUAL = 1
|
||||
@ -52,9 +51,10 @@ class InfluxGraph:
|
||||
oneyear = 365 * 24 * 3600
|
||||
return [t + now if t < oneyear else t for t in times]
|
||||
|
||||
def complete_to_end(self, result, endtime):
|
||||
def complete_to_end_and_feed_lastvalues(self, result, endtime):
|
||||
"""
|
||||
Completes the data until the last requested point in time by adding the last known y-value at the end point.
|
||||
Also feeds self.lastvalues.
|
||||
|
||||
Parameters :
|
||||
result ({(str):[[(int),(float)]]}) : a dictionnary with the variable names as key, and an array of points,
|
||||
@ -70,7 +70,7 @@ class InfluxGraph:
|
||||
|
||||
def w_graph(self, variables, time="-1800,0", interval=None):
|
||||
"""
|
||||
Gets the curves given by variables in the time range "time"
|
||||
Gets the curves given by variables in the time range "time", spaced by "interval" if given (binning/resolution)
|
||||
Called when the route /graph is reached.
|
||||
|
||||
Parameters :
|
||||
@ -79,8 +79,7 @@ class InfluxGraph:
|
||||
interval (str) : the interval (resolution) of the values to get (string in milliseconds)
|
||||
|
||||
Returns :
|
||||
{"type":"graph-draw", "reduced":(bool), "graph":{(str):[[(int),(float)]]}} : a dictionnary with its "graph-draw" type (so it can be processed by the client), a "reduced" value
|
||||
indicating if the data is reduced or not (meaning the data is sampled to be lighter for data viewing), and a "graph" dictionnary with the variable names as key, and an array of points,
|
||||
{"type":"graph-draw", "graph":{(str):[[(int),(float)]]}} : a dictionnary with its "graph-draw" type (so it can be processed by the client), and a "graph" dictionnary with the variable names as key, and an array of points,
|
||||
which are an array containing the timestamp as their first value, and the y-value in float as their second one.
|
||||
"""
|
||||
time = [float(t) for t in time.split(',')]
|
||||
@ -93,10 +92,10 @@ class InfluxGraph:
|
||||
if interval : interval = int(interval)
|
||||
|
||||
result = self.influx_data_getter.get_curves_in_timerange(queried_variables, queried_time_range, interval)
|
||||
self.complete_to_end(result, min(end, now))
|
||||
self.complete_to_end_and_feed_lastvalues(result, min(end, now))
|
||||
self.end_query = end
|
||||
# reduction not yet implemented
|
||||
return dict(type='graph-draw', reduced=False, graph=result)
|
||||
|
||||
return dict(type='graph-draw', graph=result)
|
||||
|
||||
def w_gettime(self, time):
|
||||
"""
|
||||
@ -115,16 +114,17 @@ class InfluxGraph:
|
||||
|
||||
def w_getvars(self, time, userconfiguration = None):
|
||||
"""
|
||||
Gets the curve names available at a given point in time.
|
||||
Gets the curve names available at a given point in time, with a possible user configuration on the client side.
|
||||
Called when the route /getvars is reached.
|
||||
|
||||
Parameters :
|
||||
time (str) : the given point in time represented by a string, which is a comma separated unix timestamp values list (in seconds). They are treated as relative from now if they are lesser than one year.
|
||||
time (str) : the given point in time represented by a string, which is a unix timestamp in seconds. It is treated as relative from now if it is lesser than one year.
|
||||
userconfiguration (str|None) : the JSON string representing the user configuration
|
||||
|
||||
Returns :
|
||||
{"type":"var_list", "blocks":[{"tag":(str),"unit":(str), "curves":[{"name":(str), "label":(str), "color":(str), "original_color":(str)}]}]} :
|
||||
a dictionnary with its "var_list" type (so the data can be processed by the client) and the available curves with the name of the internal variable,
|
||||
the color to display for this curve, its original color in SEA, grouped by their tag (which is a unit augmented with an index) and their unit ("in blocks")
|
||||
{"type":"var_list", "device":(str), "blocks":[{"tag":(str),"unit":(str), "curves":[{"name":(str), "label":(str), "color":(str), "original_color":(str)}]}]} :
|
||||
a dictionnary with its "var_list" type (so the data can be processed by the client), the device that was currently set at that time, and the available curves with the name of the internal variable,
|
||||
the color to display for this curve, its original color in SEA, grouped by their tag (which is a category or unit if absent) and their unit (in "blocks")
|
||||
"""
|
||||
|
||||
time = [float(t) for t in time.split(',')]
|
||||
@ -188,13 +188,12 @@ class InfluxGraph:
|
||||
|
||||
def graphpoll(self):
|
||||
"""
|
||||
Polls the last known values for all the available variables, and returns only those whose polled value is more recent than the nost recent displayed one.
|
||||
Polls the last known values for all the available variables, and returns only those whose polled values are more recent than the most recent displayed one.
|
||||
Every plain minute, all the variables are returned with a point having their last known value at the current timestamp to synchronize all the curves on the GUI.
|
||||
|
||||
Returns :
|
||||
{"type":"graph-update", "reduced":(bool), "time":(int), "graph":{(str):[[(int),(float)]]}} | None : a dictionnary with its "graph-update" type
|
||||
(so it can be processed by the client), a "reduced" value indicating if the data is reduced or not (meaning the data is sampled to be lighter
|
||||
for data viewing), and a "graph" dictionnary with the variable names as key, and an array of points, which are an array containing the timestamp
|
||||
{"type":"graph-update", "time":(int), "graph":{(str):[[(int),(float)]]}} | None : a dictionnary with its "graph-update" type
|
||||
(so it can be processed by the client), and a "graph" dictionnary with the variable names as key, and an array of points, which are an array containing the timestamp
|
||||
as their first value, and the y-value in float as their second one
|
||||
"""
|
||||
if self.livemode != self.LIVE:
|
||||
@ -224,5 +223,5 @@ class InfluxGraph:
|
||||
result[var] = [(now, lastx)]
|
||||
self.end_query = now
|
||||
if len(result) > 0:
|
||||
return dict(type='graph-update', reduced=False, time=now, graph=result)
|
||||
return dict(type='graph-update', time=now, graph=result)
|
||||
return None
|
Reference in New Issue
Block a user