File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ class Outbreak :
3+ #Aggregate root
4+ def change_latest (self , time ):
5+ try :
6+ if Timeline .latest != time :
7+ return Latest ()
8+ else :
9+ raise ValueError
10+ except ValueError :
11+ print ("latest data is not changed" )
12+
13+
14+ ##########################################################################################
15+
16+ class Timeline (BaseModel ):
17+ """
18+ Timeline model.
19+ """
20+
21+ timeline : Dict [str , int ] = {}
22+
23+ @validator ("timeline" )
24+ @classmethod
25+ def sort_timeline (cls , value ):
26+ """Sort the timeline history before inserting into the model"""
27+ return dict (sorted (value .items ()))
28+
29+ @property
30+ def latest (self ):
31+ """Get latest available history value."""
32+ return list (self .timeline .values ())[- 1 ] if self .timeline else 0
33+
34+ def serialize (self ):
35+ """
36+ Serialize the model into dict
37+ TODO: override dict() instead of using serialize
38+ """
39+ return {** self .dict (), "latest" : self .latest }
40+
41+
42+ class Latest (BaseModel ):
43+ """
44+ Latest model.
45+ """
46+
47+ confirmed : int
48+ deaths : int
49+ recovered : int
50+
51+
52+ class LatestResponse (BaseModel ):
53+ """
54+ Response for latest.
55+ """
56+
57+ latest : Latest
You can’t perform that action at this time.
0 commit comments