diff --git a/config/config.ini b/config/influx.ini similarity index 100% rename from config/config.ini rename to config/influx.ini diff --git a/graphs/lab4.json b/graphs/lab4.json deleted file mode 100644 index d7cb517..0000000 --- a/graphs/lab4.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "types": - { - "graph":"influx", - "control":"sea" - }, - "influx": - { - "bucket_prefix":"nicos-cache-", - "bucket":"nicos-cache-lab4", - "measurement_prefix":"nicos/se_", - "setup_info_prefix":"se_" - }, - "sea":{ - "address":"samenv:8664", - "logger_dir":"/home/l_samenv/sea/lab4/" - } -} \ No newline at end of file diff --git a/influxdb.py b/influxdb.py index ad5a933..dfae620 100644 --- a/influxdb.py +++ b/influxdb.py @@ -6,13 +6,16 @@ from datetime import datetime from pandas import DataFrame as df, merge_ordered from numpy import NaN +MEASURMENT_PREFIX = "nicos/se_" +BUCKET_PREFIX = "nicos-cache-" + class InfluxDB: """ Class used to handle the connection with the InfluxDB instance """ def __init__(self): config = ConfigParser() - config.read("./config/config.ini") + config.read("./config/influx.ini") self._client = InfluxDBClient(url=config["INFLUX"]["url"], token=config["INFLUX"]["token"], org=config["INFLUX"]["org"]) @@ -51,9 +54,8 @@ class PrettyFloat(float): return '%.15g' % self class InfluxDataGetter: - def __init__(self, db, influx_instrument_config): - self._influx_instrument_config = influx_instrument_config - self._bucket = self._influx_instrument_config["bucket"] + def __init__(self, db, instrument_name): + self._bucket = BUCKET_PREFIX + instrument_name self._db = db # ----- PUBLIC METHODS @@ -378,7 +380,7 @@ class InfluxDataGetter: Returns : str : the transformed variable name that matches the Influx names reqauirements """ - return self._influx_instrument_config["measurement_prefix"] + secop_module_name.lower() + return MEASURMENT_PREFIX + secop_module_name.lower() def _filter_params_with_config(self, available_variables, chart_config): """ diff --git a/seaweb.py b/seaweb.py index 0cf8e78..0bb15b7 100755 --- a/seaweb.py +++ b/seaweb.py @@ -533,7 +533,7 @@ class SeaInfluxInstrument(SeaInstrument): def __init__(self, inst_name, instrument_config): super().__init__(inst_name, instrument_config) self.db = InfluxDB() - self.influx_data_getter = InfluxDataGetter(self.db, json.load(open("./graphs/lab4.json", "r"))["influx"]) + self.influx_data_getter = InfluxDataGetter(self.db, inst_name) self.device = self.influx_data_getter.get_device_name(int(datetime.now().timestamp())) def newClient(self): @@ -545,7 +545,7 @@ class InfluxInstrument(Instrument): def __init__(self, instr_name): self.db = InfluxDB() - self.influx_data_getter = InfluxDataGetter(self.db, json.load(open("./graphs/lab4.json", "r"))["influx"]) + self.influx_data_getter = InfluxDataGetter(self.db, inst_name) self.clients = {} self.title = instr_name self.device = self.influx_data_getter.get_device_name(int(datetime.now().timestamp()))