From a4fda418b289109a3eca51f3f4fe10d5bfb58f05 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 13 May 2025 10:49:10 +0200 Subject: [PATCH] fix chart config parameters - add SEA dil pressures - read config each time when it is used --- chart_config.py | 28 +++++++--------------------- config/generic.ini | 7 +++++++ influxgraph.py | 10 +++------- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/chart_config.py b/chart_config.py index f61bc43..7fea3b4 100644 --- a/chart_config.py +++ b/chart_config.py @@ -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 ([.]) - - 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) diff --git a/config/generic.ini b/config/generic.ini index f7b9228..abd328c 100644 --- a/config/generic.ini +++ b/config/generic.ini @@ -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=- diff --git a/influxgraph.py b/influxgraph.py index 570d2e3..2d7bcba 100644 --- a/influxgraph.py +++ b/influxgraph.py @@ -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 of last known point (