diff options
author | Théo de la Hogue | 2022-11-09 19:49:12 +0100 |
---|---|---|
committer | Théo de la Hogue | 2022-11-09 19:49:12 +0100 |
commit | 3f1ab6a9a94696bdc71bcbc784c1e0b83dfc8611 (patch) | |
tree | 5258285f5b4047b3fe69bd2716b10e1bf2f2e6d1 | |
parent | a1a60196a45af849ae5073b9da34f1971b087db6 (diff) | |
download | argaze-3f1ab6a9a94696bdc71bcbc784c1e0b83dfc8611.zip argaze-3f1ab6a9a94696bdc71bcbc784c1e0b83dfc8611.tar.gz argaze-3f1ab6a9a94696bdc71bcbc784c1e0b83dfc8611.tar.bz2 argaze-3f1ab6a9a94696bdc71bcbc784c1e0b83dfc8611.tar.xz |
Making get_last_before to return timestamp and data.
-rw-r--r-- | src/argaze/DataStructures.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/argaze/DataStructures.py b/src/argaze/DataStructures.py index 2a8aed1..08bcac9 100644 --- a/src/argaze/DataStructures.py +++ b/src/argaze/DataStructures.py @@ -72,11 +72,7 @@ class TimeStampedBuffer(collections.OrderedDict): """Pop all item until a given timestamped value and return the last poped item.""" # get last timestamp before given timestamp - earliest_ts = self.get_last_before(ts) - - # when no timestamped have been found - if earliest_ts == None: - raise KeyError + earliest_ts, earliest_value = self.get_last_before(ts) popep_ts, poped_value = self.pop_first() @@ -95,7 +91,7 @@ class TimeStampedBuffer(collections.OrderedDict): return self.popitem(last=True) - def get_last_before(self, ts) -> Tuple[TimeStampType, DataType] | None: + def get_last_before(self, ts) -> Tuple[TimeStampType, DataType]: """Retreive last item timestamp before a given timestamp value.""" ts_list = list(self.keys()) @@ -103,11 +99,13 @@ class TimeStampedBuffer(collections.OrderedDict): if last_before_index >= 0: - return ts_list[last_before_index] + last_before_ts = ts_list[last_before_index] + + return last_before_ts, self[last_before_ts] else: - return None + raise KeyError(f'No data stored before {ts} timestamp.') def export_as_json(self, filepath): """Write buffer content into a json file.""" |