66# put confirmed cases, deaths cases, recovered cases into one class
77# Inseated of using confirmed cases, deaths cases, recovered cases as attributes, we can use CaseNumbers class instance as attribute
88class CaseNumbers :
9- def __init__ (self , confirmed = 0 , deaths = 0 , recovered = 0 ):
9+ def __init__ (self , id , confirmed = 0 , deaths = 0 , recovered = 0 ):
10+ self .id = id
1011 self .confirmed = confirmed
1112 self .deaths = deaths
1213 self .recovered = recovered
1314
15+
16+ #put all location information into one class
17+ #CaseNumbers, Locationinfo, coordinates and Location forms one aggregate
1418class Locationinfo :
1519 def __init__ (self , id , country , province , coordinates ):
1620 self .id = id
@@ -29,7 +33,7 @@ class Location: # pylint: disable=too-many-instance-attributes
2933
3034 # Use instance of class CaseNumbers as attribute
3135 def __init__ (
32- self , locationinfo , last_updated , casenumbers
36+ self , id , locationinfo , last_updated , casenumbers
3337 ): # pylint: disable=too-many-arguments
3438 # General info.
3539 self .locationinfo = locationinfo
@@ -48,7 +52,7 @@ def country_code(self):
4852 :returns: The country code.
4953 :rtype: str
5054 """
51- return (countries .country_code (self .country ) or countries .DEFAULT_COUNTRY_CODE ).upper ()
55+ return (countries .country_code (self .locationinfo . country ) or countries .DEFAULT_COUNTRY_CODE ).upper ()
5256
5357 @property
5458 def country_population (self ):
@@ -69,13 +73,13 @@ def serialize(self):
6973 """
7074 return {
7175 # General info.
72- "id" : self .id ,
73- "country" : self .country ,
76+ "id" : self .locationinfo . id ,
77+ "country" : self .locationinfo . country ,
7478 "country_code" : self .country_code ,
7579 "country_population" : self .country_population ,
76- "province" : self .province ,
80+ "province" : self .locationinfo . province ,
7781 # Coordinates.
78- "coordinates" : self .coordinates .serialize (),
82+ "coordinates" : self .locationinfo . coordinates .serialize (),
7983 # Last updated.
8084 "last_updated" : self .last_updated ,
8185 # Latest data (statistics).
@@ -93,13 +97,10 @@ class TimelinedLocation(Location):
9397 """
9498
9599 # pylint: disable=too-many-arguments
96- def __init__ (self , id , country , province , coordinates , last_updated , timelines , casenumbers ):
100+ def __init__ (self , locationinfo , last_updated , timelines , casenumbers ):
97101 super ().__init__ (
98102 # General info.
99- id ,
100- country ,
101- province ,
102- coordinates ,
103+ locationinfo ,
103104 last_updated ,
104105 # Statistics (retrieve latest from timelines).
105106 casenumbers
0 commit comments