Removed lab4.json (now constants in influxdb.py), config.ini to influx.ini

This commit is contained in:
l_samenv
2024-09-09 10:51:18 +02:00
parent 400899643b
commit 2a4efff511
4 changed files with 9 additions and 25 deletions

View File

@ -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/"
}
}

View File

@ -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):
"""

View File

@ -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()))