fix chart config parameters

- add SEA dil pressures
- read config each time when it is used
This commit is contained in:
2025-05-13 10:49:10 +02:00
parent 179db4c0a3
commit a4fda418b2
3 changed files with 17 additions and 28 deletions

View File

@ -1,4 +1,5 @@
from configparser import ConfigParser
import logging
class ChartConfig:
@ -16,16 +17,15 @@ class ChartConfig:
Parameters :
path (str) : the path to the configuration file
"""
self.errors = {}
self.variables = {}
cfgp = ConfigParser(interpolation=None)
cfgp.optionxform = str
cfgp.read(path)
section = cfgp["chart"]
try:
section = cfgp["chart"]
except KeyError:
return
for key, raw_value in section.items():
if len(key.split('.')) > 1:
self.errors[key] = f'illegal key: {key}'
continue
arguments = raw_value.split(",")
keyword_mode = False
config = {'cat': '*'}
@ -36,25 +36,11 @@ class ChartConfig:
config[argname] = argvalue
else:
if keyword_mode:
self.errors[key] = f"positional arg after keywd arg: {key}={raw_value!r}"
logging.error('positional arg after keywd arg: %s=%r', key, raw_value)
else:
try:
if argvalue:
config[self.KEYS[i]] = argvalue
except Exception as e:
self.errors[key] = f"{e!r} in {key}={raw_value}"
logging.error('%r in %s=%r', e, key, raw_value)
self.variables[key] = config
def get_variable_parameter_config(self, key):
"""
Gets the configuration of the given key in the configuration file (chart section).
Parameters :
key (str) : the key to look for in the chart section (<variable>[.<param>])
Returns :
{"cat":(str), "color":(str), "unit":(str)} | None : a dictionnary representing the different options for the given key in the chart section.
The different options are in this dict if they are found in the chart section for the given key. Returns None if the key is not in the chart section,
or if there is a syntax problem for the given key.
"""
return self.variables.get(key)

View File

@ -19,6 +19,13 @@ T_sorb=unit:K,color:dark_violet
T_sorb.target=-
T_still=unit:K,color:orange
dil=-
dil.G1=unit:mbar
dil.G2=unit:mbar
dil.G3=unit:mbar
dil.P1=unit:mbar
dil.P2=unit:mbar
dil.v6pos=unit:%
dil.V12A=unit:%
lev=unit:%,color:brown
lev.n2=unit:%,color:black
hefill=-

View File

@ -58,14 +58,11 @@ class InfluxGraph(HandlerBase):
self.server = server
self.db = server.db
# self.influx_data_getter = influx_data_getter
self.chart_configs = [ChartConfig("./config/generic.ini")]
self.chart_configs = ["./config/generic.ini"]
self.instrument = instrument
self.device_name = device_name
if instrument: # TODO: should it not be better to have inifiles per device?
try:
self.chart_configs.append(ChartConfig(f"./config/{instrument}.ini"))
except KeyError:
pass
self.chart_configs.append(f"./config/{instrument}.ini")
self.livemode = self.HISTORICAL
self.last_values = {} # dict <variable> of last known point (<time>, <value>)
self.last_time = {} # dict <stream> of last received time
@ -204,12 +201,11 @@ class InfluxGraph(HandlerBase):
config = {}
if chart_configs:
for chart_config in chart_configs:
for key, cfg in chart_config.variables.items():
for key, cfg in ChartConfig(chart_config).variables.items():
config.setdefault(key, {}).update(cfg)
if user_config:
for key, cfg in user_config.items():
config.setdefault(key, {}).update(cfg)
groups = {}
def add_to_groups(name, cat=None, unit='1', color='', label=None):