aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/argaze/DataStructures.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/argaze/DataStructures.py b/src/argaze/DataStructures.py
index 4dab036..5fe7ce6 100644
--- a/src/argaze/DataStructures.py
+++ b/src/argaze/DataStructures.py
@@ -2,6 +2,7 @@
import collections
import json
+import bisect
class DictObject():
"""Convert dictionnary into object"""
@@ -63,10 +64,44 @@ class TimeStampedBuffer(collections.OrderedDict):
"""Easing FIFO access mode"""
return self.popitem(last=False)
+ def pop_first_until(self, ts):
+ """Pop all item until a given timestamped value and returning the last poped item"""
+
+ popep_ts, poped_value = self.pop_first()
+
+ while popep_ts != ts:
+ popep_ts, poped_value = self.pop_first()
+
+ return popep_ts, poped_value
+
def pop_last(self):
"""Easing FIFO access mode"""
return self.popitem(last=True)
+ def pop_last_until(self, ts):
+ """Pop all item until a given timestamped value and returning the last poped item"""
+
+ popep_ts, poped_value = self.pop_last()
+
+ while popep_ts != ts:
+ popep_ts, poped_value = self.pop_last()
+
+ return popep_ts, poped_value
+
+ def get_last_before(self, ts):
+ """Retreive last item timestamp before a given timestamp value."""
+
+ ts_list = list(self.keys())
+ last_before_index = bisect.bisect_left(ts_list, ts) - 1
+
+ if last_before_index > 0:
+
+ return ts_list[last_before_index]
+
+ else:
+
+ return None
+
def export_as_json(self, filepath):
"""Write buffer content into a json file"""
try: