Added search in nicos/se_addons and nicos/se_stick for available variables

This commit is contained in:
l_samenv
2024-08-07 10:47:42 +02:00
parent 83d45e511f
commit 13a105183b
2 changed files with 47 additions and 29 deletions

View File

@ -0,0 +1,10 @@
# device.parameter=cat[,color[,unit]]
# device.parameter=cat:raw,color:yellow
[nicos]
se_t_plato.raw=raw,#FFF,Ohm
se_t_plato.target=none # do not show
se_t_plato.raw=std # show in standard section
se_t_plato.raw=raw # show in extra section "raw"
se_t_plato.value=std,unit:Ohm # custom unit

View File

@ -64,8 +64,8 @@ class InfluxDataGetter:
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.
"""
setup_info = self._get_setup_info_as_dict(time)
available_variables = self._extract_variables(setup_info)
all_setup_info = self._get_all_setup_info_as_dict(time)
available_variables = self._extract_variables(all_setup_info)
available_variables = self._remove_variables_without_value_float(available_variables, time)
available_variables = self._set_variables_with_target(available_variables, time)
res = self._group_variables_by_unit(available_variables)
@ -126,39 +126,44 @@ class InfluxDataGetter:
# ----- PRIVATE METHODS
def _get_setup_info_as_dict(self, time):
def _get_all_setup_info_as_dict(self, time):
"""
Gets the value of the field setup_info in the measurement nicos/se_main as a Python dict.
Gets the value of the field setup_info in the measurements nicos/se_main, nicos/se_stick, nicos/se_addons as an array of Python dicts.
Parameters
time (int) : the Unix timestamp in seconds we want to look the availability of variables for.
Returns :
{(str):((str), {...})} : the parsed "setup_info dict". The key is the secop_module prefixed with "se_", and the value is a tuple with its first value
[{(str):((str), {...})}]: an array of the parsed "setup_info dict" of each measurements. The key is the secop_module prefixed with "se_", and the value is a tuple with its first value
being the type of Secop device for this module, and the value is too big to give its signature. Some tuple examples can be found under graphs/setup_info_examples.
"""
measurements = ["nicos/se_main", "nicos/se_stick", "nicos/se_addons"]
res = []
for measurement in measurements:
to_add = {}
query = f"""
from(bucket: "{self._bucket}")
|> range(start: 0, stop: {time + 1})
|> filter(fn: (r) => r._measurement == "{measurement}")
|> filter(fn: (r) => r._field == "setup_info")
|> last()
|> yield(name: "res")
"""
query = f"""
from(bucket: "{self._bucket}")
|> range(start: 0, stop: {time + 1})
|> filter(fn: (r) => r._measurement == "nicos/se_main")
|> filter(fn: (r) => r._field == "setup_info")
|> last()
|> yield(name: "res")
"""
tables = self._db.query(query)
res = ast.literal_eval(tables[0].records[0].get_value())
# TODO : what if 1. there is no record and 2. what if res is get_value() is empty (do we try to look for another way of getting the variables ?)
tables = self._db.query(query)
for table in tables:
for record in table.records:
to_add = ast.literal_eval(record.get_value())
res.append(to_add)
return res
def _extract_variables(self, setup_info_dict):
def _extract_variables(self, all_setup_info_dict):
"""
Extracts relevant information out of the setup_info dict for each available variable.
Extracts relevant information out of the setup_info dict for each available variable in measurements nicos/se_main, nicos/se_stick, nicos/se_addons
Parameters :
setup_info_dict ({(str):((str), {...})}) : the parsed "setup_info dict". The key is the secop_module prefixed with "se_", and the value is a tuple with its first value
all_setup_info_dict ([{(str):((str), {...})}]) : an array of the parsed "setup_info dict" of each measurements. The key is the secop_module prefixed with "se_", and the value is a tuple with its first value
being the type of Secop device for this module, and the value is too big to give its signature. Some tuple examples can be found under graphs/setup_info_examples.
Returns :
@ -166,15 +171,18 @@ class InfluxDataGetter:
the label to display in the Web GUI, its unit and a boolean value indicating if the variable has a potential target available.
"""
available_varirables = [
{
"name":self._transform_setup_info_variable_name_to_influx(setup_info_variable_name),
"label":content[1]["secop_module"],
"unit":content[1]["unit"],
"has_potential_target": "target_datainfo" in content[1].keys()
}
for (setup_info_variable_name, content) in setup_info_dict.items() if content[0] != "nicos.devices.secop.devices.SecopDevice"
]
available_varirables = []
for setup_info_dict in all_setup_info_dict:
for (setup_info_variable_name, content) in setup_info_dict.items():
if content[0] != "nicos.devices.secop.devices.SecopDevice":
available_varirables.append(
{
"name":self._transform_setup_info_variable_name_to_influx(setup_info_variable_name),
"label":content[1]["secop_module"],
"unit":content[1]["unit"],
"has_potential_target": "target_datainfo" in content[1].keys()
}
)
return available_varirables
def _transform_setup_info_variable_name_to_influx(self, setup_info_name):