From d3e7b12b8a906b7aa0be8f113c66208c6d13d634 Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Wed, 30 Aug 2017 16:03:42 +0200 Subject: [PATCH] DASH: fix history pruning and serving --- python_suite/dashboard/dashboard.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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: -- 2.43.0