Influx graph part only + device name on jump and start + fixed dselect z-index
This commit is contained in:
@ -60,7 +60,9 @@
|
||||
<path d="M0 0h16v16H0z" fill="none"/>
|
||||
</svg>
|
||||
</span>
|
||||
<span id="header"></span>
|
||||
<span id="header">
|
||||
<span id="instrument"></span> <span id="device"></span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="center"></div>
|
||||
|
@ -176,7 +176,7 @@ body.black .legend{
|
||||
float: right;
|
||||
background-color: #dddddd;
|
||||
padding: 2px;
|
||||
/*z-index: 10; */
|
||||
z-index: 10;
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
right: 3px;
|
||||
|
@ -95,7 +95,12 @@ function handleUpdateMessage(src, message) {
|
||||
}
|
||||
var header = document.getElementById("header");
|
||||
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);
|
||||
nextInitCommand();
|
||||
break;
|
||||
|
@ -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){
|
||||
blocks = data.blocks;
|
||||
|
||||
document.getElementById("device").innerHTML = data.device
|
||||
maxTime = msRightTimestampGetGraph;
|
||||
minTime = msLeftTimestampGetGraph;
|
||||
|
||||
@ -853,7 +853,7 @@ let graphs = (function (){
|
||||
minTime = msLeftTimestamp;
|
||||
|
||||
blocks = data.blocks;
|
||||
|
||||
document.getElementById("device").innerHTML = data.device
|
||||
ngraphs = 0;
|
||||
createGraphs();
|
||||
globalIndicators.getIndicatorsMap()[datesKey].update(currentMinTime);
|
||||
|
@ -175,7 +175,7 @@ function toggleHeader() {
|
||||
var main_panel = document.getElementById("main-panel");
|
||||
panelOn = !panelOn;
|
||||
if (panelOn) {
|
||||
header.innerHTML = clientTitle
|
||||
// header.innerHTML = clientTitle
|
||||
/* header.style.width = "auto;"; */
|
||||
main_panel.style.display = "block";
|
||||
} else {
|
||||
|
41
influxdb.py
41
influxdb.py
@ -199,6 +199,19 @@ class InfluxDataGetter:
|
||||
res[variable] = points
|
||||
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
|
||||
|
||||
def _get_all_setup_info_as_dict(self, times, all=False):
|
||||
@ -741,3 +754,31 @@ class InfluxDataGetter:
|
||||
value = None
|
||||
res.append([t, value])
|
||||
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
|
@ -26,9 +26,8 @@ class InfluxGraph:
|
||||
ACTUAL = 1
|
||||
LIVE = 2
|
||||
|
||||
def __init__(self):
|
||||
self.db = InfluxDB()
|
||||
self.influx_data_getter = InfluxDataGetter(self.db, json.load(open("./graphs/lab4.json", "r"))["influx"])
|
||||
def __init__(self, influx_data_getter):
|
||||
self.influx_data_getter = influx_data_getter
|
||||
self.livemode = self.HISTORICAL
|
||||
self.end_query = 0
|
||||
self.lastvalues = {}
|
||||
@ -139,13 +138,14 @@ class InfluxGraph:
|
||||
end_time = int(self.get_abs_time(time)[-1])
|
||||
|
||||
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
|
||||
self.variables = [variable["name"] for block in blocks for variable in block["curves"]]
|
||||
|
||||
assign_colors_to_curves(blocks)
|
||||
result = dict(type='var_list')
|
||||
result['blocks'] = blocks
|
||||
result['device'] = device_name
|
||||
return result
|
||||
|
||||
def w_updategraph(self):
|
||||
|
59
seaweb.py
59
seaweb.py
@ -11,7 +11,7 @@ import time
|
||||
import pprint
|
||||
import random
|
||||
import time
|
||||
from datetime import date
|
||||
from datetime import date, datetime
|
||||
from collections import deque
|
||||
import sys
|
||||
import socket
|
||||
@ -27,6 +27,7 @@ import signal
|
||||
|
||||
from influxgraph import InfluxGraph
|
||||
|
||||
from influxdb import InfluxDB, InfluxDataGetter
|
||||
|
||||
try: import simplejson as json
|
||||
except ImportError: import json
|
||||
@ -498,11 +499,28 @@ class SeaInstrument(Instrument):
|
||||
|
||||
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):
|
||||
if not self.seaspy.connected:
|
||||
self.init()
|
||||
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:
|
||||
HISTORICAL = 0
|
||||
@ -679,6 +697,36 @@ class SeaParams:
|
||||
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):
|
||||
def __init__(self):
|
||||
SeaParams.__init__(self)
|
||||
@ -688,7 +736,12 @@ class SeaClient(SeaParams, SeaGraph):
|
||||
class SeaInfluxClient(SeaParams, InfluxGraph):
|
||||
def __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):
|
||||
@ -1015,6 +1068,8 @@ if __name__ == '__main__':
|
||||
instrument = SeaInstrument(inst_name, instrument_config)
|
||||
elif type == 'influxsea':
|
||||
instrument = SeaInfluxInstrument(inst_name, instrument_config)
|
||||
elif type == 'influx':
|
||||
instrument = InfluxInstrument(inst_name)
|
||||
elif type == 'dummy':
|
||||
instrument = DummyInstrument(inst_name, instrument_config)
|
||||
elif type == 'secop':
|
||||
|
Reference in New Issue
Block a user