forked from ExpDev07/coronavirus-tracker-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeline.py
More file actions
36 lines (30 loc) · 801 Bytes
/
timeline.py
File metadata and controls
36 lines (30 loc) · 801 Bytes
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
from datetime import datetime
from collections import OrderedDict
class Timeline:
"""
Timeline with history of data.
"""
def __init__(self, history = {}):
self.__timeline = history
@property
def timeline(self):
"""
Gets the history sorted by date (key).
"""
return OrderedDict(sorted(self.__timeline.items()))
@property
def latest(self):
"""
Gets the latest available history value.
"""
return list(self.timeline.values())[-1] or 0
def serialize(self):
"""
Serializes the timeline into a dict.
:returns: The serialized timeline.
:rtype: dict
"""
return {
'latest' : self.latest,
'timeline': self.timeline
}