Skip to content

Commit 928dc24

Browse files
committed
Merge branch 'main' into remove-wip
2 parents e1ce9d0 + 753c688 commit 928dc24

File tree

69 files changed

+913
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+913
-424
lines changed

.github/workflows/json-check.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This workflow will verify all JSON files in the directory, excluding venv files
2+
3+
name: JSON check
4+
5+
on:
6+
push:
7+
branches: [ main, prod ]
8+
pull_request:
9+
types: [ opened, synchronize, reopened, ready_for_review ]
10+
branches: [ main, prod ]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-20.04
15+
if: github.event.pull_request.draft == false
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python 3.8
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: 3.8
22+
- name: Check JSONs
23+
run: |
24+
python3 -c "import json; from pathlib import Path
25+
for i in Path('.').glob('**/*.json*'):
26+
if '/env/' not in str(i):
27+
print(i)
28+
json.load(open(str(i)))"

_delphi_utils_python/data_proc/geomap/geo_data_proc.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,14 @@ def create_fips_population_table():
400400
df_pr = df_pr[~df_pr["fips"].isin(census_pop["fips"])]
401401
census_pop_pr = pd.concat([census_pop, df_pr])
402402

403-
census_pop_pr.to_csv(join(OUTPUT_DIR, FIPS_POPULATION_OUT_FILENAME), index=False)
403+
# Filled from https://www.census.gov/data/tables/2010/dec/2010-island-areas.html
404+
territories_pop = pd.DataFrame({
405+
"fips": ["60010", "60020", "60030", "60040", "60050", "66010", "78010", "78020", "78030", "69085", "69100", "69110", "69120"],
406+
"pop": [23030, 1143, 0, 17, 31329, 159358, 50601, 4170, 51634, 0, 2527, 48220, 3136]
407+
})
408+
census_pop_territories = pd.concat([census_pop_pr, territories_pop])
409+
410+
census_pop_territories.to_csv(join(OUTPUT_DIR, FIPS_POPULATION_OUT_FILENAME), index=False)
404411

405412

406413
def derive_zip_population_table():

_delphi_utils_python/delphi_utils/data/fips_hhs_table.csv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,3 +3273,16 @@ fips,hhs
32733273
72149,2
32743274
72151,2
32753275
72153,2
3276+
60010,9
3277+
60020,9
3278+
60030,9
3279+
60040,9
3280+
60050,9
3281+
66010,9
3282+
78010,2
3283+
78020,2
3284+
78030,2
3285+
69085,9
3286+
69100,9
3287+
69110,9
3288+
69120,9

_delphi_utils_python/delphi_utils/data/fips_pop.csv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,3 +3273,16 @@ fips,pop
32733273
72149,26073
32743274
72151,37941
32753275
72153,42043
3276+
60010,23030
3277+
60020,1143
3278+
60030,0
3279+
60040,17
3280+
60050,31329
3281+
66010,159358
3282+
78010,50601
3283+
78020,4170
3284+
78030,51634
3285+
69085,0
3286+
69100,2527
3287+
69110,48220
3288+
69120,3136

_delphi_utils_python/delphi_utils/data/fips_state_table.csv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,3 +3273,16 @@ fips,state_code,state_id,state_name
32733273
72149,72,pr,Puerto Rico
32743274
72151,72,pr,Puerto Rico
32753275
72153,72,pr,Puerto Rico
3276+
60010,60,as,American Samoa
3277+
60020,60,as,American Samoa
3278+
60030,60,as,American Samoa
3279+
60040,60,as,American Samoa
3280+
60050,60,as,American Samoa
3281+
66010,66,gu,Guam
3282+
78010,78,vi,U.S. Virgin Islands
3283+
78020,78,vi,U.S. Virgin Islands
3284+
78030,78,vi,U.S. Virgin Islands
3285+
69085,69,mp,Northern Mariana Islands
3286+
69100,69,mp,Northern Mariana Islands
3287+
69110,69,mp,Northern Mariana Islands
3288+
69120,69,mp,Northern Mariana Islands

_delphi_utils_python/delphi_utils/geomap.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ def __init__(self):
125125
# Utility functions
126126
def _load_crosswalk(self, from_code, to_code):
127127
"""Load the crosswalk from from_code -> to_code."""
128+
assert from_code in self.crosswalk_filepaths, \
129+
f"No crosswalk files for {from_code}; try {'; '.join(self.crosswalk_filepaths.keys())}"
130+
assert to_code in self.crosswalk_filepaths[from_code], \
131+
f"No crosswalk file from {from_code} to {to_code}; try" \
132+
f"{'; '.join(self.crosswalk_filepaths[from_code].keys())}"
128133
stream = pkg_resources.resource_stream(
129134
__name__, self.crosswalk_filepaths[from_code][to_code]
130135
)
@@ -301,6 +306,7 @@ def add_geocode(
301306
df = df.copy()
302307
from_col = from_code if from_col is None else from_col
303308
new_col = new_code if new_col is None else new_col
309+
assert from_col != new_col, f"Can't use the same column '{from_col}' for both from_col and to_col"
304310
state_codes = ["state_code", "state_id", "state_name"]
305311

306312
if not is_string_dtype(df[from_col]):
@@ -319,7 +325,7 @@ def add_geocode(
319325
return df
320326
elif new_code == "nation":
321327
raise ValueError(
322-
"Conversion to the nation level is only supported from the FIPS and ZIP codes."
328+
f"Conversion to the nation level is not supported from {from_code}; try fips, zip, or state_*"
323329
)
324330

325331
# state codes are all stored in one table
@@ -522,6 +528,17 @@ def fips_to_megacounty(
522528
data = data.reset_index().groupby([date_col, mega_col]).sum()
523529
return data.reset_index()
524530

531+
def as_mapper_name(self, geo_type, state="state_id"):
532+
"""
533+
Return the mapper equivalent of a region type.
534+
535+
Human-readable names like 'county' will return their mapper equivalents ('fips').
536+
"""
537+
if geo_type == "state":
538+
return state
539+
if geo_type == "county":
540+
return "fips"
541+
return geo_type
525542
def get_geo_values(self, geo_type):
526543
"""
527544
Return a set of all values for a given geography type.

_delphi_utils_python/delphi_utils/logger.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
"""Structured logger utility for creating JSON logs in Delphi pipelines."""
22
import logging
3+
import sys
4+
import threading
35
import structlog
46

5-
def get_structured_logger(name = __name__, filename = None):
7+
8+
def handle_exceptions(logger):
9+
"""Handle exceptions using the provided logger."""
10+
def exception_handler(etype, value, traceback):
11+
logger.exception("Top-level exception occurred",
12+
exc_info=(etype, value, traceback))
13+
14+
def multithread_exception_handler(args):
15+
exception_handler(args.exc_type, args.exc_value, args.exc_traceback)
16+
17+
sys.excepthook = exception_handler
18+
threading.excepthook = multithread_exception_handler
19+
20+
21+
def get_structured_logger(name=__name__,
22+
filename=None,
23+
log_exceptions=True):
624
"""Create a new structlog logger.
725
826
Use the logger returned from this in indicator code using the standard
@@ -66,4 +84,9 @@ def get_structured_logger(name = __name__, filename = None):
6684
cache_logger_on_first_use=True,
6785
)
6886

69-
return structlog.get_logger(name)
87+
logger = structlog.get_logger(name)
88+
89+
if log_exceptions:
90+
handle_exceptions(logger)
91+
92+
return logger

_delphi_utils_python/tests/test_geomap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,6 @@ def test_get_geos(self):
307307
gmpr = GeoMapper()
308308
assert gmpr.get_geo_values("nation") == {"us"}
309309
assert gmpr.get_geo_values("hhs") == set(str(i) for i in range(1, 11))
310-
assert len(gmpr.get_geo_values("fips")) == 3274
310+
assert len(gmpr.get_geo_values("fips")) == 3287
311311
assert len(gmpr.get_geo_values("state_id")) == 60
312312
assert len(gmpr.get_geo_values("zip")) == 32976

ansible/templates/changehc-params-prod.json.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
"user": "{{ changehc_sftp_user }}",
3232
"pass": "{{ changehc_sftp_password }}",
3333
"port": "{{ changehc_sftp_port }}"
34-
}
34+
},
35+
"log_filename": "/var/log/indicators/changehc.log"
3536
}

ansible/templates/nchs_mortality-params-prod.json.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"aws_access_key_id": "{{ delphi_aws_access_key_id }}",
1212
"aws_secret_access_key": "{{ delphi_aws_secret_access_key }}"
1313
},
14-
"bucket_name": "delphi-covidcast-indicator-output"
14+
"bucket_name": "delphi-covidcast-indicator-output",
15+
"log_filename": "/var/log/indicators/nchs_mortality.log"
1516
}

ansible/templates/quidel_covidtest-params-prod.json.j2

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
"export_end_date": "",
77
"pull_start_date": "2020-05-26",
88
"pull_end_date":"",
9-
"mail_server": "{{ quidel_datadrop_mail_server }}",
10-
"account": "{{ quidel_datadrop_account }}",
11-
"password": "{{ quidel_datadrop_password }}",
12-
"sender": "{{ quidel_datadrop_sender }}",
9+
"aws_credentials": {
10+
"aws_access_key_id": "{{ quidel_aws_access_key_id }}",
11+
"aws_secret_access_key": "{{ quidel_aws_secret_access_key }}"
12+
},
13+
"bucket_name": "{{ quidel_aws_bucket_name }}",
1314
"wip_signal": [""],
14-
"mode": ""
15-
}
15+
"mode": "",
16+
"log_filename": "/var/log/indicators/quidel_covidtest.log"
17+
}

ansible/templates/safegraph-params-prod.json.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"aws_default_region": "us-east-1",
1010
"aws_endpoint": "https://s3.wasabisys.com",
1111
"sync": true,
12-
"wip_signal" : []
12+
"wip_signal" : [],
13+
"log_filename": "/var/log/indicators/safegraph.log"
1314
}

ansible/templates/safegraph_patterns-params-prod.json.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"aws_default_region": "us-east-1",
1010
"aws_endpoint": "https://s3.wasabisys.com",
1111
"sync": true,
12-
"wip_signal" : []
12+
"wip_signal" : [],
13+
"log_filename": "/var/log/indicators/safegraph_patterns.log"
1314
}

ansible/templates/sir_complainsalot-params-prod.json.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"channel": "#sir-complains-a-lot",
3+
"log_filename": "/var/log/indicators/sircal.log",
34
"slack_token": "{{ sir_complainsalot_slack_token }}",
45
"sources": {
56
"doctor-visits": {

ansible/vars.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ delphi_aws_access_key_id: "{{ vault_delphi_aws_access_key_id }}"
1515
delphi_aws_secret_access_key: "{{ vault_delphi_aws_secret_access_key }}"
1616
safegraph_aws_access_key_id: "{{ vault_safegraph_aws_access_key_id }}"
1717
safegraph_aws_secret_access_key: "{{ vault_safegraph_aws_secret_access_key }}"
18-
quidel_datadrop_mail_server: "{{ vault_quidel_datadrop_mail_server }}"
19-
quidel_datadrop_account: "{{ vault_quidel_datadrop_account }}"
20-
quidel_datadrop_password: "{{ vault_quidel_datadrop_password }}"
21-
quidel_datadrop_sender: "{{ vault_quidel_datadrop_sender }}"
18+
quidel_aws_access_key_id: "{{ vault_quidel_aws_access_key_id }}"
19+
quidel_aws_secret_access_key: "{{ vault_quidel_aws_secret_access_key }}"
20+
quidel_aws_bucket_name: 'delphi-quidel-data'
2221
changehc_sftp_host: "{{ vault_changehc_sftp_host }}"
2322
changehc_sftp_port: "{{ vault_changehc_sftp_port }}"
2423
changehc_sftp_user: "{{ vault_changehc_sftp_user }}"

0 commit comments

Comments
 (0)