-
Notifications
You must be signed in to change notification settings - Fork 16
2088 patch nhsn #2094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
2088 patch nhsn #2094
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0157f0d
in progress
aysim319 9ae52f1
changed insertions to be weekday index
aysim319 778eb57
finishing up test and cleaning up
aysim319 8b3d95c
lint
aysim319 c7769cc
more test
aysim319 746856c
fixed tests
aysim319 3d004b7
more test fix
aysim319 6879f03
fixed pull test
aysim319 34bda4a
Update nhsn/delphi_nhsn/patch.py docs
aysim319 043f374
changed so only the latest day in epiweek gets patched in
aysim319 6e1e54a
making dataset_id into constants
aysim319 873162e
lint
aysim319 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """ | ||
| This module is used for patching data in the delphi_nhsn package. | ||
|
|
||
| To use this module, you need to specify the range of issue dates in params.json, like so: | ||
|
|
||
| { | ||
| "common": { | ||
| ... | ||
| }, | ||
| "validation": { | ||
| ... | ||
| }, | ||
| "patch": { | ||
| "patch_dir": "/Users/minhkhuele/Desktop/delphi/covidcast-indicators/nhsn/patch" | ||
| } | ||
| } | ||
|
|
||
| It will generate data for the range of issue dates corresponding to source data files available in "backup_dir" | ||
| specified under "common", and store them in batch issue format under "patch_dir": | ||
| [name-of-patch]/issue_[issue-date]/nhsn/actual_data_file.csv | ||
| """ | ||
|
|
||
| from datetime import datetime | ||
| from os import makedirs | ||
| from pathlib import Path | ||
| from typing import List | ||
|
|
||
| from delphi_utils import get_structured_logger, read_params | ||
| from epiweeks import Week | ||
|
|
||
| from .run import run_module | ||
|
|
||
|
|
||
| def filter_source_files(source_files: List[Path]): | ||
| """ | ||
| Filter patch files such that each element in the list is an unique epiweek with the latest issue date. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| source_files | ||
|
|
||
| Returns | ||
| ------- | ||
| list of issue dates | ||
|
|
||
| """ | ||
| epiweek_dict = dict() | ||
|
|
||
| for file in source_files: | ||
| if "prelim" not in file.stem: | ||
| current_issue_date = datetime.strptime(file.name.split(".")[0], "%Y%m%d") | ||
| epiweek = Week.fromdate(current_issue_date) | ||
| epiweek_dict[epiweek] = file | ||
|
|
||
| filtered_patch_list = list(epiweek_dict.values()) | ||
| return filtered_patch_list | ||
|
|
||
|
|
||
| def patch(params): | ||
| """ | ||
| Run the doctor visits indicator for a range of issue dates. | ||
|
|
||
| The range of issue dates is specified in params.json using the following keys: | ||
| - "patch": Only used for patching data | ||
| - "patch_dir": str, directory to write all issues output | ||
| """ | ||
| logger = get_structured_logger("delphi_nhsn.patch", filename=params["common"]["log_filename"]) | ||
|
|
||
| source_files = sorted(Path(params["common"]["backup_dir"]).glob("*.csv.gz")) | ||
| makedirs(params["patch"]["patch_dir"], exist_ok=True) | ||
|
|
||
| logger.info( | ||
| "Starting patching", | ||
| patch_directory=params["patch"]["patch_dir"], | ||
| start_issue=source_files[0].name.split(".")[0], | ||
| end_issue=source_files[-1].name.split(".")[0], | ||
| ) | ||
|
|
||
| patch_list = filter_source_files(source_files) | ||
| for file in patch_list: | ||
| issue_date = datetime.strptime(file.name.split(".")[0], "%Y%m%d") | ||
| current_issue_ew = Week.fromdate(issue_date) | ||
| logger.info("Running issue", issue_date=issue_date.strftime("%Y-%m-%d")) | ||
| params["patch"]["issue_date"] = issue_date.strftime("%Y%m%d") | ||
| current_issue_dir = f"{params['patch']['patch_dir']}/issue_{current_issue_ew}/nhsn" | ||
| makedirs(current_issue_dir, exist_ok=True) | ||
| params["common"]["export_dir"] = current_issue_dir | ||
| params["common"]["custom_run"] = True | ||
| run_module(params, logger) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| patch(read_params()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not fully understanding what's going on here, but Is there a way to write this chunk such that we don't have to change it later?