Added live data functionnality + some docs in Python and JS code

This commit is contained in:
l_samenv
2024-07-24 11:41:24 +02:00
parent aa29d89a18
commit 5a82601e8e
6 changed files with 294 additions and 63 deletions

View File

@@ -66,7 +66,7 @@ def get_update(path=None):
logging.info('UPDATE %s %s', client.id, socket.getfqdn(flask.request.remote_addr.split(':')[-1]))
#msg = dict(type='id', id=client.id, title=instrument.title);
#yield to_json_sse(msg)
msg = dict(type='id', id=client.id, instrument=instrument.title, device=instrument.device);
msg = dict(type='id', id=client.id, instrument=instrument.title, device=instrument.device)
yield to_json_sse(msg)
try:
lastmsg = time.time()
@@ -498,6 +498,7 @@ class SeaGraph:
self.livemode = self.HISTORICAL
self.time = [0, 0]
self.lastvalues = {}
self.variables = []
def strip_future(self, result):
'strip future points (happens only on dummy test_day)'
@@ -527,13 +528,13 @@ class SeaGraph:
self.last_t = 0
start, end, now = seagraph.get_abs_time(time + [0])
self.time = [start, end]
self.variables = variables.split(',')
variables = variables.split(',')
self.livemode = self.ACTUAL if end >= now else self.HISTORICAL
logging.info('LIVE %g %g %d %d', end, now, end >= now, self.livemode)
self.scanner = seagraph.NumericScanner(instrument.logger_dir, instrument.test_day)
#result = self.scanner.get_message(self.variables, self.time)
#self.time[0] = self.time[1]
result = self.scanner.get_message(self.variables, self.time, show_empty=True)
result = self.scanner.get_message(variables, self.time, show_empty=True)
self.strip_future(result)
#for var in ('treg.set.reg', 'mf'):
# curve = result.get(var,[(0,0)])
@@ -557,6 +558,8 @@ class SeaGraph:
scanner = seagraph.VarsScanner(instrument.logger_dir, instrument.test_day)
result = dict(type='var_list')
result['blocks'] = list(scanner.get_message(time[-1]).values())
# updates the self.variables attribute to keep track of the available variables
self.variables = [variable["name"] for block in result['blocks'] for variable in block["curves"]]
return result
def w_updategraph(self):