diff --git a/app/coordinates.py b/app/coordinates.py index be972c6e..62008184 100644 --- a/app/coordinates.py +++ b/app/coordinates.py @@ -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 diff --git a/app/location/__init__.py b/app/location/__init__.py index 1da5e9e5..34cdc2c2 100644 --- a/app/location/__init__.py +++ b/app/location/__init__.py @@ -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. """ diff --git a/app/location/creationalBP.py b/app/location/creationalBP.py new file mode 100644 index 00000000..556c5b82 --- /dev/null +++ b/app/location/creationalBP.py @@ -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, + }, + } +} diff --git a/app/location/csbs.py b/app/location/csbs.py index 649e8b22..74196f3a 100644 --- a/app/location/csbs.py +++ b/app/location/csbs.py @@ -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 @@ -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 """ @@ -40,4 +39,4 @@ def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused ) # Return the serialized location. - return serialized + return serialized \ No newline at end of file diff --git a/app/main.py b/app/main.py index b9aff949..7ccb68e3 100644 --- a/app/main.py +++ b/app/main.py @@ -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 \ No newline at end of file diff --git a/app/models.py b/app/models.py index 497a4b83..843d71b2 100644 --- a/app/models.py +++ b/app/models.py @@ -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): diff --git a/Makefile b/makefile similarity index 100% rename from Makefile rename to makefile