]> jspc29.x-matter.uni-frankfurt.de Git - mvd_epics.git/commitdiff
DASH: fix history pruning and serving
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Wed, 30 Aug 2017 14:03:42 +0000 (16:03 +0200)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Wed, 30 Aug 2017 14:03:42 +0000 (16:03 +0200)
python_suite/dashboard/dashboard.py

index 5718a182901912507ed4d016381391aac0d5e318..034d6d630effc531da333fd1ca41e7f825ccfbeb 100755 (executable)
@@ -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: