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
68 changes: 49 additions & 19 deletions app/location/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,48 @@ 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
self._id = id
self._country = country.strip()
self._province = province.strip()
self._coordinates = coordinates

# Last update.
self.last_updated = last_updated
self._last_updated = last_updated

# Statistics.
self.confirmed = confirmed
self.deaths = deaths
self.recovered = recovered
self._confirmed = confirmed
self._deaths = deaths
self._recovered = recovered

@property
def confirmed(self):
"""
Gets the latest amount of total confirmed cases of this location.

:returns: The latest amount of total confirmed cases.
:rtype: int
"""
return self._confirmed

@property
def deaths(self):
"""
Gets the latest amount of total death cases of this location.

:returns: The latest amount of total death cases.
:rtype: int
"""
return self._deaths

@property
def recovered(self):
"""
Gets the latest amount of total recovered cases of this location.

:returns: The latest amount of total recovered cases.
:rtype: int
"""
return self._recovered

@property
def country_code(self):
Expand All @@ -35,7 +65,7 @@ def country_code(self):
:returns: The country code.
:rtype: str
"""
return (countries.country_code(self.country) or countries.DEFAULT_COUNTRY_CODE).upper()
return (countries.country_code(self._country) or countries.DEFAULT_COUNTRY_CODE).upper()

@property
def country_population(self):
Expand All @@ -56,20 +86,20 @@ def serialize(self):
"""
return {
# General info.
"id": self.id,
"country": self.country,
"id": self._id,
"country": self._country,
"country_code": self.country_code,
"country_population": self.country_population,
"province": self.province,
"province": self._province,
# Coordinates.
"coordinates": self.coordinates.serialize(),
"coordinates": self._coordinates.serialize(),
# Last updated.
"last_updated": self.last_updated,
"last_updated": self._last_updated,
# Latest data (statistics).
"latest": {
"confirmed": self.confirmed,
"deaths": self.deaths,
"recovered": self.recovered,
"confirmed": self._confirmed,
"deaths": self._deaths,
"recovered": self._recovered,
},
}

Expand All @@ -95,7 +125,7 @@ def __init__(self, id, country, province, coordinates, last_updated, timelines):
)

# Set timelines.
self.timelines = timelines
self._timelines = timelines

# pylint: disable=arguments-differ
def serialize(self, timelines=False):
Expand All @@ -115,7 +145,7 @@ def serialize(self, timelines=False):
"timelines": {
# Serialize all the timelines.
key: value.serialize()
for (key, value) in self.timelines.items()
for (key, value) in self._timelines.items()
}
}
)
Expand Down
26 changes: 23 additions & 3 deletions app/location/csbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,28 @@ def __init__(self, id, state, county, coordinates, last_updated, confirmed, deat
recovered=0,
)

self.state = state
self.county = county
self._state = state
self._county = county

@property
def state(self):
"""
Gets the name of the state.

:returns: The name of the state.
:rtype: str
"""
return self._state

@property
def county(self):
"""
Gets the name of the county.

:returns: The name of the county.
:rtype: str
"""
return self._county

def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
"""
Expand All @@ -36,7 +56,7 @@ def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused

# Update with new fields.
serialized.update(
{"state": self.state, "county": self.county,}
{"state": self._state, "county": self._county,}
)

# Return the serialized location.
Expand Down
6 changes: 3 additions & 3 deletions app/location/nyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class NYTLocation(TimelinedLocation):
def __init__(self, id, state, county, coordinates, last_updated, timelines):
super().__init__(id, "US", state, coordinates, last_updated, timelines)

self.state = state
self.county = county
self._state = state
self._county = county

def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
"""
Expand All @@ -25,7 +25,7 @@ def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused

# Update with new fields.
serialized.update(
{"state": self.state, "county": self.county,}
{"state": self._state, "county": self._county,}
)

# Return the serialized location.
Expand Down