Total Complexity | 9 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | """Data structures for timestamp information.""" |
||
2 | |||
3 | 1 | import yorm |
|
4 | |||
5 | 1 | ||
6 | @yorm.attr(started=yorm.types.Integer) |
||
7 | @yorm.attr(stopped=yorm.types.Integer) |
||
8 | 1 | class Timestamp(yorm.types.AttributeDictionary): |
|
9 | """Dictionary of last start and stop times.""" |
||
10 | |||
11 | 1 | def __init__(self, started=0, stopped=0): |
|
12 | 1 | super().__init__() |
|
13 | 1 | self.started = started |
|
14 | self.stopped = stopped |
||
15 | |||
16 | 1 | def __repr__(self): |
|
17 | 1 | return "<timestamp {}>".format(self.latest) |
|
18 | 1 | ||
19 | 1 | def __eq__(self, other): |
|
20 | return self.latest == other.latest |
||
21 | 1 | ||
22 | 1 | def __ne__(self, other): |
|
23 | return not self.__eq__(other) |
||
24 | 1 | ||
25 | 1 | def __lt__(self, other): |
|
26 | return self.latest < other.latest |
||
27 | 1 | ||
28 | 1 | @property |
|
29 | def latest(self): |
||
30 | 1 | """Get the latest timestamp.""" |
|
31 | 1 | return max((self.started, self.stopped)) |
|
32 | |||
33 | 1 | @property |
|
34 | def active(self): |
||
35 | """Determine if the timestamps indicate current activity.""" |
||
36 | 1 | if not self.started: |
|
37 | return False |
||
38 | 1 | ||
39 | if not self.stopped: |
||
40 | return True |
||
41 | 1 | ||
42 | return self.started > self.stopped |
||
43 |