Skip to content

Commit cbc7894

Browse files
committed
implimentation done
1 parent 39c433e commit cbc7894

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

claims_hosp/delphi_claims_hosp/download_claims_ftp_files.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ def change_date_format(name):
5353
return name
5454

5555

56-
def download(ftp_credentials, out_path, logger):
56+
def download(ftp_credentials, out_path, logger, issue_date=None):
5757
"""Pull the latest raw files."""
58-
current_time = datetime.datetime.now()
58+
current_time = issue_date if issue_date else datetime.datetime.now()
59+
5960
seconds_in_day = 24 * 60 * 60
6061
logger.info("starting download", time=current_time)
6162

claims_hosp/delphi_claims_hosp/get_latest_claims_name.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import datetime
66
from pathlib import Path
77

8-
def get_latest_filename(dir_path, logger):
8+
def get_latest_filename(dir_path, logger, issue_date=None):
99
"""Get the latest filename from the list of downloaded raw files."""
10-
current_date = datetime.datetime.now()
10+
current_date = issue_date if issue_date else datetime.datetime.now()
1111
files = list(Path(dir_path).glob("*"))
1212

1313
latest_timestamp = datetime.datetime(1900, 1, 1)

claims_hosp/delphi_claims_hosp/patch.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,19 @@ def patch():
4545
start_issue = datetime.strptime(params["patch"]["start_issue"], "%Y-%m-%d")
4646
end_issue = datetime.strptime(params["patch"]["end_issue"], "%Y-%m-%d")
4747

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")}""")
48+
logger.info(
49+
"Starting patching",
50+
patch_directory=params["patch"]["patch_dir"],
51+
start_issue=start_issue.strftime("%Y-%m-%d"),
52+
end_issue=end_issue.strftime("%Y-%m-%d"),
53+
)
5154

5255
makedirs(params["patch"]["patch_dir"], exist_ok=True)
5356

5457
current_issue = start_issue
5558

5659
while current_issue <= end_issue:
57-
logger.info(f"""Running issue {current_issue.strftime("%Y-%m-%d")}""")
60+
logger.info("Running issue", issue_date=current_issue.strftime("%Y-%m-%d"))
5861

5962
params["patch"]["current_issue"] = current_issue.strftime("%Y-%m-%d")
6063

claims_hosp/delphi_claims_hosp/run.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from .backfill import (store_backfill_file, merge_backfill_file)
2424

2525

26-
def run_module(params):
26+
def run_module(params, logger=None):
2727
"""
2828
Generate updated claims-based hospitalization indicator values.
2929
@@ -54,19 +54,24 @@ def run_module(params):
5454
adjustments (False).
5555
"""
5656
start_time = time.time()
57-
logger = get_structured_logger(
58-
__name__, filename=params["common"].get("log_filename"),
59-
log_exceptions=params["common"].get("log_exceptions", True))
57+
issue_date_str = params.get("patch", {}).get("current_issue", None)
58+
issue_date = datetime.strptime(issue_date_str, "%Y-%m-%d")
59+
if not logger:
60+
logger = get_structured_logger(
61+
__name__,
62+
filename=params["common"].get("log_filename"),
63+
log_exceptions=params["common"].get("log_exceptions", True),
64+
)
6065

6166
# pull latest data
6267
download(params["indicator"]["ftp_credentials"],
63-
params["indicator"]["input_dir"], logger)
68+
params["indicator"]["input_dir"], logger, issue_date=issue_date)
6469

6570
# aggregate data
6671
modify_and_write(params["indicator"]["input_dir"], logger)
6772

6873
# find the latest files (these have timestamps)
69-
claims_file = get_latest_filename(params["indicator"]["input_dir"], logger)
74+
claims_file = get_latest_filename(params["indicator"]["input_dir"], logger, issue_date=issue_date)
7075

7176
# handle range of estimates to produce
7277
# filename expected to have format: EDI_AGG_INPATIENT_DDMMYYYY_HHMM{timezone}.csv.gz

0 commit comments

Comments
 (0)