aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/DataStructures.py
blob: 9c0414c5a91833f664aaba4575ec6414742cf720 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python

import collections

class DictObject():
    """Convert dictionnary into object"""

    def __init__(self, object_type, **dictionnary):

        self.__dict__.update(dictionnary)
        self.__type = object_type

    def __getitem__(self, key):
        return self.__dict__[key]

    def type(self):
        return self.__type

    def keys(self):
        return list(self.__dict__.keys())[:-1]
        
class TimeStampedBuffer(collections.OrderedDict):
    """Ordered dictionary to handle timestamped data.
    ```
    {
        timestamp1: data1,
        timestamp2: data2,
        ...
    }
    ```
    """

    def __new__(cls):
        return super(TimeStampedBuffer, 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)