Skip to content

Commit 8013c4e

Browse files
authored
Merge pull request #605 from cmu-delphi/main
Release nchs_mortality to production
2 parents c339e31 + acf2aef commit 8013c4e

Some content is hidden

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

55 files changed

+1456
-870
lines changed

Jenkinsfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pipeline {
4545
}
4646
parallel deploy_staging
4747
}
48+
sh "jenkins/deploy-staging-api-match-list.sh"
4849
}
4950
}
5051
stage('Deploy production') {

_delphi_utils_python/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ install: venv
1212

1313
lint:
1414
. env/bin/activate; \
15-
pylint $(dir)
15+
pylint $(dir); \
16+
pydocstyle $(dir)
1617

1718
test:
1819
. env/bin/activate ;\

_delphi_utils_python/delphi_utils/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
"""Common Utility Functions to Support DELPHI Indicators
3-
"""
2+
"""Common Utility Functions to Support DELPHI Indicators."""
43

54
from __future__ import absolute_import
65

_delphi_utils_python/delphi_utils/archive.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
22
Utilities for diffing and archiving covidcast export CSVs.
3+
34
Aims to simplify the creation of issues for new and backfilled value for indicators.
45
Also handles archiving of export CSVs to some backend (git, S3 etc.) before replacing them.
56
@@ -52,6 +53,7 @@ def diff_export_csv(
5253
) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]:
5354
"""
5455
Find differences in exported covidcast CSVs, using geo_id as the index.
56+
5557
Treats NA == NA as True.
5658
5759
Parameters
@@ -68,7 +70,6 @@ def diff_export_csv(
6870
changed_df is the pd.DataFrame of common rows from after_csv with changed values.
6971
added_df is the pd.DataFrame of added rows from after_csv.
7072
"""
71-
7273
export_csv_dtypes = {"geo_id": str, "val": float,
7374
"se": float, "sample_size": float}
7475

@@ -99,7 +100,7 @@ def run_module(archive_type: str,
99100
cache_dir: str,
100101
export_dir: str,
101102
**kwargs):
102-
"""Builds and runs an ArchiveDiffer.
103+
"""Build and run an ArchiveDiffer.
103104
104105
Parameters
105106
----------
@@ -132,13 +133,11 @@ def run_module(archive_type: str,
132133

133134

134135
class ArchiveDiffer:
135-
"""
136-
Base class for performing diffing and archiving of exported covidcast CSVs
137-
"""
136+
"""Base class for performing diffing and archiving of exported covidcast CSVs."""
138137

139138
def __init__(self, cache_dir: str, export_dir: str):
140139
"""
141-
Initialize an ArchiveDiffer
140+
Initialize an ArchiveDiffer.
142141
143142
Parameters
144143
----------
@@ -157,15 +156,17 @@ def __init__(self, cache_dir: str, export_dir: str):
157156

158157
def update_cache(self):
159158
"""
160-
For making sure cache_dir is updated correctly from a backend.
159+
Make sure cache_dir is updated correctly from a backend.
160+
161161
To be implemented by specific archiving backends.
162162
Should set self._cache_updated = True after verifying cache is updated.
163163
"""
164164
raise NotImplementedError
165165

166166
def diff_exports(self) -> Tuple[Files, FileDiffMap, Files]:
167167
"""
168-
Finds diffs across and within CSV files, from cache_dir to export_dir.
168+
Find diffs across and within CSV files, from cache_dir to export_dir.
169+
169170
Should be called after update_cache() succeeds. Only works on *.csv files,
170171
ignores every other file.
171172
@@ -223,7 +224,8 @@ def diff_exports(self) -> Tuple[Files, FileDiffMap, Files]:
223224

224225
def archive_exports(self, exported_files: Files) -> Tuple[Files, Files]:
225226
"""
226-
Handles actual archiving of files, depending on specific backend.
227+
Handle actual archiving of files, depending on specific backend.
228+
227229
To be implemented by specific archiving backends.
228230
229231
Parameters
@@ -241,6 +243,8 @@ def archive_exports(self, exported_files: Files) -> Tuple[Files, Files]:
241243

242244
def filter_exports(self, common_diffs: FileDiffMap):
243245
"""
246+
Filter export directory to only contain relevant files.
247+
244248
Filters down the export_dir to only contain:
245249
1) New files, 2) Changed files, filtered-down to the ADDED and CHANGED rows only.
246250
Should be called after archive_exports() so we archive the raw exports before
@@ -269,7 +273,7 @@ def filter_exports(self, common_diffs: FileDiffMap):
269273
replace(diff_file, exported_file)
270274

271275
def run(self):
272-
"""Runs the differ and archives the changed and new files."""
276+
"""Run the differ and archive the changed and new files."""
273277
self.update_cache()
274278

275279
# Diff exports, and make incremental versions
@@ -293,7 +297,8 @@ def run(self):
293297

294298
class S3ArchiveDiffer(ArchiveDiffer):
295299
"""
296-
AWS S3 backend for archving
300+
AWS S3 backend for archiving.
301+
297302
Archives CSV files into a S3 bucket, with keys "{indicator_prefix}/{csv_file_name}".
298303
Ideally, versioning should be enabled in this bucket to track versions of each CSV file.
299304
"""
@@ -306,6 +311,7 @@ def __init__(
306311
):
307312
"""
308313
Initialize a S3ArchiveDiffer.
314+
309315
See this link for possible aws_credentials kwargs:
310316
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html#boto3.session.Session
311317
@@ -330,9 +336,7 @@ def __init__(
330336
self.indicator_prefix = indicator_prefix
331337

332338
def update_cache(self):
333-
"""
334-
For making sure cache_dir is updated with all latest files from the S3 bucket.
335-
"""
339+
"""Make sure cache_dir is updated with all latest files from the S3 bucket."""
336340
# List all indicator-related objects from S3
337341
archive_objects = self.bucket.objects.filter(
338342
Prefix=self.indicator_prefix).all()
@@ -358,7 +362,7 @@ def archive_exports(self, # pylint: disable=arguments-differ
358362
update_s3: bool = True
359363
) -> Tuple[Files, Files]:
360364
"""
361-
Handles actual archiving of files to the S3 bucket.
365+
Handle actual archiving of files to the S3 bucket.
362366
363367
Parameters
364368
----------
@@ -398,7 +402,8 @@ def archive_exports(self, # pylint: disable=arguments-differ
398402

399403
class GitArchiveDiffer(ArchiveDiffer):
400404
"""
401-
Local git repo backend for archiving
405+
Local git repo backend for archiving.
406+
402407
Archives CSV files into a local git repo as commits.
403408
Assumes that a git repository is already set up.
404409
"""
@@ -446,7 +451,8 @@ def __init__(
446451

447452
def get_branch(self, branch_name: Optional[str] = None) -> Head:
448453
"""
449-
Retrieves a Head object representing a branch of specified name.
454+
Retrieve a Head object representing a branch of specified name.
455+
450456
Creates the branch from the current active branch if does not exist yet.
451457
452458
Parameters
@@ -469,6 +475,8 @@ def get_branch(self, branch_name: Optional[str] = None) -> Head:
469475
@contextmanager
470476
def archiving_branch(self):
471477
"""
478+
Context manager for checking out a branch.
479+
472480
Useful for checking out self.branch within a context, then switching back
473481
to original branch when finished.
474482
"""
@@ -482,8 +490,9 @@ def archiving_branch(self):
482490

483491
def update_cache(self):
484492
"""
493+
Check if cache_dir is clean: has everything nicely committed if override_dirty=False.
494+
485495
Since we are using a local git repo, assumes there is nothing to update from.
486-
Checks if cache_dir is clean: has everything nice committed if override_dirty=False
487496
"""
488497
# Make sure cache directory is clean: has everything nicely committed
489498
if not self.override_dirty:
@@ -495,14 +504,16 @@ def update_cache(self):
495504

496505
def diff_exports(self) -> Tuple[Files, FileDiffMap, Files]:
497506
"""
498-
Same as base class diff_exports, but in context of specified branch
507+
Find diffs across and within CSV files, from cache_dir to export_dir.
508+
509+
Same as base class diff_exports, but in context of specified branch.
499510
"""
500511
with self.archiving_branch():
501512
return super().diff_exports()
502513

503514
def archive_exports(self, exported_files: Files) -> Tuple[Files, Files]:
504515
"""
505-
Handles actual archiving of files to the local git repo.
516+
Handle actual archiving of files to the local git repo.
506517
507518
Parameters
508519
----------

_delphi_utils_python/delphi_utils/geomap.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ class GeoMapper: # pylint: disable=too-many-public-methods
9191
"""
9292

9393
def __init__(self):
94-
"""Initialize geomapper. Holds loading the crosswalk tables
95-
until a conversion function is first used.
94+
"""Initialize geomapper.
95+
96+
Holds loading the crosswalk tables until a conversion function is first used.
9697
9798
Parameters
9899
---------
@@ -110,7 +111,7 @@ def __init__(self):
110111

111112
# Utility functions
112113
def _load_crosswalk(self, from_code, to_code):
113-
"""Loads the crosswalk from from_code -> to_code."""
114+
"""Load the crosswalk from from_code -> to_code."""
114115
stream = pkg_resources.resource_stream(
115116
__name__, self.crosswalk_filepaths[from_code][to_code]
116117
)
@@ -189,7 +190,7 @@ def _load_crosswalk(self, from_code, to_code):
189190

190191
@staticmethod
191192
def convert_fips_to_mega(data, fips_col="fips", mega_col="megafips"):
192-
"""convert fips string to a megafips string"""
193+
"""Convert fips string to a megafips string."""
193194
data = data.copy()
194195
data[mega_col] = data[fips_col].astype(str).str.zfill(5)
195196
data[mega_col] = data[mega_col].str.slice_replace(start=2, stop=5, repl="000")
@@ -205,7 +206,7 @@ def megacounty_creation(
205206
date_col="date",
206207
mega_col="megafips",
207208
):
208-
"""create megacounty column
209+
"""Create megacounty column.
209210
210211
Parameters
211212
---------
@@ -412,8 +413,9 @@ def replace_geocode(
412413

413414
def add_population_column(self, data, geocode_type, geocode_col=None, dropna=True):
414415
"""
415-
Appends a population column to a dataframe, based on the FIPS or ZIP code. If no
416-
dataframe is provided, the full crosswalk from geocode to population is returned.
416+
Append a population column to a dataframe, based on the FIPS or ZIP code.
417+
418+
If no dataframe is provided, the full crosswalk from geocode to population is returned.
417419
418420
Parameters
419421
---------
@@ -464,7 +466,7 @@ def fips_to_megacounty(
464466
mega_col="megafips",
465467
count_cols=None,
466468
):
467-
"""Convert and aggregate from FIPS to megaFIPS
469+
"""Convert and aggregate from FIPS to megaFIPS.
468470
469471
Parameters
470472
---------

_delphi_utils_python/delphi_utils/signal.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import covidcast
33

44
def add_prefix(signal_names, wip_signal, prefix="wip_"):
5-
"""Adds prefix to signal if there is a WIP signal
5+
"""Add prefix to signal if there is a WIP signal.
6+
67
Parameters
78
----------
89
signal_names: List[str]
@@ -18,7 +19,6 @@ def add_prefix(signal_names, wip_signal, prefix="wip_"):
1819
List of signal names
1920
wip/non wip signals for further computation
2021
"""
21-
2222
if wip_signal is True:
2323
return [prefix + signal for signal in signal_names]
2424
if isinstance(wip_signal, list):
@@ -37,7 +37,8 @@ def add_prefix(signal_names, wip_signal, prefix="wip_"):
3737

3838

3939
def public_signal(signal):
40-
"""Checks if the signal name is already public using COVIDcast
40+
"""Check if the signal name is already public using COVIDcast.
41+
4142
Parameters
4243
----------
4344
signal : str

_delphi_utils_python/delphi_utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from shutil import copyfile
66

77
def read_params():
8-
"""Reads a file named 'params.json' in the current working directory.
8+
"""Read a file named 'params.json' in the current working directory.
99
1010
If the file does not exist, it copies the file 'params.json.template' to
1111
'param.json' and then reads the file.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
- hosts: api_proxy_staging
3+
remote_user: deploy
4+
vars_files:
5+
- vars.yaml
6+
- vault.yaml
7+
tasks:
8+
- name: Set staging api proxy openresty signal match list template.
9+
template:
10+
src: "templates/staging-api-match-list.j2"
11+
dest: "/common/staging-api-match-list"
12+
owner: "deploy"
13+
group: "deploy"
14+
mode: "0777"

ansible/inventory

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ delphi-master-prod-01.delphi.cmu.edu
33

44
[runtime_host_staging]
55
app-mono-dev-01.delphi.cmu.edu
6+
7+
[api_proxy_staging]
8+
api-staging.delphi.cmu.edu

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
"static_file_dir": "./static",
33
"export_dir": "/common/covidcast/receiving/chng",
44
"cache_dir": "./cache",
5-
"input_denom_file": null,
6-
"input_covid_file": null,
5+
"input_files": {
6+
"denom": null,
7+
"covid": null,
8+
"flu": null,
9+
"mixed": null,
10+
"flu_like": null,
11+
"covid_like": null
12+
},
713
"start_date": "2020-02-01",
814
"end_date": null,
915
"drop_date": null,
@@ -13,6 +19,7 @@
1319
"parallel": false,
1420
"geos": ["state", "msa", "hrr", "county"],
1521
"weekday": [true, false],
22+
"types": ["covid","cli"],
1623
"wip_signal": "",
1724
"aws_credentials": {
1825
"aws_access_key_id": "",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"export_start_date": "2020-02-01",
3+
"static_file_dir": "./static",
4+
"export_dir": "/common/covidcast/receiving/nchs-mortality",
5+
"cache_dir": "./cache",
6+
"daily_export_dir": "./daily_receiving",
7+
"daily_cache_dir": "./daily_cache",
8+
"token": "{{ nchs_mortality_token }}",
9+
"mode":"",
10+
"aws_credentials": {
11+
"aws_access_key_id": "{{ delphi_aws_access_key_id }}",
12+
"aws_secret_access_key": "{{ delphi_aws_secret_access_key }}"
13+
},
14+
"bucket_name": "delphi-covidcast-indicator-output"
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data_source=quidel-staging&signal=covid_ag_
2+
data_source=chng
3+
data_source=safegraph
4+
data_source=google-symptoms

ansible/vars.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ changehc_sftp_host: "{{ vault_changehc_sftp_host }}"
2121
changehc_sftp_port: "{{ vault_changehc_sftp_port }}"
2222
changehc_sftp_user: "{{ vault_changehc_sftp_user }}"
2323
changehc_sftp_password: "{{ vault_changehc_sftp_password }}"
24+
nchs_mortality_token: "{{ vault_nchs_mortality_token }}"

0 commit comments

Comments
 (0)