diff --git a/app/location/__init__.py b/app/location/__init__.py index 1da5e9e5..c7205f34 100644 --- a/app/location/__init__.py +++ b/app/location/__init__.py @@ -14,18 +14,48 @@ def __init__( self, id, country, province, coordinates, last_updated, confirmed, deaths, recovered, ): # pylint: disable=too-many-arguments # General info. - self.id = id - self.country = country.strip() - self.province = province.strip() - self.coordinates = coordinates + self._id = id + self._country = country.strip() + self._province = province.strip() + self._coordinates = coordinates # Last update. - self.last_updated = last_updated + self._last_updated = last_updated # Statistics. - self.confirmed = confirmed - self.deaths = deaths - self.recovered = recovered + self._confirmed = confirmed + self._deaths = deaths + self._recovered = recovered + + @property + def confirmed(self): + """ + Gets the latest amount of total confirmed cases of this location. + + :returns: The latest amount of total confirmed cases. + :rtype: int + """ + return self._confirmed + + @property + def deaths(self): + """ + Gets the latest amount of total death cases of this location. + + :returns: The latest amount of total death cases. + :rtype: int + """ + return self._deaths + + @property + def recovered(self): + """ + Gets the latest amount of total recovered cases of this location. + + :returns: The latest amount of total recovered cases. + :rtype: int + """ + return self._recovered @property def country_code(self): @@ -35,7 +65,7 @@ def country_code(self): :returns: The country code. :rtype: str """ - return (countries.country_code(self.country) or countries.DEFAULT_COUNTRY_CODE).upper() + return (countries.country_code(self._country) or countries.DEFAULT_COUNTRY_CODE).upper() @property def country_population(self): @@ -56,20 +86,20 @@ def serialize(self): """ return { # General info. - "id": self.id, - "country": self.country, + "id": self._id, + "country": self._country, "country_code": self.country_code, "country_population": self.country_population, - "province": self.province, + "province": self._province, # Coordinates. - "coordinates": self.coordinates.serialize(), + "coordinates": self._coordinates.serialize(), # Last updated. - "last_updated": self.last_updated, + "last_updated": self._last_updated, # Latest data (statistics). "latest": { - "confirmed": self.confirmed, - "deaths": self.deaths, - "recovered": self.recovered, + "confirmed": self._confirmed, + "deaths": self._deaths, + "recovered": self._recovered, }, } @@ -95,7 +125,7 @@ def __init__(self, id, country, province, coordinates, last_updated, timelines): ) # Set timelines. - self.timelines = timelines + self._timelines = timelines # pylint: disable=arguments-differ def serialize(self, timelines=False): @@ -115,7 +145,7 @@ def serialize(self, timelines=False): "timelines": { # Serialize all the timelines. key: value.serialize() - for (key, value) in self.timelines.items() + for (key, value) in self._timelines.items() } } ) diff --git a/app/location/csbs.py b/app/location/csbs.py index 649e8b22..e8881391 100644 --- a/app/location/csbs.py +++ b/app/location/csbs.py @@ -22,8 +22,28 @@ def __init__(self, id, state, county, coordinates, last_updated, confirmed, deat recovered=0, ) - self.state = state - self.county = county + self._state = state + self._county = county + + @property + def state(self): + """ + Gets the name of the state. + + :returns: The name of the state. + :rtype: str + """ + return self._state + + @property + def county(self): + """ + Gets the name of the county. + + :returns: The name of the county. + :rtype: str + """ + return self._county def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument """ @@ -36,7 +56,7 @@ def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused # Update with new fields. serialized.update( - {"state": self.state, "county": self.county,} + {"state": self._state, "county": self._county,} ) # Return the serialized location. diff --git a/app/location/nyt.py b/app/location/nyt.py index ad92212e..7f0574ac 100644 --- a/app/location/nyt.py +++ b/app/location/nyt.py @@ -11,8 +11,8 @@ class NYTLocation(TimelinedLocation): def __init__(self, id, state, county, coordinates, last_updated, timelines): super().__init__(id, "US", state, coordinates, last_updated, timelines) - self.state = state - self.county = county + self._state = state + self._county = county def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument """ @@ -25,7 +25,7 @@ def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused # Update with new fields. serialized.update( - {"state": self.state, "county": self.county,} + {"state": self._state, "county": self._county,} ) # Return the serialized location.