diff --git a/PythonServer/screens/ts2_helevpres.py b/PythonServer/screens/ts2_helevpres.py index 2bb93d43dfc98d3c9fa5c4bf8e288c4f29ee05ce..633c215cdb15999f68544fbbb87295891b42bf4d 100755 --- a/PythonServer/screens/ts2_helevpres.py +++ b/PythonServer/screens/ts2_helevpres.py @@ -3,6 +3,9 @@ import json import time import sys import numpy +import pandas +import datetime +import requests from threading import Thread @@ -55,6 +58,28 @@ def p2t(p): return t +def get_from_archiver(pv, start_date, end_date): + try: + url = "http://archiver-01.tn.esss.lu.se:17668/retrieval/data/getData.json?pv=ncount({})&from={}&to={}".format( + pv, start_date, end_date + ) + entries = int(requests.get(url).json()[0]["data"][0]["val"]) + url = "http://archiver-01.tn.esss.lu.se:17668/retrieval/data/getData.json?pv=nth_{}({})&from={}&to={}".format( + int(entries // 100), pv, start_date, end_date + ) + r = requests.get(url).json()[0]["data"] + raw_data = pandas.DataFrame.from_dict(r) + return list( + zip( + (raw_data["secs"] * 1000).astype("int") + + (raw_data["nanos"] / 1e6).astype("int"), + round(raw_data["val"], 3), + ) + ) + except Exception: + return [] + + class ts2_helevpresScreen(Thread): def __init__(self, stop_signal): Thread.__init__(self) @@ -67,41 +92,74 @@ class ts2_helevpresScreen(Thread): "TS2-010CRM:Cryo-LT-001:MeasValue", "TS2-010CRM:Cryo-LT-002:MeasValue", ] + intervals = {"2w": 24 * 14, "1w": 24 * 7, "2d": 24 * 2, "1d": 24, "live": 1} epics_dict = {} for pv in pvs: epics_dict[pv] = epics.PV(pv, auto_monitor=True) + json_dict = {} + counter = 0 while not self.stop_signal.isSet(): try: - json_dict = {} for pv in epics_dict: - json_dict[pv] = {} - if epics_dict[pv].connected: - json_dict[pv]["units"] = epics_dict[pv].units - json_dict[pv]["timestamp"] = epics_dict[pv].timestamp - value = epics_dict[pv].value - if type(value) == float: - json_dict[pv]["value"] = round(value, 3) - else: - json_dict[pv]["value"] = value - else: - json_dict[pv]["units"] = "n.c." - json_dict[pv]["timestamp"] = "" - json_dict[pv]["value"] = "" - if pv == "TS2-010CRM:Cryo-PT-003:MeasValue": - json_dict[pv]["temp"] = round(p2t(json_dict[pv]["value"]), 3) + json_dict[pv] = {} + if epics_dict[pv].connected: + json_dict[pv]["units"] = epics_dict[pv].units + json_dict[pv]["timestamp"] = epics_dict[pv].timestamp + json_dict[pv]["temp"] = "N/A" + value = epics_dict[pv].value + if type(value) == float: + json_dict[pv]["value"] = round(value, 3) + json_dict[pv]["temp"] = round( + p2t(json_dict[pv]["value"]), 3 + ) + else: + json_dict[pv]["value"] = value if pv == "TS2-010CRM:Cryo-PT-004:MeasValue": - if ( - numpy.isreal(json_dict[pv]["value"]) - and json_dict[pv]["value"] <= 65 - ): - json_dict[pv]["temp"] = round( - p2t(json_dict[pv]["value"]), 3 - ) - else: + json_dict[pv] = {} + if epics_dict[pv].connected: + json_dict[pv]["units"] = epics_dict[pv].units + json_dict[pv]["timestamp"] = epics_dict[pv].timestamp json_dict[pv]["temp"] = "N/A" + value = epics_dict[pv].value + if type(value) == float: + json_dict[pv]["value"] = round(value, 3) + if value <= 65: + json_dict[pv]["temp"] = round( + p2t(json_dict[pv]["value"]), 3 + ) + else: + json_dict[pv]["value"] = value + if ( + pv == "TS2-010CRM:Cryo-LT-001:MeasValue" + or pv == "TS2-010CRM:Cryo-LT-002:MeasValue" + ): + if counter % 7200 == 0: + json_dict[pv] = {} + for interval in intervals: + start_date = ( + datetime.datetime.now() + - datetime.timedelta(hours=intervals[interval]) + ).isoformat() + "Z" + end_date = datetime.datetime.now().isoformat() + "Z" + json_dict[pv][interval] = get_from_archiver( + pv, start_date, end_date + ) + counter = 0 + else: + if epics_dict[pv].connected: + value = epics_dict[pv].value + timestamp = int(epics_dict[pv].timestamp * 1000) + if ( + type(value) == float + and timestamp != json_dict[pv]["live"][-1][0] + ): + json_dict[pv]["live"] = json_dict[pv]["live"][1:] + json_dict[pv]["live"].append( + (timestamp, round(value, 3)) + ) tmp_json = json.dumps(json_dict) tmp_json = tmp_json.replace("NaN", "0") @@ -112,6 +170,7 @@ class ts2_helevpresScreen(Thread): print(sys.exc_info()) time.sleep(1) time.sleep(0.5) + counter += 1 for pv in epics_dict: epics_dict[pv].clear_auto_monitor() diff --git a/WebSites/ts2_helevpres/dashboard.json b/WebSites/ts2_helevpres/dashboard.json index 5acfd8f2ca90155e622f9e5506cfc70e4c06900a..45430d0da863bcfb9a3c04d56aa9a32462c4c4ca 100644 --- a/WebSites/ts2_helevpres/dashboard.json +++ b/WebSites/ts2_helevpres/dashboard.json @@ -31,69 +31,56 @@ ] }, { - "title": "Level Probes", + "title": "Levels", "width": 1, "row": { - "1": 7, - "2": 7, - "3": 7, - "4": 7, - "5": 7, - "6": 7, - "7": 7 + "4": 11, + "5": 1 }, "col": { - "1": 1, - "2": 1, - "3": 1, "4": 1, - "5": 1, - "6": 1, - "7": 1 + "5": 5 }, - "col_width": 1, + "col_width": 2, "widgets": [ { - "type": "vertical-linear-gauge", + "type": "flot_extended_plugin", "settings": { - "title": "<a href=\"https://pos.esss.lu.se/plot/retrieval/ui/viewer/archViewer.html?pv=TS2-010CRM:Cryo-LT-001:MeasValue&pv=TS2-010CRM:Cryo-LT-002:MeasValue\" target=\"_blank\">LT-001 Level Sensor 1</a>", - "value": "datasources[\"TS2\"][\"TS2-010CRM:Cryo-LT-001:MeasValue\"][\"value\"]", - "units": "%", - "min_value": "0", - "max_value": 100 - } - }, - { - "type": "vertical-linear-gauge", - "settings": { - "title": "<a href=\"https://pos.esss.lu.se/plot/retrieval/ui/viewer/archViewer.html?pv=TS2-010CRM:Cryo-LT-001:MeasValue&pv=TS2-010CRM:Cryo-LT-002:MeasValue\" target=\"_blank\">LT-002 Level Sensor 2</a>", - "value": "datasources[\"TS2\"][\"TS2-010CRM:Cryo-LT-002:MeasValue\"][\"value\"]", - "units": "%", - "min_value": 0, - "max_value": 100 + "plot_type": "line", + "legend": true, + "height": 4, + "value": "var series = document.getElementById(\"time-series\").value;\ndata = [\n {label: 'TS2-010CRM:Cryo-LT-001', data: datasources[\"TS2\"][\"TS2-010CRM:Cryo-LT-001:MeasValue\"][series]},\n {label: 'TS2-010CRM:Cryo-LT-002', data: datasources[\"TS2\"][\"TS2-010CRM:Cryo-LT-002:MeasValue\"][series]},\n];\nfreeboard.showLoadingIndicator(false);\nreturn data;", + "x_timestamp": true, + "zoom": "" } } ] }, { - "title": "Pressures", + "title": "TS2-010CRM:Cryo-PT-003", "width": 1, "row": { "2": 7, "3": 7, - "4": 7 + "4": 7, + "5": 7, + "6": 7, + "7": 7 }, "col": { "2": 2, "3": 2, - "4": 2 + "4": 3, + "5": 2, + "6": 2, + "7": 2 }, "col_width": 1, "widgets": [ { "type": "vertical-linear-gauge", "settings": { - "title": "<a href=\"https://pos.esss.lu.se/plot/retrieval/ui/viewer/archViewer.html?pv=TS2-010CRM:Cryo-LT-001:MeasValue&pv=TS2-010CRM:Cryo-PT-003:MeasValue\" target=\"_blank\">TS2-010CRM:Cryo-PT-003</a>", + "title": "<a href=\"https://pos.esss.lu.se/plot/retrieval/ui/viewer/archViewer.html?pv=TS2-010CRM:Cryo-PT-003:MeasValue\" target=\"_blank\">Pressure</a>", "value": "datasources[\"TS2\"][\"TS2-010CRM:Cryo-PT-003:MeasValue\"][\"value\"]", "units": "mbar", "min_value": 0, @@ -103,44 +90,48 @@ { "type": "vertical-linear-gauge", "settings": { - "title": "<a href=\"https://pos.esss.lu.se/plot/retrieval/ui/viewer/archViewer.html?pv=TS2-010CRM:Cryo-LT-001:MeasValue&pv=TS2-010CRM:Cryo-PT-004:MeasValue\" target=\"_blank\">TS2-010CRM:Cryo-PT-004</a>", - "value": "datasources[\"TS2\"][\"TS2-010CRM:Cryo-PT-004:MeasValue\"][\"value\"]", - "units": "mbar", + "title": "Temperature", + "value": "datasources[\"TS2\"][\"TS2-010CRM:Cryo-PT-003:MeasValue\"][\"temp\"]", + "units": "K", "min_value": 0, - "max_value": 67 + "max_value": 5 } } ] }, { - "title": "Temperatures", + "title": "TS2-010CRM:Cryo-PT-004", "width": 1, "row": { "2": 21, "3": 7, - "4": 7 + "4": 7, + "6": 7, + "7": 7 }, "col": { "2": 1, "3": 3, - "4": 3 + "4": 4, + "6": 3, + "7": 3 }, "col_width": 1, "widgets": [ { "type": "vertical-linear-gauge", "settings": { - "title": "TS2-010CRM-Cryo-PT-003 Temperature", - "value": "datasources[\"TS2\"][\"TS2-010CRM:Cryo-PT-003:MeasValue\"][\"temp\"]", - "units": "K", + "title": "<a href=\"https://pos.esss.lu.se/plot/retrieval/ui/viewer/archViewer.html?pv=TS2-010CRM:Cryo-PT-004:MeasValue\" target=\"_blank\">Pressure</a>", + "value": "datasources[\"TS2\"][\"TS2-010CRM:Cryo-PT-004:MeasValue\"][\"value\"]", + "units": "mbar", "min_value": 0, - "max_value": 5 + "max_value": 67 } }, { "type": "vertical-linear-gauge", "settings": { - "title": "TS2-010CRM-Cryo-PT-004 Temperature", + "title": "Temperature", "value": "datasources[\"TS2\"][\"TS2-010CRM:Cryo-PT-004:MeasValue\"][\"temp\"]", "units": "K", "min_value": 0, @@ -148,6 +139,26 @@ } } ] + }, + { + "title": "Time Selector", + "width": 1, + "row": { + "4": 7 + }, + "col": { + "4": 1 + }, + "col_width": 2, + "widgets": [ + { + "type": "html", + "settings": { + "html": "<script>\n function setDatasource(event) {\n\t\tfreeboard.showLoadingIndicator(true);\n\t};\n</script>\n<div style=\"position:relative;height:100%;display:flex;flex-direction:column;justify-content:center;align-items:center;\">\n <select onchange=\"setDatasource()\" id=\"time-series\">\n <option value=\"2w\">Two Weeks</option>\n <option value=\"1w\">One Week</option>\n <option value=\"2d\">Two Days</option>\n <option value=\"1d\">One Day</option>\n <option value=\"live\">Live</option>\n </select>\n</div>", + "height": 1 + } + } + ] } ], "datasources": [