diff --git a/app/location/__init__.py b/app/location/__init__.py index 1da5e9e5..d4440be8 100644 --- a/app/location/__init__.py +++ b/app/location/__init__.py @@ -3,30 +3,14 @@ from ..utils import countries from ..utils.populations import country_population +class Country: + def __init__(self, id, country, province, coordinates): -# pylint: disable=redefined-builtin,invalid-name -class Location: # pylint: disable=too-many-instance-attributes - """ - A location in the world affected by the coronavirus. - """ - - 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 - - # Last update. - self.last_updated = last_updated - - # Statistics. - self.confirmed = confirmed - self.deaths = deaths - self.recovered = recovered - + @property def country_code(self): """ @@ -47,6 +31,23 @@ def country_population(self): """ return country_population(self.country_code) + +# pylint: disable=redefined-builtin,invalid-name +class Location: # pylint: disable=too-many-instance-attributes + """ + A location in the world affected by the coronavirus. + """ + + def __init__(self, last_updated, confirmed, deaths, recovered): # pylint: disable=too-many-arguments + + # Last update. + self.last_updated = last_updated + + # Statistics. + self.confirmed = confirmed + self.deaths = deaths + self.recovered = recovered + def serialize(self): """ Serializes the location into a dict. @@ -54,6 +55,7 @@ def serialize(self): :returns: The serialized location. :rtype: dict """ + return { # General info. "id": self.id, @@ -74,14 +76,14 @@ def serialize(self): } -class TimelinedLocation(Location): +class TimelinedLocation: """ A location with timelines. """ # pylint: disable=too-many-arguments - def __init__(self, id, country, province, coordinates, last_updated, timelines): - super().__init__( + def __init__(self, id, country, province, coordinates, last_updated, timelines, location): + Location.__init__( # General info. id, country, @@ -96,6 +98,7 @@ def __init__(self, id, country, province, coordinates, last_updated, timelines): # Set timelines. self.timelines = timelines + self.location = Location # pylint: disable=arguments-differ def serialize(self, timelines=False): diff --git a/app/location/csbs.py b/app/location/csbs.py index 649e8b22..01770c61 100644 --- a/app/location/csbs.py +++ b/app/location/csbs.py @@ -2,14 +2,14 @@ from . import Location -class CSBSLocation(Location): +class CSBSLocation: """ A CSBS (county) location. """ # pylint: disable=too-many-arguments,redefined-builtin - def __init__(self, id, state, county, coordinates, last_updated, confirmed, deaths): - super().__init__( + def __init__(self, id, state, county, coordinates, last_updated, confirmed, deaths, location): + Location.__init__( # General info. id, "US", @@ -24,6 +24,8 @@ def __init__(self, id, state, county, coordinates, last_updated, confirmed, deat self.state = state self.county = county + self.location = Location + def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument """ diff --git a/app/location/nyt.py b/app/location/nyt.py index ad92212e..f8d2156f 100644 --- a/app/location/nyt.py +++ b/app/location/nyt.py @@ -2,17 +2,18 @@ from . import TimelinedLocation -class NYTLocation(TimelinedLocation): +class NYTLocation: """ A NYT (county) Timelinedlocation. """ # pylint: disable=too-many-arguments,redefined-builtin - def __init__(self, id, state, county, coordinates, last_updated, timelines): - super().__init__(id, "US", state, coordinates, last_updated, timelines) + def __init__(self, id, state, county, coordinates, last_updated, timelines, timelinedLocation): + TimelinedLocation.__init__(id, "US", state, coordinates, last_updated, timelines) self.state = state self.county = county + self.timelinedLocation = TimelinedLocation def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument """