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
17 changes: 4 additions & 13 deletions app/coordinates.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
"""app.coordinates.py"""
from pydantic import BaseModel


class Coordinates:
class Coordinates(BaseModel):
"""
A position on earth using decimal coordinates (latitude and longitude).
"""

def __init__(self, latitude, 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}
latitude: float = None
longitude: float = None

def __str__(self):
return "lat: %s, long: %s" % (self.latitude, self.longitude)
2 changes: 1 addition & 1 deletion app/location/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def serialize(self):
"country_population": self.country_population,
"province": self.province,
# Coordinates.
"coordinates": self.coordinates.serialize(),
"coordinates": self.coordinates.dict(),
# Last updated.
"last_updated": self.last_updated,
# Latest data (statistics).
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
5 changes: 4 additions & 1 deletion app/services/location/jhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ async def get_locations():

# Grab coordinates.
coordinates = location["coordinates"]
# print(coordinates)

# Create location (supporting timelines) and append.
locations.append(
Expand All @@ -178,7 +179,9 @@ async def get_locations():
location["country"],
location["province"],
# Coordinates.
Coordinates(latitude=coordinates["lat"], longitude=coordinates["long"]),
Coordinates(
latitude=coordinates["lat"] or None, longitude=coordinates["long"] or None
),
# Last update.
datetime.utcnow().isoformat() + "Z",
# Timelines (parse dates as ISO).
Expand Down
2 changes: 1 addition & 1 deletion app/services/location/nyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def get_locations():
id=idx,
state=county_state[1],
county=county_state[0],
coordinates=Coordinates(None, None), # NYT does not provide coordinates
coordinates=Coordinates(), # NYT does not provide coordinates
last_updated=datetime.utcnow().isoformat() + "Z", # since last request
timelines={
"confirmed": Timeline(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def test_coordinates_class(latitude, longitude):
coord_obj = coordinates.Coordinates(latitude=latitude, longitude=longitude)

# validate serialize
check_obj = {"latitude": latitude, "longitude": longitude}
check_obj = {"latitude": float(latitude), "longitude": float(longitude)}

assert coord_obj.serialize() == check_obj
assert coord_obj.dict() == check_obj