diff options
Diffstat (limited to 'src/argaze/DataAnalysis/TimeStampedDataBuffer.py')
-rw-r--r-- | src/argaze/DataAnalysis/TimeStampedDataBuffer.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/argaze/DataAnalysis/TimeStampedDataBuffer.py b/src/argaze/DataAnalysis/TimeStampedDataBuffer.py new file mode 100644 index 0000000..23bcf06 --- /dev/null +++ b/src/argaze/DataAnalysis/TimeStampedDataBuffer.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import collections + +class TimeStampedDataBuffer(collections.OrderedDict): + """Ordered dictionary to handle timestamped data. + ``` + { + timestamp1: data1, + timestamp2: data2, + ... + } + ``` + """ + + def __new__(cls): + return super(TimeStampedDataBuffer, cls).__new__(cls) + + def __init__(self): + pass + + def __del__(self): + pass + + def __setitem__(self, key: float, value): + """Force key to be a float""" + if type(key) != float: + raise KeyError('key must be a float') + + super().__setitem__(key, value) + + def pop_first(self): + """Easing FIFO access mode""" + return self.popitem(last=False)
\ No newline at end of file |