work on select_experiment

- on currently running exp. make two links, to instrument
  or history only
- create dummy secop client when hideRightPart is used in order
  to avoid waiting impossible connection
This commit is contained in:
2025-05-21 11:35:25 +02:00
parent 55dd7a3777
commit 7d4607e947
2 changed files with 38 additions and 23 deletions

View File

@ -84,6 +84,7 @@ if (window.instrument) {
let args = '';
if (window.stream) { args += "&stream=" + window.stream; }
if (window.device) { args += "&device=" + window.device; }
if (window.hideRightPart) { args += "&history_only=1"; }
window.clientTags = args;
}

View File

@ -91,9 +91,13 @@ class Server:
tags['device'] = devices[0] if len(devices) == 1 else devices
return streams, tags, ','.join(device_names)
def register_client(self, instrument=None, stream=None, device=None):
def register_client(self, instrument=None, stream=None, device=None, history_only='0'):
streams, tags, device_name = self.lookup_streams(instrument, stream, device)
client = self.client_cls(self, streams, instrument or '', device_name)
if history_only != '0':
# create dummy client
client = self.client_cls(self, [], '', '')
else:
client = self.client_cls(self, streams, instrument or '', device_name)
history = self.history_cls(self, instrument, device_name, tags)
# history.db.debug = True
# all relevant methods of the history instance are saved in client.handlers
@ -142,7 +146,7 @@ pollinterval = 0.2
@app.route('/update')
def get_update(_=None):
# Client Adress: socket.getfqdn(flask.request.remote_addr)
kwargs = {k: flask.request.values.get(k) for k in ('instrument', 'stream', 'device')}
kwargs = {k: flask.request.values.get(k) for k in ('instrument', 'stream', 'device', 'history_only')}
client = server.register_client(**kwargs)
client.remote_info = circularlog.strtm() + " " + socket.getfqdn(flask.request.remote_addr.split(':')[-1])
@ -352,11 +356,16 @@ a {
</style></head>
<body><table>
''']
showtitle = 0
ONEMONTH = 30 * 24 * 3600
def title(text):
out.append(f'<tr><td colspan=2><h3>{text}</h3></td></tr>')
prevtitle = [None]
def change_title(text):
if text == prevtitle[0]:
return False
prevtitle[0] = text
out.append(f'<tr><td colspan=3><b>{text}</b></td></tr>')
return True
# TODO: sort this by (instrument / device) and list dates
# period format: Ymd..Ymd, Ymd (single date), Ymd..now, HM..now
@ -379,36 +388,41 @@ a {
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))
port = None
host = ''
if key[0] == 'instrument':
if key[0] == 'instrument':
ins = key[1]
port = instruments.get(ins)
if port is None:
args = ['='.join(key)]
else:
host = f'http://{ins}.psi.ch:{port}'
args = []
args = ['='.join(key)]
remote = None if port is None else f'http://{ins}.psi.ch:{port}'
history_only = bool(remote)
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
if change_title('currently running'):
out.append('<tr><td>instrument</td><td>history only</td><td></td></tr>')
else:
history_only = True
remote = None
daterange = begdate if begdate == enddate else f'{begdate}...{enddate}'
if end < now - ONEMONTH:
if showtitle == 1:
title('older than 30 days')
showtitle = 2
out.append(f'<tr><th><a href="{host}/?{"&".join(args)}">{key[1]} / {" ".join(devices)}</a></th>')
if end > now - ONEMONTH:
change_title('recently running')
else:
change_title('older than 30 days')
if history_only:
args.append('hr=1')
link = f'<a href="/?{"&".join(args)}">'
label = " ".join(devices)
if remote:
out.append(f'<tr><th><a href="{remote}">{ins.upper()}</a></th><th>{link}{label}</a></th>')
else:
out.append(f'<tr><th colspan=2>{link}{key[1]}&nbsp;{label}</a></th>')
out.append(f'<td>{daterange}</td></tr>')
if timerange:
out.append(f'<h3><a href="/select_experiment?time=all">earlier dates</a></h3><br>')
out.append('</table>')
out.append('<h3><a href="http://linse-c.psi.ch:8888/">central server</a></h3>')
if server.db.has_local:
out.append('<h3><a href="http://linse-c.psi.ch:8888/">central server</a></h3>')
out.append('<h3>direct link to instruments:</h3>')
out.extend([f'<a href="http://{ins}.psi.ch:{port}/">{ins.upper()}</a>&nbsp;\n'
for ins, port in instruments.items()])