From: Philipp Klaus Date: Wed, 30 Aug 2017 14:03:42 +0000 (+0200) Subject: DASH: fix history pruning and serving X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=d3e7b12b8a906b7aa0be8f113c66208c6d13d634;p=mvd_epics.git DASH: fix history pruning and serving --- diff --git a/python_suite/dashboard/dashboard.py b/python_suite/dashboard/dashboard.py index 5718a18..034d6d6 100755 --- a/python_suite/dashboard/dashboard.py +++ b/python_suite/dashboard/dashboard.py @@ -21,12 +21,9 @@ def history_garbage_collection(): return GC_LAST_RUN = time.time() for pv_name in HISTORY: - # delete entries older than HISTORY_LENGTH (but leave at least one entry in the list) - while (len(HISTORY[pv_name]) > 1) and (HISTORY[pv_name][0][0] < (time.time()-HISTORY_LENGTH)): + # delete entries older than HISTORY_LENGTH (but leave at least one entry older than that in the list) + while (len(HISTORY[pv_name]) >= 2) and (HISTORY[pv_name][1][0] < (time.time()-HISTORY_LENGTH)): del HISTORY[pv_name][0] - # if only one (outdated) entry left, update its time to now - HISTORY_LENGTH - if (len(HISTORY[pv_name]) == 1) and (HISTORY[pv_name][0][0] < (time.time()-HISTORY_LENGTH)): - HISTORY[pv_name][0][0] = time.time()-HISTORY_LENGTH def register_pv_value_in_history(pv_name, ts, value): global HISTORY @@ -174,6 +171,9 @@ def api_history(name): except KeyError: abort(404, "PV not found") if len(history) != 0: + # if the first entry is older than HISTORY_LENGTH, we 'fake' its timestamp to be HISTORY_LENGTH + if history[0][0] < (time.time()-HISTORY_LENGTH): + history[0][0] = time.time()-HISTORY_LENGTH # repeat latest value in history (to make plot lines end 'now') history.append([time.time(), history[-1][1]]) for row in history: