Skip to content

Commit 7667a9d

Browse files
committed
Apply aggregate to the Location class, as well as its subclasses
Turning most of the variables into protected, because there is no point making them public. Appropriate getters are added.
1 parent 1c7e4ae commit 7667a9d

File tree

3 files changed

+45
-25
lines changed

3 files changed

+45
-25
lines changed

app/location/__init__.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,30 @@ def __init__(
1414
self, id, country, province, coordinates, last_updated, confirmed, deaths, recovered,
1515
): # pylint: disable=too-many-arguments
1616
# General info.
17-
self.id = id
18-
self.country = country.strip()
19-
self.province = province.strip()
20-
self.coordinates = coordinates
17+
self._id = id
18+
self._country = country.strip()
19+
self._province = province.strip()
20+
self._coordinates = coordinates
2121

2222
# Last update.
23-
self.last_updated = last_updated
23+
self._last_updated = last_updated
2424

2525
# Statistics.
26-
self.confirmed = confirmed
27-
self.deaths = deaths
28-
self.recovered = recovered
26+
self._confirmed = confirmed
27+
self._deaths = deaths
28+
self._recovered = recovered
29+
30+
@property
31+
def confirmed(self):
32+
return self._confirmed
33+
34+
@property
35+
def deaths(self):
36+
return self._deaths
37+
38+
@property
39+
def recovered(self):
40+
return self._recovered
2941

3042
@property
3143
def country_code(self):
@@ -35,7 +47,7 @@ def country_code(self):
3547
:returns: The country code.
3648
:rtype: str
3749
"""
38-
return (countries.country_code(self.country) or countries.DEFAULT_COUNTRY_CODE).upper()
50+
return (countries.country_code(self._country) or countries.DEFAULT_COUNTRY_CODE).upper()
3951

4052
@property
4153
def country_population(self):
@@ -56,20 +68,20 @@ def serialize(self):
5668
"""
5769
return {
5870
# General info.
59-
"id": self.id,
60-
"country": self.country,
71+
"id": self._id,
72+
"country": self._country,
6173
"country_code": self.country_code,
6274
"country_population": self.country_population,
63-
"province": self.province,
75+
"province": self._province,
6476
# Coordinates.
65-
"coordinates": self.coordinates.serialize(),
77+
"coordinates": self._coordinates.serialize(),
6678
# Last updated.
67-
"last_updated": self.last_updated,
79+
"last_updated": self._last_updated,
6880
# Latest data (statistics).
6981
"latest": {
70-
"confirmed": self.confirmed,
71-
"deaths": self.deaths,
72-
"recovered": self.recovered,
82+
"confirmed": self._confirmed,
83+
"deaths": self._deaths,
84+
"recovered": self._recovered,
7385
},
7486
}
7587

@@ -95,7 +107,7 @@ def __init__(self, id, country, province, coordinates, last_updated, timelines):
95107
)
96108

97109
# Set timelines.
98-
self.timelines = timelines
110+
self._timelines = timelines
99111

100112
# pylint: disable=arguments-differ
101113
def serialize(self, timelines=False):
@@ -115,7 +127,7 @@ def serialize(self, timelines=False):
115127
"timelines": {
116128
# Serialize all the timelines.
117129
key: value.serialize()
118-
for (key, value) in self.timelines.items()
130+
for (key, value) in self._timelines.items()
119131
}
120132
}
121133
)

app/location/csbs.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ def __init__(self, id, state, county, coordinates, last_updated, confirmed, deat
2222
recovered=0,
2323
)
2424

25-
self.state = state
26-
self.county = county
25+
self._state = state
26+
self._county = county
27+
28+
@property
29+
def state(self):
30+
return self._state
31+
32+
@property
33+
def county(self):
34+
return self._county
2735

2836
def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
2937
"""
@@ -36,7 +44,7 @@ def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused
3644

3745
# Update with new fields.
3846
serialized.update(
39-
{"state": self.state, "county": self.county,}
47+
{"state": self._state, "county": self._county,}
4048
)
4149

4250
# Return the serialized location.

app/location/nyt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class NYTLocation(TimelinedLocation):
1111
def __init__(self, id, state, county, coordinates, last_updated, timelines):
1212
super().__init__(id, "US", state, coordinates, last_updated, timelines)
1313

14-
self.state = state
15-
self.county = county
14+
self._state = state
15+
self._county = county
1616

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

2626
# Update with new fields.
2727
serialized.update(
28-
{"state": self.state, "county": self.county,}
28+
{"state": self._state, "county": self._county,}
2929
)
3030

3131
# Return the serialized location.

0 commit comments

Comments
 (0)