from time import time as current_time import logging import json import io import uuid from configparser import ConfigParser from math import ceil from sehistory.seinflux import SEHistory from colors import assign_colors_to_curves from chart_config import ChartConfig from base import Instrument, get_abs_time from secop import SecopClient, SecopInstrument def split_tags(tags): return {k: v.split(',') for k, v in tags.items()} class InfluxGraph: """Class implementing the logic of the different routes that are called by the client to retrieve graph data with InfluxDB. Global constants : HISTORICAL (int) : value that represents the "historical" visualization mode, meaning that the most recent point is not in the visualisation window (no live data is sent). ACTUAL (int) : value that represents the "actual" visualization mode, wihch is an intermediate state used before going for live mode (the requested time window includes now) LIVE (int) : value that represents the "live" visualization mode, meaning that new points are sent to the client. Attributes : influx_data_getter (InfluxDataGetter) : the InfluxDataGetter instance that allows to get data out of InfluxDB. chart_configs ([ChartConfig]) : an array of chart configuration to apply when /getvars is called livemode (int) : the type of visualization the user is currently in. Can be HISTORICAL, ACTUAL or LIVE. end_query (int) : the unix timestamp in seconds of the most recent requested point in time of the last query or update. last_values ({(str):((int), (float))}) : a dictionnary where the keys are the variable names, and the values are tuples, where the first value is the unix timestamp of the most recent value known for this variable, and the second value its corresponding value variables ({(str):(str)}) : a dictionary of the current available variables requested by the client. The key is the InfluxDB name of the curve, and the value is its label in the GUI. """ HISTORICAL = 0 ACTUAL = 1 LIVE = 2 def __init__(self, instrument): self.instrument = instrument self.db = instrument.db instrument_name = instrument.title # self.influx_data_getter = influx_data_getter self.chart_configs = [ChartConfig("./config/generic.ini")] try: self.chart_configs.append(ChartConfig(f"./config/{instrument_name}.ini")) except KeyError: pass self.livemode = self.HISTORICAL self.last_values = {} # dict of last known point (