get_available_variables_at_time usable without config file
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
from configparser import ConfigParser
|
||||
class ChartConfig:
|
||||
def __init__(self):
|
||||
def __init__(self, path):
|
||||
cfgp = ConfigParser()
|
||||
cfgp.read("./variables_config.ini")
|
||||
cfgp.read(path)
|
||||
self.chart_config = cfgp["chart"]
|
||||
|
||||
def get_variable_parameter_config(self, key):
|
||||
|
25
influxdb.py
25
influxdb.py
@ -58,23 +58,24 @@ class InfluxDataGetter:
|
||||
|
||||
# ----- PUBLIC METHODS
|
||||
|
||||
def get_available_variables_at_time(self, times):
|
||||
def get_available_variables_at_time(self, times, chart_config = None):
|
||||
"""
|
||||
Gets the available variables (those that we can have a value for since the device has been installed on the instrument) at the given point in time.
|
||||
We can get the last available variables at the given point in time or all the known variables for the day corresponding to the timestamp.
|
||||
Gets the available variables (those that we can have a value for since the device has been installed on the instrument) at the given point in time (times[1]).
|
||||
Here, a variable means : SECOP module name + parameter. By default, this method returns the parameters "value" and "target", unless the config file used in chart_config indicates other directives.
|
||||
|
||||
Parameters :
|
||||
times ([int]) : the unix timestamps in seconds of the range. The first value can be unused. The last can represent the point in time.
|
||||
times ([int]) : the unix timestamps in seconds of the range. The first value is unused. The last represents the point in time.
|
||||
chart_config (ChartConfig | None) : the object holding a configuration file for the chart.
|
||||
|
||||
Returns :
|
||||
[{"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, grouped by their tag (which can be the unit augmented with an index) and their unit.
|
||||
a block of curves with their name, their label and their color to display, grouped by their category and unit (in tag).
|
||||
"""
|
||||
|
||||
all_setup_info = self._get_all_setup_info_as_dict(times)
|
||||
|
||||
available_variables = self._extract_variables(all_setup_info)
|
||||
available_variables = self._filter_params_with_config(available_variables)
|
||||
available_variables = self._filter_params_with_config(available_variables, chart_config)
|
||||
available_variables = self._remove_variables_params_wihout_param_float_and_split(available_variables, times)
|
||||
res = self._group_variables_by_cat_unit(available_variables)
|
||||
|
||||
@ -373,26 +374,26 @@ class InfluxDataGetter:
|
||||
"""
|
||||
return self._influx_instrument_config["measurement_prefix"] + secop_module_name.lower()
|
||||
|
||||
def _filter_params_with_config(self, available_variables):
|
||||
def _filter_params_with_config(self, available_variables, chart_config = None):
|
||||
"""
|
||||
Removes and updates (cat, color, unit) the parameters according to the content of variables_config.ini file.
|
||||
Removes and updates (cat, color, unit) the parameters according to the chart_config object if given.
|
||||
If not given, only value and target parameters are kept.
|
||||
|
||||
Parameters:
|
||||
available_variables ([{"name":(str), "label":(str), "params":{(str):{"cat":(str), "color":(str), "unit":(str)}}}]) : an array of dictionnaries, each containing the Influx name of the corresponding variable out of the setup_info dict,
|
||||
the label to display in the Web GUI, and a dictionnary of parameters (including value), which consist of dictionnares with the category (empty for the moment), the color (same) and the unit (if available), indexed by the name of the parameter.
|
||||
chart_config (ChartConfig | None) : the object holding a configuration file for the chart.
|
||||
|
||||
Returns :
|
||||
[{"name":(str), "label":(str), "params":{(str):{"cat":(str), "color":(str), "unit":(str)}}}] : the available_variables parameter, updated
|
||||
"""
|
||||
|
||||
chart_config = ChartConfig()
|
||||
|
||||
for variable in available_variables:
|
||||
params = list(variable["params"].keys())
|
||||
for param_key in params:
|
||||
key = variable["label"] if param_key == "value" else variable["label"]+"."+param_key
|
||||
param_config = chart_config.get_variable_parameter_config(key)
|
||||
if param_config == None : # no entries were found
|
||||
param_config = chart_config.get_variable_parameter_config(key) if chart_config else None
|
||||
if param_config == None : # no entries were found or there is no chart_config
|
||||
if param_key != "target" and param_key != "value": # and the current param is not value or target which are displayed by default
|
||||
del variable["params"][param_key]
|
||||
else:
|
||||
|
@ -4,6 +4,7 @@ import logging
|
||||
from colors import assign_colors_to_curves
|
||||
import json
|
||||
import io
|
||||
from chart_config import ChartConfig
|
||||
|
||||
class InfluxGraph:
|
||||
"""
|
||||
@ -29,6 +30,7 @@ class InfluxGraph:
|
||||
|
||||
def __init__(self, influx_data_getter):
|
||||
self.influx_data_getter = influx_data_getter
|
||||
self.chart_config = ChartConfig("./variables_config.ini")
|
||||
self.livemode = self.HISTORICAL
|
||||
self.end_query = 0
|
||||
self.lastvalues = {}
|
||||
@ -129,7 +131,7 @@ class InfluxGraph:
|
||||
start_time = int(self.get_abs_time(time)[0])
|
||||
end_time = int(self.get_abs_time(time)[-1])
|
||||
|
||||
blocks = self.influx_data_getter.get_available_variables_at_time([start_time, end_time])
|
||||
blocks = self.influx_data_getter.get_available_variables_at_time([start_time, end_time], self.chart_config)
|
||||
device_name = self.influx_data_getter.get_device_name(end_time)
|
||||
# updates the self.variables attribute to keep track of the available variables
|
||||
self.variables = {variable["name"]:variable["label"] for block in blocks for variable in block["curves"]}
|
||||
|
Reference in New Issue
Block a user