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
82 changes: 81 additions & 1 deletion app/location/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,88 @@
from ..utils.populations import country_population


class Location:
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

def add(self, location):
pass

def remove(self, location):
pass

def country_code(self):
pass

def country_population(self):
pass

def serialize(self):
pass


class Province(Location):
countries = None

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 = None
self.coordinates = coordinates

# Last update.
self.last_updated = last_updated

# Statistics.
self.confirmed = confirmed
self.deaths = deaths
self.recovered = recovered
self.countries = []

def add(self, location):
self.countries.append(location)

def remove(self, location):
self.countries.remove(location)

def country_code(self):
countries_code = []
for i in countries
countries_code.append(countries.country_code(i))
return countries_code

def country_population(self):
countries_population = 0
for i in countries
countries_population=countries_population+ country_population(i)
return countries_population

def serialize(self):
for i in countries
i.serialize()




# pylint: disable=redefined-builtin,invalid-name
class Location: # pylint: disable=too-many-instance-attributes
class Country(Location): # pylint: disable=too-many-instance-attributes
"""
A location in the world affected by the coronavirus.
"""
Expand Down
10 changes: 10 additions & 0 deletions app/services/location/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
"""app.services.location"""
from abc import ABC, abstractmethod

def singleton(cls):
instances = {}

def wrapper(*args, **kwargs):
if cls not in instances:
instances[cls] = cls(*args, **kwargs)
return instances[cls]

return wrapper

@singleton
class LocationService(ABC):
"""
Service for retrieving locations.
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 @@ -14,7 +14,7 @@

LOGGER = logging.getLogger("services.location.csbs")


@singleton
class CSBSLocationService(LocationService):
"""
Service for retrieving locations from csbs
Expand Down
1 change: 1 addition & 0 deletions app/services/location/jhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
PID = os.getpid()


@singleton
class JhuLocationService(LocationService):
"""
Service for retrieving locations from Johns Hopkins CSSE (https://github.com/CSSEGISandData/COVID-19).
Expand Down
1 change: 1 addition & 0 deletions app/services/location/nyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
LOGGER = logging.getLogger("services.location.nyt")


@singleton
class NYTLocationService(LocationService):
"""
Service for retrieving locations from New York Times (https://github.com/nytimes/covid-19-data).
Expand Down