aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThéo de la Hogue2022-04-06 16:53:04 +0200
committerThéo de la Hogue2022-04-06 16:53:04 +0200
commitf50b0961f2feec0b7a220a451f9e05e080536147 (patch)
tree642601f618728e5524a740bc8d853a55eec7f499 /src
parent1e0fe8878e649ee6a172c0b1fb2c397cfb438b9a (diff)
downloadargaze-f50b0961f2feec0b7a220a451f9e05e080536147.zip
argaze-f50b0961f2feec0b7a220a451f9e05e080536147.tar.gz
argaze-f50b0961f2feec0b7a220a451f9e05e080536147.tar.bz2
argaze-f50b0961f2feec0b7a220a451f9e05e080536147.tar.xz
Adding functions to TimeStampedBuffer class
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: