fix chart config parameters
- add SEA dil pressures - read config each time when it is used
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class ChartConfig:
|
class ChartConfig:
|
||||||
@ -16,16 +17,15 @@ class ChartConfig:
|
|||||||
Parameters :
|
Parameters :
|
||||||
path (str) : the path to the configuration file
|
path (str) : the path to the configuration file
|
||||||
"""
|
"""
|
||||||
self.errors = {}
|
|
||||||
self.variables = {}
|
self.variables = {}
|
||||||
cfgp = ConfigParser(interpolation=None)
|
cfgp = ConfigParser(interpolation=None)
|
||||||
cfgp.optionxform = str
|
cfgp.optionxform = str
|
||||||
cfgp.read(path)
|
cfgp.read(path)
|
||||||
section = cfgp["chart"]
|
try:
|
||||||
|
section = cfgp["chart"]
|
||||||
|
except KeyError:
|
||||||
|
return
|
||||||
for key, raw_value in section.items():
|
for key, raw_value in section.items():
|
||||||
if len(key.split('.')) > 1:
|
|
||||||
self.errors[key] = f'illegal key: {key}'
|
|
||||||
continue
|
|
||||||
arguments = raw_value.split(",")
|
arguments = raw_value.split(",")
|
||||||
keyword_mode = False
|
keyword_mode = False
|
||||||
config = {'cat': '*'}
|
config = {'cat': '*'}
|
||||||
@ -36,25 +36,11 @@ class ChartConfig:
|
|||||||
config[argname] = argvalue
|
config[argname] = argvalue
|
||||||
else:
|
else:
|
||||||
if keyword_mode:
|
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:
|
else:
|
||||||
try:
|
try:
|
||||||
if argvalue:
|
if argvalue:
|
||||||
config[self.KEYS[i]] = argvalue
|
config[self.KEYS[i]] = argvalue
|
||||||
except Exception as e:
|
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
|
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)
|
|
||||||
|
@ -19,6 +19,13 @@ T_sorb=unit:K,color:dark_violet
|
|||||||
T_sorb.target=-
|
T_sorb.target=-
|
||||||
T_still=unit:K,color:orange
|
T_still=unit:K,color:orange
|
||||||
dil=-
|
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=unit:%,color:brown
|
||||||
lev.n2=unit:%,color:black
|
lev.n2=unit:%,color:black
|
||||||
hefill=-
|
hefill=-
|
||||||
|
@ -58,14 +58,11 @@ class InfluxGraph(HandlerBase):
|
|||||||
self.server = server
|
self.server = server
|
||||||
self.db = server.db
|
self.db = server.db
|
||||||
# self.influx_data_getter = influx_data_getter
|
# self.influx_data_getter = influx_data_getter
|
||||||
self.chart_configs = [ChartConfig("./config/generic.ini")]
|
self.chart_configs = ["./config/generic.ini"]
|
||||||
self.instrument = instrument
|
self.instrument = instrument
|
||||||
self.device_name = device_name
|
self.device_name = device_name
|
||||||
if instrument: # TODO: should it not be better to have inifiles per device?
|
if instrument: # TODO: should it not be better to have inifiles per device?
|
||||||
try:
|
self.chart_configs.append(f"./config/{instrument}.ini")
|
||||||
self.chart_configs.append(ChartConfig(f"./config/{instrument}.ini"))
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
self.livemode = self.HISTORICAL
|
self.livemode = self.HISTORICAL
|
||||||
self.last_values = {} # dict <variable> of last known point (<time>, <value>)
|
self.last_values = {} # dict <variable> of last known point (<time>, <value>)
|
||||||
self.last_time = {} # dict <stream> of last received time
|
self.last_time = {} # dict <stream> of last received time
|
||||||
@ -204,12 +201,11 @@ class InfluxGraph(HandlerBase):
|
|||||||
config = {}
|
config = {}
|
||||||
if chart_configs:
|
if chart_configs:
|
||||||
for chart_config in 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)
|
config.setdefault(key, {}).update(cfg)
|
||||||
if user_config:
|
if user_config:
|
||||||
for key, cfg in user_config.items():
|
for key, cfg in user_config.items():
|
||||||
config.setdefault(key, {}).update(cfg)
|
config.setdefault(key, {}).update(cfg)
|
||||||
|
|
||||||
groups = {}
|
groups = {}
|
||||||
|
|
||||||
def add_to_groups(name, cat=None, unit='1', color='', label=None):
|
def add_to_groups(name, cat=None, unit='1', color='', label=None):
|
||||||
|
Reference in New Issue
Block a user