Skip to content

Commit bb0b2d5

Browse files
committed
merge location package into a single module
1 parent ecb0a68 commit bb0b2d5

File tree

6 files changed

+77
-83
lines changed

6 files changed

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

66

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

123123
# Return the serialized location.
124124
return serialized
125+
126+
127+
class CSBSLocation(Location):
128+
"""
129+
A CSBS (county) location.
130+
"""
131+
132+
# pylint: disable=too-many-arguments,redefined-builtin
133+
def __init__(self, id, state, county, coordinates, last_updated, confirmed, deaths):
134+
super().__init__(
135+
# General info.
136+
id,
137+
"US",
138+
state,
139+
coordinates,
140+
last_updated,
141+
# Statistics.
142+
confirmed=confirmed,
143+
deaths=deaths,
144+
recovered=0,
145+
)
146+
147+
self.state = state
148+
self.county = county
149+
150+
def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
151+
"""
152+
Serializes the location into a dict.
153+
:returns: The serialized location.
154+
:rtype: dict
155+
"""
156+
serialized = super().serialize()
157+
158+
# Update with new fields.
159+
serialized.update(
160+
{"state": self.state, "county": self.county,}
161+
)
162+
163+
# Return the serialized location.
164+
return serialized
165+
166+
167+
class NYTLocation(TimelinedLocation):
168+
"""
169+
A NYT (county) Timelinedlocation.
170+
"""
171+
172+
# pylint: disable=too-many-arguments,redefined-builtin
173+
def __init__(self, id, state, county, coordinates, last_updated, timelines):
174+
super().__init__(id, "US", state, coordinates, last_updated, timelines)
175+
176+
self.state = state
177+
self.county = county
178+
179+
def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
180+
"""
181+
Serializes the location into a dict.
182+
:returns: The serialized location.
183+
:rtype: dict
184+
"""
185+
serialized = super().serialize(timelines)
186+
187+
# Update with new fields.
188+
serialized.update(
189+
{"state": self.state, "county": self.county,}
190+
)
191+
192+
# Return the serialized location.
193+
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
import csv
33
import logging
44
from datetime import datetime
5+
from pprint import pformat as pf
56

67
from asyncache import cached
78
from cachetools import TTLCache
89

910
from ...caches import check_cache, load_cache
1011
from ...coordinates import Coordinates
11-
from ...location.csbs import CSBSLocation
12+
from ...location import CSBSLocation
1213
from ...utils import httputils
1314
from . import LocationService
1415

@@ -97,6 +98,6 @@ async def get_locations():
9798
await load_cache(data_id, locations)
9899
except TypeError as type_err:
99100
LOGGER.error(type_err)
100-
101+
101102
# Return the locations.
102103
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)