Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions app/coordinates.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 6 additions & 4 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion app/services/location/csbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions app/services/location/jhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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).
Expand Down