Skip to content
Open
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
46 changes: 41 additions & 5 deletions app/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,43 @@ class Coordinates:
A position on earth using decimal coordinates (latitude and longitude).
"""

def __init__(self, latitude, longitude):
self.latitude = latitude
self.longitude = longitude
def __init__(self):
self.lat_long = {}

class CBuilder():

def build_latitude(self): pass
def build_longitude(self): pass
def get_result(self): pass

class Builder(CBuilder):

def __init__(self):
self.coordinates = Coordinates()

def build_latitude(self, latitude):
self.coordinates.lat_long["latitude"] = latitude
return self

def build_longitude(self, longitude):
self.coordinates.lat_long["longitude"] = longitude
return self

def get_result(self):
return self.coordinates.lat_long

class CDirector:
lat: int
long: int

def construct(latitude, longitude):
CDirector.lat = latitude
CDirector.long = longitude

return Builder()\
.build_latitude(latitude)\
.build_longitude(longitude)\
.get_result()

def serialize(self):
"""
Expand All @@ -17,7 +51,9 @@ def serialize(self):
:returns: The serialized coordinates.
:rtype: dict
"""
return {"latitude": self.latitude, "longitude": self.longitude}
return self

def __str__(self):
return "lat: %s, long: %s" % (self.latitude, self.longitude)
return "lat: %s, long: %s" % (CDirector.lat, CDirector.long)


4 changes: 2 additions & 2 deletions app/services/location/csbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cachetools import TTLCache

from ...caches import check_cache, load_cache
from ...coordinates import Coordinates
from ...coordinates import CDirector
from ...location.csbs import CSBSLocation
from ...utils import httputils
from . import LocationService
Expand Down Expand Up @@ -82,7 +82,7 @@ async def get_locations():
state,
county,
# Coordinates.
Coordinates(item["Latitude"], item["Longitude"]),
CDirector.construct(item["Latitude"], 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 @@ -9,7 +9,7 @@
from cachetools import TTLCache

from ...caches import check_cache, load_cache
from ...coordinates import Coordinates
from ...coordinates import CDirector
from ...location import TimelinedLocation
from ...models import Timeline
from ...utils import countries
Expand Down Expand Up @@ -178,7 +178,7 @@ async def get_locations():
location["country"],
location["province"],
# Coordinates.
Coordinates(latitude=coordinates["lat"], longitude=coordinates["long"]),
CDirector.construct(coordinates["lat"], coordinates["long"]),
# Last update.
datetime.utcnow().isoformat() + "Z",
# Timelines (parse dates as ISO).
Expand Down
4 changes: 2 additions & 2 deletions app/services/location/nyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cachetools import TTLCache

from ...caches import check_cache, load_cache
from ...coordinates import Coordinates
from ...coordinates import CDirector
from ...location.nyt import NYTLocation
from ...models import Timeline
from ...utils import httputils
Expand Down 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=CDirector.construct(None, None), # NYT does not provide coordinates
last_updated=datetime.utcnow().isoformat() + "Z", # since last request
timelines={
"confirmed": Timeline(
Expand Down