diff --git a/app/coordinates.py b/app/coordinates.py index be972c6e..33d69168 100644 --- a/app/coordinates.py +++ b/app/coordinates.py @@ -1,23 +1,53 @@ """app.coordinates.py""" +class CoordinateFactory: + def create_coordinate(creation_type:int, data:float): + if creation_type == 1: new_coordinate = Latitude(data) + if creation_type == 2: new_coordinate = Longitude(data) + return new_coordinate +class Coordinate: + pass +class Latitude(Coordinate): + """ + A numeric representation of a latitudinal position north or south of the Earth's equator, to track Coronavirus spread nation to nation latitudinally. + """ + def __init__(self, value: float): + self.data = value + + def sum(other: Latitude): + self.data += other.data + + def merge(other: Longitude): + return Coordinates(self, other) +class Longitude(Coordinate): + """ + A numeric representation of a longitudinal position measuring east to west, to track Coronavirus spread nation to nation longitudinally + """ + def __init__(self, value: float): + self.data = value + + def sum(other: Longitude): + self.data += other.data + + def merge(other: Latitude): + return Coordinates(self, other) class Coordinates: """ A position on earth using decimal coordinates (latitude and longitude). """ - def __init__(self, latitude, longitude): + def __init__(self, latitude: Latitude, longitude:Longitude): self.latitude = latitude self.longitude = longitude def serialize(self): """ Serializes the coordinates into a dict. - :returns: The serialized coordinates. :rtype: dict """ - return {"latitude": self.latitude, "longitude": self.longitude} + return {"latitude": self.latitude.data, "longitude": self.longitude.data} def __str__(self): - return "lat: %s, long: %s" % (self.latitude, self.longitude) + return "lat: %s, long: %s" % (self.latitude.data, self.longitude.data) diff --git a/app/models.py b/app/models.py index 497a4b83..edc858ea 100644 --- a/app/models.py +++ b/app/models.py @@ -3,15 +3,17 @@ from pydantic import BaseModel, validator - +class Stats: + confirmed: int + deaths: int + recovered: int + class Latest(BaseModel): """ Latest model. """ - confirmed: int - deaths: int - recovered: int + stats: Stats class LatestResponse(BaseModel): diff --git a/app/services/location/csbs.py b/app/services/location/csbs.py index 444ebad6..23748e08 100644 --- a/app/services/location/csbs.py +++ b/app/services/location/csbs.py @@ -82,7 +82,7 @@ async def get_locations(): state, county, # Coordinates. - Coordinates(item["Latitude"], item["Longitude"]), + Coordinates(Latitude(item["Latitude"]), Longitude(item["Longitude"])), # Last update (parse as ISO). datetime.strptime(last_update, "%Y-%m-%d %H:%M").isoformat() + "Z", # Statistics. diff --git a/app/services/location/jhu.py b/app/services/location/jhu.py index ebed3960..06e82e13 100644 --- a/app/services/location/jhu.py +++ b/app/services/location/jhu.py @@ -101,7 +101,7 @@ async def get_category(category): "country_code": countries.country_code(country), "province": item["Province/State"], # Coordinates. - "coordinates": {"lat": item["Lat"], "long": item["Long"],}, + "coordinates": {"lat": Latitude(item["Lat"]), "long": Longitude(item["Long"]),}, # History. "history": history, # Latest statistic. @@ -178,7 +178,7 @@ async def get_locations(): location["country"], location["province"], # Coordinates. - Coordinates(latitude=coordinates["lat"], longitude=coordinates["long"]), + Coordinates(latitude=Latitude(coordinates["lat"]), longitude=Longitude(coordinates["long"]), # Last update. datetime.utcnow().isoformat() + "Z", # Timelines (parse dates as ISO).