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



class Person:

def __init__(self, p, w):
self.p = p
self.w = w

personOne = Person("Abdullah", 190)

print(personOne.p)
print(personOne.w)

3
y
n
y
y
57 changes: 7 additions & 50 deletions app/location/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,36 @@
from ..coordinates import Coordinates
from ..utils import countries
from ..utils.populations import country_population
from creationalBP import DataLocation


# pylint: disable=redefined-builtin,invalid-name
class Location: # pylint: disable=too-many-instance-attributes
class Location(creationalBP): # pylint: disable=too-many-instance-attributes
"""
A location in the world affected by the coronavirus.
"""

def __init__(
self, id, country, province, coordinates, last_updated, confirmed, deaths, recovered,
): # pylint: disable=too-many-arguments
# General info.
self.id = id
self.country = country.strip()
self.province = province.strip()
self.coordinates = coordinates

# Last update.
self.last_updated = last_updated

# Statistics.
self.confirmed = confirmed
self.deaths = deaths
self.recovered = recovered

@property
def country_code(self):
def country_code(DataLocation):
"""
Gets the alpha-2 code represention of the country. Returns 'XX' if none is found.

:returns: The country code.
:rtype: str
"""
return (countries.country_code(self.country) or countries.DEFAULT_COUNTRY_CODE).upper()
return (countries.country_code(super().__init__.country) or countries.DEFAULT_COUNTRY_CODE).upper()

@property
def country_population(self):
def country_population(DataLocation):
"""
Gets the population of this location.

:returns: The population.
:rtype: int
"""
return country_population(self.country_code)

def serialize(self):
"""
Serializes the location into a dict.

:returns: The serialized location.
:rtype: dict
"""
return {
# General info.
"id": self.id,
"country": self.country,
"country_code": self.country_code,
"country_population": self.country_population,
"province": self.province,
# Coordinates.
"coordinates": self.coordinates.serialize(),
# Last updated.
"last_updated": self.last_updated,
# Latest data (statistics).
"latest": {
"confirmed": self.confirmed,
"deaths": self.deaths,
"recovered": self.recovered,
},
}

return country_population(super().__init__.country_code)

class TimelinedLocation(Location):
class TimelinedLocation(DataLocation):
"""
A location with timelines.
"""
Expand Down
47 changes: 47 additions & 0 deletions app/location/creationalBP.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from ..coordinates import Coordinates
from ..utils import countries
from ..utils.populations import country_population
from ..__init__.py import country_code, country_population

class DataLocation:

def __init__ (self, id, country, province, coordinates, last_updated, confirmed, deaths, recovered,
):

self.id = id
self.country = country.strip()
self.province = province.strip()
self.coordinates = coordinates


self.last_updated = last_updated


self.confirmed = confirmed
self.deaths = deaths
self.recovered = recovered

def serialize(self):
"""
Serializes the location into a dict.
:returns: The serialized location.
:rtype: dict
"""
return {

"id": self.id,
"country": self.country,
"country_code": self.country_code,
"country_population": self.country_population,
"province": self.province,

"coordinates": self.coordinates.serialize(),

"last_updated": self.last_updated,
"latest": {
"confirmed": self.confirmed,
"deaths": self.deaths,
"recovered": self.recovered,
},
}
}
9 changes: 4 additions & 5 deletions app/location/csbs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""app.locations.csbs.py"""
from . import Location
from . import DataLocation


class CSBSLocation(Location):
class CSBSLocation(DataLocation):
"""
A CSBS (county) location.
A CSBS (county) DataLocation.
"""

# pylint: disable=too-many-arguments,redefined-builtin
Expand All @@ -28,7 +28,6 @@ def __init__(self, id, state, county, coordinates, last_updated, confirmed, deat
def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
"""
Serializes the location into a dict.

:returns: The serialized location.
:rtype: dict
"""
Expand All @@ -40,4 +39,4 @@ def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused
)

# Return the serialized location.
return serialized
return serialized
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.