Skip to content

Commit 39c433e

Browse files
committed
implement
1 parent 23e1055 commit 39c433e

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""
2+
This module is used for patching data in the delphi_doctor_visits package.
3+
4+
To use this module, you need to specify the range of issue dates in params.json, like so:
5+
6+
{
7+
"common": {
8+
...
9+
},
10+
"validation": {
11+
...
12+
},
13+
"patch": {
14+
"patch_dir": "/covidcast-indicators/doctor_visits/AprilPatch",
15+
"start_issue": "2024-04-20",
16+
"end_issue": "2024-04-21"
17+
}
18+
}
19+
20+
It will generate data for that range of issue dates, and store them in batch issue format:
21+
[name-of-patch]/issue_[issue-date]/doctor-visits/actual_data_file.csv
22+
"""
23+
24+
from datetime import datetime, timedelta
25+
from os import makedirs
26+
27+
from delphi_utils import get_structured_logger, read_params
28+
29+
from .run import run_module
30+
31+
32+
def patch():
33+
"""
34+
Run the doctor visits indicator for a range of issue dates.
35+
36+
The range of issue dates is specified in params.json using the following keys:
37+
- "patch": Only used for patching data
38+
- "start_date": str, YYYY-MM-DD format, first issue date
39+
- "end_date": str, YYYY-MM-DD format, last issue date
40+
- "patch_dir": str, directory to write all issues output
41+
"""
42+
params = read_params()
43+
logger = get_structured_logger("delphi_claims_hosp.patch", filename=params["common"]["log_filename"])
44+
45+
start_issue = datetime.strptime(params["patch"]["start_issue"], "%Y-%m-%d")
46+
end_issue = datetime.strptime(params["patch"]["end_issue"], "%Y-%m-%d")
47+
48+
logger.info(f"""Start patching {params["patch"]["patch_dir"]}""")
49+
logger.info(f"""Start issue: {start_issue.strftime("%Y-%m-%d")}""")
50+
logger.info(f"""End issue: {end_issue.strftime("%Y-%m-%d")}""")
51+
52+
makedirs(params["patch"]["patch_dir"], exist_ok=True)
53+
54+
current_issue = start_issue
55+
56+
while current_issue <= end_issue:
57+
logger.info(f"""Running issue {current_issue.strftime("%Y-%m-%d")}""")
58+
59+
params["patch"]["current_issue"] = current_issue.strftime("%Y-%m-%d")
60+
61+
current_issue_yyyymmdd = current_issue.strftime("%Y%m%d")
62+
current_issue_dir = f"""{params["patch"]["patch_dir"]}/issue_{current_issue_yyyymmdd}/doctor-visits"""
63+
makedirs(f"{current_issue_dir}", exist_ok=True)
64+
params["common"]["export_dir"] = f"""{current_issue_dir}"""
65+
66+
run_module(params, logger)
67+
current_issue += timedelta(days=1)
68+
69+
70+
if __name__ == "__main__":
71+
patch()

0 commit comments

Comments
 (0)