Influx graph part only + device name on jump and start + fixed dselect z-index

This commit is contained in:
l_samenv
2024-08-21 10:05:47 +02:00
parent 2ea1674991
commit 89dd427a22
8 changed files with 115 additions and 12 deletions

View File

@ -60,7 +60,9 @@
<path d="M0 0h16v16H0z" fill="none"/> <path d="M0 0h16v16H0z" fill="none"/>
</svg> </svg>
</span> </span>
<span id="header"></span> <span id="header">
<span id="instrument"></span> <span id="device"></span>
</span>
</div> </div>
</div> </div>
<div id="center"></div> <div id="center"></div>

View File

@ -176,7 +176,7 @@ body.black .legend{
float: right; float: right;
background-color: #dddddd; background-color: #dddddd;
padding: 2px; padding: 2px;
/*z-index: 10; */ z-index: 10;
position: absolute; position: absolute;
top: 3px; top: 3px;
right: 3px; right: 3px;

View File

@ -95,7 +95,12 @@ function handleUpdateMessage(src, message) {
} }
var header = document.getElementById("header"); var header = document.getElementById("header");
header.style.width = 'auto'; header.style.width = 'auto';
header.innerHTML = clientTitle; let instrument = document.getElementById("instrument");
let device = document.getElementById("device");
instrument.style.width = 'auto'
device.style.width = 'auto'
instrument.innerHTML = message.instrument
device.innerHTML = message.device
console.log('ID', initCommands); console.log('ID', initCommands);
nextInitCommand(); nextInitCommand();
break; break;

View File

@ -768,7 +768,7 @@ let graphs = (function (){
AJAX("http://" + hostPort + "/getvars?time=" + msLeftTimestampGetVars/1000 + "," + msRightTimestampGetVars/1000 + "&all=" +allQueryParameterRepresentation(mode) + "&id="+ clientID).getJSON().then(function(data){ AJAX("http://" + hostPort + "/getvars?time=" + msLeftTimestampGetVars/1000 + "," + msRightTimestampGetVars/1000 + "&all=" +allQueryParameterRepresentation(mode) + "&id="+ clientID).getJSON().then(function(data){
blocks = data.blocks; blocks = data.blocks;
document.getElementById("device").innerHTML = data.device
maxTime = msRightTimestampGetGraph; maxTime = msRightTimestampGetGraph;
minTime = msLeftTimestampGetGraph; minTime = msLeftTimestampGetGraph;
@ -853,7 +853,7 @@ let graphs = (function (){
minTime = msLeftTimestamp; minTime = msLeftTimestamp;
blocks = data.blocks; blocks = data.blocks;
document.getElementById("device").innerHTML = data.device
ngraphs = 0; ngraphs = 0;
createGraphs(); createGraphs();
globalIndicators.getIndicatorsMap()[datesKey].update(currentMinTime); globalIndicators.getIndicatorsMap()[datesKey].update(currentMinTime);

View File

@ -175,7 +175,7 @@ function toggleHeader() {
var main_panel = document.getElementById("main-panel"); var main_panel = document.getElementById("main-panel");
panelOn = !panelOn; panelOn = !panelOn;
if (panelOn) { if (panelOn) {
header.innerHTML = clientTitle // header.innerHTML = clientTitle
/* header.style.width = "auto;"; */ /* header.style.width = "auto;"; */
main_panel.style.display = "block"; main_panel.style.display = "block";
} else { } else {

View File

@ -199,6 +199,19 @@ class InfluxDataGetter:
res[variable] = points res[variable] = points
return res return res
def get_device_name(self, time):
"""
Gets the device name available at time with stick and addons
Parameters :
time (int) : the Unix timestamp in seconds of the time we want the device name
Returns :
str : the device name
"""
components = self._get_device_name_components(time)
return "/".join(components)
# ----- PRIVATE METHODS # ----- PRIVATE METHODS
def _get_all_setup_info_as_dict(self, times, all=False): def _get_all_setup_info_as_dict(self, times, all=False):
@ -741,3 +754,31 @@ class InfluxDataGetter:
value = None value = None
res.append([t, value]) res.append([t, value])
return res return res
def _get_device_name_components(self, time):
"""
Gets the components of the device name, first in the main name, then stick, then addons.
Parameters :
time (int) : the Unix timestamp in seconds of the time we want the device name
Returns :
[str] : an array of string, each one being a component of the device name
"""
measurements = ["nicos/se_main", "nicos/se_stick", "nicos/se_addons"]
res = []
for measurement in measurements:
query = f"""
from(bucket: "{self._bucket}")
|> range(start: 0, stop: {time + 1})
|> filter(fn: (r) => r._measurement == "{measurement}")
|> filter(fn: (r) => r._field == "value")
|> last()
"""
tables = self._db.query(query)
for table in tables:
for record in table.records:
name = ast.literal_eval(record.get_value())
if name != None and name != '':
res.append(ast.literal_eval(record.get_value()))
return res

View File

@ -26,9 +26,8 @@ class InfluxGraph:
ACTUAL = 1 ACTUAL = 1
LIVE = 2 LIVE = 2
def __init__(self): def __init__(self, influx_data_getter):
self.db = InfluxDB() self.influx_data_getter = influx_data_getter
self.influx_data_getter = InfluxDataGetter(self.db, json.load(open("./graphs/lab4.json", "r"))["influx"])
self.livemode = self.HISTORICAL self.livemode = self.HISTORICAL
self.end_query = 0 self.end_query = 0
self.lastvalues = {} self.lastvalues = {}
@ -139,13 +138,14 @@ class InfluxGraph:
end_time = int(self.get_abs_time(time)[-1]) end_time = int(self.get_abs_time(time)[-1])
blocks = self.influx_data_getter.get_available_variables_at_time2([start_time, end_time], all) blocks = self.influx_data_getter.get_available_variables_at_time2([start_time, end_time], all)
device_name = self.influx_data_getter.get_device_name(end_time)
# updates the self.variables attribute to keep track of the available variables # updates the self.variables attribute to keep track of the available variables
self.variables = [variable["name"] for block in blocks for variable in block["curves"]] self.variables = [variable["name"] for block in blocks for variable in block["curves"]]
assign_colors_to_curves(blocks) assign_colors_to_curves(blocks)
result = dict(type='var_list') result = dict(type='var_list')
result['blocks'] = blocks result['blocks'] = blocks
result['device'] = device_name
return result return result
def w_updategraph(self): def w_updategraph(self):

View File

@ -11,7 +11,7 @@ import time
import pprint import pprint
import random import random
import time import time
from datetime import date from datetime import date, datetime
from collections import deque from collections import deque
import sys import sys
import socket import socket
@ -27,6 +27,7 @@ import signal
from influxgraph import InfluxGraph from influxgraph import InfluxGraph
from influxdb import InfluxDB, InfluxDataGetter
try: import simplejson as json try: import simplejson as json
except ImportError: import json except ImportError: import json
@ -498,11 +499,28 @@ class SeaInstrument(Instrument):
class SeaInfluxInstrument(SeaInstrument): 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.device = self.influx_data_getter.get_device_name(int(datetime.now().timestamp()))
def newClient(self): def newClient(self):
if not self.seaspy.connected: if not self.seaspy.connected:
self.init() self.init()
return self.register(SeaInfluxClient()) return self.register(SeaInfluxClient())
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.clients = {}
self.title = instr_name
self.device = self.influx_data_getter.get_device_name(int(datetime.now().timestamp()))
def newClient(self):
return self.register(InfluxClient())
class SeaGraph: class SeaGraph:
HISTORICAL = 0 HISTORICAL = 0
@ -679,6 +697,36 @@ class SeaParams:
return dict(type='accept-command') return dict(type='accept-command')
class InfluxParams:
"""Class with dummy routes, in case client side is started with the right part init commands"""
def __init__(self):
self.id = uuid.uuid4().hex[0:15]
self.queue = []
def poll(self):
messages = self.queue
self.queue = []
msg = self.graphpoll()
if msg:
messages.append(msg)
return messages
def info(self):
return ["na"]
def w_getblock(self, path):
return dict(type='draw', title="graph", path=path, components=[])
def w_updateblock(self, path):
return dict(type='accept-block')
def w_console(self):
return dict(type='accept-console')
def w_sendcommand(self, command):
return dict(type='accept-command')
class SeaClient(SeaParams, SeaGraph): class SeaClient(SeaParams, SeaGraph):
def __init__(self): def __init__(self):
SeaParams.__init__(self) SeaParams.__init__(self)
@ -688,7 +736,12 @@ class SeaClient(SeaParams, SeaGraph):
class SeaInfluxClient(SeaParams, InfluxGraph): class SeaInfluxClient(SeaParams, InfluxGraph):
def __init__(self): def __init__(self):
SeaParams.__init__(self) SeaParams.__init__(self)
InfluxGraph.__init__(self) InfluxGraph.__init__(self, instrument.influx_data_getter)
class InfluxClient(InfluxParams, InfluxGraph):
def __init__(self):
InfluxParams.__init__(self)
InfluxGraph.__init__(self, instrument.influx_data_getter)
class DummyClient(SeaGraph): class DummyClient(SeaGraph):
@ -1015,6 +1068,8 @@ if __name__ == '__main__':
instrument = SeaInstrument(inst_name, instrument_config) instrument = SeaInstrument(inst_name, instrument_config)
elif type == 'influxsea': elif type == 'influxsea':
instrument = SeaInfluxInstrument(inst_name, instrument_config) instrument = SeaInfluxInstrument(inst_name, instrument_config)
elif type == 'influx':
instrument = InfluxInstrument(inst_name)
elif type == 'dummy': elif type == 'dummy':
instrument = DummyInstrument(inst_name, instrument_config) instrument = DummyInstrument(inst_name, instrument_config)
elif type == 'secop': elif type == 'secop':