Skip to content

Commit 838951d

Browse files
committed
merge location package into a single module
1 parent 464453d commit 838951d

File tree

6 files changed

+75
-83
lines changed

6 files changed

+75
-83
lines changed
Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""app.location"""
2-
from ..coordinates import Coordinates
3-
from ..utils import countries
4-
from ..utils.populations import country_population
2+
from .utils import countries
3+
from .utils.populations import country_population
54

65

76
# pylint: disable=redefined-builtin,invalid-name
@@ -122,3 +121,72 @@ def serialize(self, timelines=False):
122121

123122
# Return the serialized location.
124123
return serialized
124+
125+
126+
class CSBSLocation(Location):
127+
"""
128+
A CSBS (county) location.
129+
"""
130+
131+
# pylint: disable=too-many-arguments,redefined-builtin
132+
def __init__(self, id, state, county, coordinates, last_updated, confirmed, deaths):
133+
super().__init__(
134+
# General info.
135+
id,
136+
"US",
137+
state,
138+
coordinates,
139+
last_updated,
140+
# Statistics.
141+
confirmed=confirmed,
142+
deaths=deaths,
143+
recovered=0,
144+
)
145+
146+
self.state = state
147+
self.county = county
148+
149+
def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
150+
"""
151+
Serializes the location into a dict.
152+
:returns: The serialized location.
153+
:rtype: dict
154+
"""
155+
serialized = super().serialize()
156+
157+
# Update with new fields.
158+
serialized.update(
159+
{"state": self.state, "county": self.county,}
160+
)
161+
162+
# Return the serialized location.
163+
return serialized
164+
165+
166+
class NYTLocation(TimelinedLocation):
167+
"""
168+
A NYT (county) Timelinedlocation.
169+
"""
170+
171+
# pylint: disable=too-many-arguments,redefined-builtin
172+
def __init__(self, id, state, county, coordinates, last_updated, timelines):
173+
super().__init__(id, "US", state, coordinates, last_updated, timelines)
174+
175+
self.state = state
176+
self.county = county
177+
178+
def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
179+
"""
180+
Serializes the location into a dict.
181+
:returns: The serialized location.
182+
:rtype: dict
183+
"""
184+
serialized = super().serialize(timelines)
185+
186+
# Update with new fields.
187+
serialized.update(
188+
{"state": self.state, "county": self.county,}
189+
)
190+
191+
# Return the serialized location.
192+
return serialized

app/location/csbs.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

app/location/nyt.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

app/services/location/csbs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ...caches import check_cache, load_cache
1010
from ...coordinates import Coordinates
11-
from ...location.csbs import CSBSLocation
11+
from ...location import CSBSLocation
1212
from ...utils import httputils
1313
from . import LocationService
1414

@@ -97,6 +97,6 @@ async def get_locations():
9797
await load_cache(data_id, locations)
9898
except TypeError as type_err:
9999
LOGGER.error(type_err)
100-
100+
101101
# Return the locations.
102102
return locations

app/services/location/nyt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ...caches import check_cache, load_cache
1010
from ...coordinates import Coordinates
11-
from ...location.nyt import NYTLocation
11+
from ...location import NYTLocation
1212
from ...timeline import Timeline
1313
from ...utils import httputils
1414
from . import LocationService

tests/test_nyt.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import pytest
55

6-
from app.location import TimelinedLocation
7-
from app.location.nyt import NYTLocation
6+
from app.location import NYTLocation, TimelinedLocation
87
from app.services.location import nyt
98
from tests.conftest import mocked_strptime_isoformat
109

0 commit comments

Comments
 (0)