Removed reduced + original_color for influx, doc for influxgraph
This commit is contained in:
@ -499,13 +499,13 @@ let graphs = (function (){
|
||||
* Adds the received dataset in the graph being created
|
||||
* Sets the visualization window, conditionnaly autoscale, applies the changes, and show the legend
|
||||
* @param {number} gindex - The position of the graph in the container
|
||||
* @param {{tag:string, unit:string, curves:[{name:string, label:string, color:string, original_color:string}]}} block - The information of the block to create
|
||||
* @param {{tag:string, unit:string, curves:[{name:string, label:string, color:string}]}} block - The information of the block to create
|
||||
*/
|
||||
function createGraph(gindex, block){
|
||||
console.log("clear for create graph", gindex)
|
||||
clear(gindex);
|
||||
tag_dict[block.tag] = gindex;
|
||||
let dict = {} // {string: [name:string, label:string, color:string, original_color:string]}
|
||||
let dict = {} // {string: [name:string, label:string, color:string]}
|
||||
for (let curve of block.curves) {
|
||||
if (curve.show !== false) {
|
||||
vars_array[gindex].push(curve.name);
|
||||
@ -1003,7 +1003,7 @@ let graphs = (function (){
|
||||
}
|
||||
/**
|
||||
* Inits the graph content
|
||||
* @param {[{tag:string, unit:string, curves:[{name:string, label:string, color:string, original_color:string}]}]} blocks - the received blocks
|
||||
* @param {[{tag:string, unit:string, curves:[{name:string, label:string, color:string}]}]} blocks - the received blocks
|
||||
*/
|
||||
function initGraphs(blocks){
|
||||
buildGraphicsUI();
|
||||
@ -1012,7 +1012,7 @@ let graphs = (function (){
|
||||
|
||||
/**
|
||||
* Holds the received variables from the /getvars call, gets the server time, then creates the graphs
|
||||
* @param {[{tag:string, unit:string, curves:[{name:string, label:string, color:string, original_color:string}]}]} blocks_arg - the received blocks
|
||||
* @param {[{tag:string, unit:string, curves:[{name:string, label:string, color:string}]}]} blocks_arg - the received blocks
|
||||
*/
|
||||
function receivedVars(blocks_arg){
|
||||
maxTime = timeRange[1]*1000;
|
||||
@ -1962,7 +1962,7 @@ function Graph(gindex, container, x_label, y_label, tag, scaleType = "linear"){
|
||||
/**
|
||||
* Called when new data is received from the server (SSE).
|
||||
* Appends new data to the corresponding curves' datasets
|
||||
* @param {{type:"graph-update", reduced:boolean, time:number, graph:{string:[[(number),(number)]]}}} graph - The graph response from the server
|
||||
* @param {{type:"graph-update", time:number, graph:{string:[[(number),(number)]]}}} graph - The graph response from the server
|
||||
*/
|
||||
function updateCharts2(graph){
|
||||
if(!graphs.doUpdates()) {
|
||||
|
11
colors.py
11
colors.py
@ -4,12 +4,12 @@ def assign_colors_to_curves(blocks):
|
||||
|
||||
Parameters :
|
||||
|
||||
blocks ["tag":(str),"unit":(str), "curves":[{"name":(str), "label":(str), "color":(str)}]] : a list of dictionnaries, each one representing
|
||||
a block of curves with their name, their label and their color (if found in the database), grouped by their tag (which can be the unit augmented with an index) and their unit
|
||||
blocks (["tag":(str),"unit":(str), "curves":[{"name":(str), "label":(str), "color":(str)}]]) : a list of dictionnaries, each one representing
|
||||
a block of curves with their name, their label and their color to display (can be empty if not defined before), grouped by their category if given or unit (in tag).
|
||||
|
||||
Returns :
|
||||
["tag":(str),"unit":(str), "curves":[{"name":(str), "label":(str), "color":(str), "original_color":(str)}]] : the same object as the "blocks" parameter, with the color value
|
||||
updated depending on its availability in the ColorMap, and a new "original_color" value which contains the previous "color" value
|
||||
["tag":(str),"unit":(str), "curves":[{"name":(str), "label":(str), "color":(str)}]] : the same object as the "blocks" parameter, with the color value
|
||||
updated depending on its availability in the ColorMap
|
||||
"""
|
||||
|
||||
# get last value only
|
||||
@ -23,14 +23,11 @@ def assign_colors_to_curves(blocks):
|
||||
if c < 0:
|
||||
valid = ColorMap.check_hex(col)
|
||||
if valid:
|
||||
curve["original_color"] = col
|
||||
curve["color"] = valid
|
||||
else:
|
||||
auto_curves.append(curve)
|
||||
curve["original_color"] = col + "?"
|
||||
else:
|
||||
color_set.add(c)
|
||||
curve["original_color"] = col
|
||||
curve["color"] = ColorMap.to_hex(c)
|
||||
c = 1 # omit white
|
||||
for curve in auto_curves:
|
||||
|
@ -35,7 +35,6 @@ The only constantly open connection:
|
||||
|
||||
<graph-update-message> = {
|
||||
"type": "graph-update",
|
||||
"reduced": true/false,
|
||||
"time": <server-time>,
|
||||
"graph": {
|
||||
"<name1>": [[<time>,<value>],[<time>,<value>]...
|
||||
@ -189,7 +188,6 @@ All other connections are to be closed (getJSON):
|
||||
|
||||
<graph-draw-message> = = {
|
||||
"type": "graph-draw",
|
||||
"reduced": true/false,
|
||||
"graph": {
|
||||
"<name1>": [[<time>,<value>],[<time>,<value>]...
|
||||
"<name2>": [[<time>,<value>],[<time>,<value>]...
|
||||
|
@ -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