Skip to content

Commit 9cb1da4

Browse files
committed
cleanup names and comments
- rename input arg to `update` to avoid reassignment later - comment and reuse args_insert - spelling - comment magic constant used in output format - rename location-network/catchmentid map
1 parent 3580f3f commit 9cb1da4

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/acquisition/flusurv/flusurv.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
=== Purpose ===
44
===============
55
6-
Fetches FluSurv-NET data (flu hospitaliation rates) from CDC. Unlike the other
6+
Fetches FluSurv-NET data (flu hospitalization rates) from CDC. Unlike the other
77
CDC-hosted datasets (e.g. FluView), FluSurv is not available as a direct
88
download. This program emulates web browser requests for the web app and
99
extracts data of interest from the JSON response.
@@ -49,7 +49,7 @@
4949

5050
# all currently available FluSurv locations and their associated codes
5151
# the number pair represents NetworkID and CatchmentID
52-
location_codes = {
52+
location_to_code = {
5353
"CA": (2, 1),
5454
"CO": (2, 2),
5555
"CT": (2, 3),
@@ -155,7 +155,7 @@ def mmwrid_to_epiweek(mmwrid):
155155

156156
def extract_from_object(data_in):
157157
"""
158-
Given a FluSurv data object, return hospitaliation rates.
158+
Given a FluSurv data object, return hospitalization rates.
159159
160160
The returned object is indexed first by epiweek, then by zero-indexed age
161161
group.
@@ -171,11 +171,16 @@ def extract_from_object(data_in):
171171
# capture as-of-yet undefined age groups 10, 11, and 12
172172
continue
173173
age_index = obj["age"] - 1
174-
# iterage over weeks
174+
# iterate over weeks
175175
for mmwrid, _, _, rate in obj["data"]:
176176
epiweek = mmwrid_to_epiweek(mmwrid)
177177
if epiweek not in data_out:
178178
# weekly rate of each age group
179+
# TODO what is this magic constant? Maybe total # of age
180+
# groups?? Appears to be assuming that age groups are
181+
# numbered sequentially. Better to store data_out in a
182+
# dictionary of dictionaries, given new age group ids
183+
# (e.g. 99, 21, etc)
179184
data_out[epiweek] = [None] * 9
180185
prev_rate = data_out[epiweek][age_index]
181186
if prev_rate is None:
@@ -201,7 +206,7 @@ def get_data(location_code):
201206
202207
This method performs the following operations:
203208
- fetches FluSurv data from CDC
204-
- extracts and returns hospitaliation rates
209+
- extracts and returns hospitalization rates
205210
"""
206211

207212
# fetch

src/acquisition/flusurv/flusurv_update.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,16 @@ def get_rows(cur):
9090
return num
9191

9292

93-
def update(issue, location_name, test_mode=False):
93+
def update(issue, location, test_mode=False):
9494
"""Fetch and store the currently avialble weekly FluSurv dataset."""
9595

9696
# fetch data
97-
location_code = flusurv.location_codes[location_name]
98-
print("fetching data for", location_name, location_code)
97+
location_code = flusurv.location_to_code[location]
98+
print("fetching data for", location, location_code)
9999
data = flusurv.get_data(location_code)
100100

101101
# metadata
102102
epiweeks = sorted(data.keys())
103-
location = location_name
104103
release_date = str(EpiDate.today())
105104

106105
# connect to the database
@@ -142,8 +141,9 @@ def update(issue, location_name, test_mode=False):
142141
# values (including duplicates) were stored on each run.
143142
continue
144143
args_meta = [release_date, issue, epiweek, location, lag]
144+
# List of values in order of columns specified in sql statement above
145145
args_insert = data[epiweek]
146-
args_update = [release_date] + data[epiweek]
146+
args_update = [release_date] + args_insert
147147
cur.execute(sql, tuple(args_meta + args_insert + args_update))
148148

149149
# commit and disconnect
@@ -184,7 +184,7 @@ def main():
184184
# fetch flusurv data
185185
if args.location == "all":
186186
# all locations
187-
for location in flusurv.location_codes.keys():
187+
for location in flusurv.location_to_code.keys():
188188
update(issue, location, args.test)
189189
else:
190190
# single location

0 commit comments

Comments
 (0)