diff --git a/client/jsFiles/SEAWebClientCommunication.js b/client/jsFiles/SEAWebClientCommunication.js index 3cbacde..c95612e 100644 --- a/client/jsFiles/SEAWebClientCommunication.js +++ b/client/jsFiles/SEAWebClientCommunication.js @@ -406,8 +406,9 @@ function successHandler(s, message) { begin = timeRange[0] - timeRange[1]; select.value = begin; // Server-request for variable-list.*/ + console.log('TIME', window['clientTags'], timeRange) reqJSONPOST(0, "http://" + hostPort + "/getvars", - "time=" + timeRange[1] + "time=" + timeRange[0] + ',' + timeRange[1] + window['clientTags'] + "&userconfiguration=" + JSON.stringify(getFormattedUserConfigurationFromLocalStorage()) + "&id=" + clientID, successHandler, errorHandler); diff --git a/client/jsFiles/SEAWebClientGraphics.js b/client/jsFiles/SEAWebClientGraphics.js index 6a80407..572a228 100644 --- a/client/jsFiles/SEAWebClientGraphics.js +++ b/client/jsFiles/SEAWebClientGraphics.js @@ -1073,7 +1073,7 @@ let graphs = (function (){ currentMaxTime = maxTime; currentMinTime = minTime; } - AJAX("http://" + hostPort + "/gettime?time=-1800,0&id="+ clientID).getJSON().then(function(data){ + AJAX("http://" + hostPort + "/gettime?time=" + window['timerange'] + "&id="+ clientID).getJSON().then(function(data){ startTime = data.time[1]*1000; maxTime = startTime; currentMaxTime = maxTime + 60000; diff --git a/client/jsFiles/SEAWebClientMain.js b/client/jsFiles/SEAWebClientMain.js index b54fabd..52f5e2a 100644 --- a/client/jsFiles/SEAWebClientMain.js +++ b/client/jsFiles/SEAWebClientMain.js @@ -93,7 +93,8 @@ new Settings() .treat("showAsync", "sa", to_bool, false) .treat("device", "dev", 0, "*") .treat("server", "srv", 0, "*") - .treat("instrument", "ins", 0, "") + .treat("instrument", "instrument", 0, "") + .treat("timerange", "time", 0, "-1800,0") if (window['instrument']) { window['clientTags'] = "&instrument=" + window["instrument"]; @@ -111,11 +112,11 @@ function loadFirstBlocks() { if (showMain) pushInitCommand("getblock?path=main&", "main") if (showConsole) pushInitCommand("console?", "console") if (nColumns == 1) { // probably mobile phone} - if (showGraphics) pushInitCommand("gettime?time=-1800,0&", "graphics") + if (showGraphics) pushInitCommand("gettime?time=" + window["timerange"] + "&", "graphics") if (showOverview) pushInitCommand("getblock?path=_overview&", "overview") } else { if (showOverview) pushInitCommand("getblock?path=_overview&", "overview") - if (showGraphics) pushInitCommand("gettime?time=-1800,0&", "graphics") + if (showGraphics) pushInitCommand("gettime?time=" + window["timerange"] + "&", "graphics") // last is shown first } } diff --git a/influxgraph.py b/influxgraph.py index 7ad9a10..d57254d 100644 --- a/influxgraph.py +++ b/influxgraph.py @@ -5,7 +5,7 @@ import io import uuid from configparser import ConfigParser from math import ceil -from sehistory.influx import InfluxDBWrapper +from sehistory.seinflux import SEHistory from colors import assign_colors_to_curves from chart_config import ChartConfig from base import Instrument, get_abs_time @@ -84,8 +84,10 @@ class InfluxGraph: logging.info('LIVE %g %g %d %d', end, now, end >= now, self.livemode) if interval: interval = float(interval) + print('CURVES', start - now, end - now, self.tags) result = self.db.curves(start, end, queried_variables, merge='_measurement', interval=interval or None, **self.tags) + print('LEN', len(result)) self.update_last(result) self.db.complete(result, self.last_time, 'stream') self.last_minute = now // 60 @@ -145,19 +147,19 @@ class InfluxGraph: self.tags = split_tags(tags) if instrument: - tags['stream'] = list(self.db.get_streams(instrument)) - print('GETAV', self.tags) + self.tags['stream'] = list(self.db.get_streams(instrument)) + print('TAGS', self.tags) blocks = self.get_available_variables(start_time, end_time, self.chart_configs, userconfiguration) - device_name = tags.get('device', '') + device_name = self.tags.get('device', '') # initialize self.last_values to keep track of the available variables self.last_values = {var["name"]: [0, None] for block in blocks for var in block["curves"]} assign_colors_to_curves(blocks) result = dict(type='var_list') result['blocks'] = blocks result['device'] = device_name - print('DEVICE', device_name, tags) - for block in blocks: - print(block['tag'], [c['name'] for c in block['curves']]) + # print('DEVICE', device_name, tags) + # for block in blocks: + # print(block['tag'], [c['name'] for c in block['curves']]) return result def get_available_variables(self, start_time, end_time, chart_configs=None, user_config=None): @@ -307,7 +309,7 @@ class InfluxGraph: # the server is only waiting after a None return # this avoids to many queries with expected empty result return None - last_time = int(min(self.last_time.values())) + last_time = int(min(self.last_time.values(), default=now-3600)) # if len(self.last_time) > 1: # print('time_poll_jitter', max(self.last_time.values()) - min(self.last_time.values())) prev_minute, self.last_minute = self.last_minute, now // 60 @@ -416,7 +418,7 @@ class SecopInfluxInstrument(SecopInstrument): config.optionxform = str config.read("./config/influx.ini") section = config["INFLUX"] - self.db = InfluxDBWrapper('linse-c') + self.db = SEHistory() # self.db = InfluxDBWrapper(uri=section["url"], token=section["token"], # org=section["org"], bucket=section['bucket']) # self.influx_data_getter = InfluxDataGetter(self.db, inst_name) @@ -425,7 +427,9 @@ class SecopInfluxInstrument(SecopInstrument): def new_client(self): return self.register(SecopInfluxClient(self)) - def get_stream_tags(self, timestamp=None): + def get_streams(self, timestamp=None): return self.db.get_streams(None, timestamp) + def get_experiments(self, start=None, stop=None): + return self.db.get_experiments(start, stop) diff --git a/webserver.py b/webserver.py index 9ba7bda..2924b31 100755 --- a/webserver.py +++ b/webserver.py @@ -88,7 +88,6 @@ def get_update(path=None): logging.info('CLOSED %s', client.id) print('CLOSE client') instrument.remove(client) - pass except Exception as e: logging.info('error') logging.error('%s', traceback.format_exc()) @@ -211,21 +210,21 @@ def replace_by_empty(file): @app.route('/') -def main(): +def default(): return general_file('SEAWebClient.html') -@app.route('/select') -def default(): +@app.route('/select_instrument') +def select_instrument(): out = [''' -'''] +'''] result = {} - for stream, tags in instrument.get_stream_tags().items(): + for stream, tags in instrument.get_streams().items(): ins = tags.get('instrument', '0') result.setdefault(ins, []).append((stream, tags.get('device'))) bare_streams = result.pop('0', []) @@ -235,7 +234,76 @@ th { out.append('') for stream, device in bare_streams: out.append(f'') - out.extend(['
InstrumentDevices
instrumentdevices
{stream}{device}
', '']) + out.extend(['', '']) + return '\n'.join(out) + + +@app.route('/select_experiment') +def select_experiment(): + out = [''' + +'''] + showtitle = 0 + ONEMONTH = 30 * 24 * 3600 + + def title(text): + out.append(f'') + + # TODO: sort this by (instrument / device) and list dates + # period format: Ymd..Ymd, Ymd (single date), Ymd..now, HM..now + try: + now = time.time() + timerange = flask.request.values.get('time') + if timerange == 'all': + starttime, endtime = None, None + elif timerange: + timerange = timerange.split(',') + starttime, endtime = [None if timerange[i] == '0' else int(timerange[i]) for i in (0, -1)] + else: + starttime, endtime = now - ONEMONTH, now + + chunk_list = [] + for key, chunk_dict in instrument.get_experiments(starttime, endtime).items(): + for (streams, devices), chunks in chunk_dict.items(): + chunk_list.extend((r[1], r[0], key, devices) for r in chunks) + chunk_list.sort(reverse=True) + for end, beg, key, devices in chunk_list: + today, begdate, enddate = (time.strftime("%Y-%m-%d", time.localtime(t)) for t in (now, beg, end)) + args = ['='.join(key)] + if end > now: + if begdate == today: + daterange = f'since {time.strftime("%H:%M", time.localtime(beg))}' + else: + daterange = f'since {begdate}' + if showtitle == 0: + title('currently running') + showtitle = 1 + else: + daterange = begdate if begdate == enddate else f'{begdate}...{enddate}' + if end > now - ONEMONTH: + if showtitle == 1: + title('older than 30 days') + showtitle = 2 + + print('A', args) + out.append(f'') + out.append(f'') + if timerange: + out.append(f'

earlier dates


') + out.extend(['
{text}
{key[1]} / {" ".join(devices)}{daterange}
', '']) + except Exception as e: + logging.error('%s', traceback.format_exc()) + circularlog.log() + out = [f"ERROR {e!r}"] + return '\n'.join(out)