diff --git a/app/latest.py b/app/latest.py new file mode 100644 index 00000000..66532e54 --- /dev/null +++ b/app/latest.py @@ -0,0 +1,24 @@ +"""app.latest.py""" + + +class Latest: + """ + A position on earth using decimal coordinates (latitude and longitude). + """ + + def __init__(self, confirmed, deaths, recovered): + self.confirmed = confirmed + self.deaths = deaths + self.recovered = recovered + + def serialize(self): + """ + Serializes the latest data into a dict. + + :returns: The serialized latest confirmed deaths and recovered cases + :rtype: dict + """ + return {"confirmed": self.confirmed, "deaths": self.deaths, "recovered": self.recovered} + + def __str__(self): + return "confirmed: %s, deaths: %s, recovered: %s" % (self.confirmed, self.deaths, self.recovered) diff --git a/app/location/__init__.py b/app/location/__init__.py index 1da5e9e5..9adfdc00 100644 --- a/app/location/__init__.py +++ b/app/location/__init__.py @@ -11,7 +11,7 @@ class Location: # pylint: disable=too-many-instance-attributes """ def __init__( - self, id, country, province, coordinates, last_updated, confirmed, deaths, recovered, + self, id, country, province, coordinates, last_updated, latest ): # pylint: disable=too-many-arguments # General info. self.id = id @@ -23,9 +23,7 @@ def __init__( self.last_updated = last_updated # Statistics. - self.confirmed = confirmed - self.deaths = deaths - self.recovered = recovered + self.latest @property def country_code(self): @@ -66,11 +64,7 @@ def serialize(self): # Last updated. "last_updated": self.last_updated, # Latest data (statistics). - "latest": { - "confirmed": self.confirmed, - "deaths": self.deaths, - "recovered": self.recovered, - }, + "latest": self.latest.serialize(),, } diff --git a/app/services/location/jhu.py b/app/services/location/jhu.py index ebed3960..64fe69d9 100644 --- a/app/services/location/jhu.py +++ b/app/services/location/jhu.py @@ -182,26 +182,26 @@ async def get_locations(): # Last update. datetime.utcnow().isoformat() + "Z", # Timelines (parse dates as ISO). - { - "confirmed": Timeline( + Latest( + confirmed = Timeline( timeline={ datetime.strptime(date, "%m/%d/%y").isoformat() + "Z": amount for date, amount in timelines["confirmed"].items() } ), - "deaths": Timeline( + deaths = Timeline( timeline={ datetime.strptime(date, "%m/%d/%y").isoformat() + "Z": amount for date, amount in timelines["deaths"].items() } ), - "recovered": Timeline( + recovered = Timeline( timeline={ datetime.strptime(date, "%m/%d/%y").isoformat() + "Z": amount for date, amount in timelines["recovered"].items() } ), - }, + ) ) ) LOGGER.info(f"{data_id} Data normalized")