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
27 changes: 11 additions & 16 deletions app/coordinates.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
"""app.coordinates.py"""

class Coordinates:
def __init__(self, lat_long):
self.lat_long = lat_long

class Coordinates:
"""
A position on earth using decimal coordinates (latitude and longitude).
"""
if __name__ == "__main__":
us_lat, us_long = 45, 60
us = Point(us_lat, us_long)
us_coord = Coorinates(us)

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}
class Point:

def __str__(self):
return "lat: %s, long: %s" % (self.latitude, self.longitude)
def __init__(self, x, y):
self.x = x
self.y = y
1 change: 1 addition & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,4 @@ async def handle_validation_error(
uvicorn.run(
"app.main:APP", host="127.0.0.1", port=SETTINGS.port, log_level="info",
)
# this is a test comment
49 changes: 22 additions & 27 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,35 @@ class LatestResponse(BaseModel):
latest: Latest


class Timeline(BaseModel):
"""
Timeline model.
"""
class Timeline(basemodel):

timeline: Dict[str, int] = {}
def __init__(self, timeline):

@validator("timeline")
@classmethod
def sort_timeline(cls, value):
"""Sort the timeline history before inserting into the model"""
return dict(sorted(value.items()))
self.timeline = timeline

@property
def latest(self):
"""Get latest available history value."""
return list(self.timeline.values())[-1] if self.timeline else 0


def serialize(self):
"""
Serialize the model into dict
TODO: override dict() instead of using serialize
"""
return {**self.dict(), "latest": self.latest}
class Timelines(basemodel):

def __init__(self, confirmed, deaths, recovered):

class Timelines(BaseModel):
"""
Timelines model.
"""
self.confirmed = confirmed

self.deaths = deaths

self.recovered = recovered



if __name__ == "__main__":

confirm = Timeline({'Sat':10, 'Wed':20})

death = Timeline({'Sat':10, 'Wed':20})

recovered = Timeline({'Sat':10, 'Wed':20})

confirmed: Timeline
deaths: Timeline
recovered: Timeline
timelines_1 = Timelines(confirm, death, recovered)


class Location(BaseModel):
Expand Down
File renamed without changes.