Skip to content

Commit 14b4e6f

Browse files
committed
various bug fixes
1 parent ab4b542 commit 14b4e6f

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

nssp/delphi_nssp/patch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
import sys
4343
from datetime import datetime, timedelta
44-
from os import listdir, makedirs, path
44+
from os import listdir, makedirs, path, getcwd
4545
from shutil import rmtree
4646

4747
from delphi_utils import get_structured_logger, read_params
@@ -123,15 +123,15 @@ def patch():
123123

124124
current_issue = start_issue
125125
while current_issue <= end_issue:
126-
logger.info("patching issue", issue_date=current_issue.strftime("%Y-%m-%d"))
126+
logger.info("patching issue", issue_date=current_issue.strftime("%Y%m%d"))
127127

128-
current_issue_source_csv = f"""{source_dir}/{current_issue.strftime("%Y-%m-%d")}.csv"""
128+
current_issue_source_csv = f"""{source_dir}/{current_issue.strftime("%Y%m%d")}.csv.gz"""
129129
if not path.isfile(current_issue_source_csv):
130130
logger.info("No source data at this path", current_issue_source_csv=current_issue_source_csv)
131131
current_issue += timedelta(days=1)
132132
continue
133133

134-
params["patch"]["current_issue"] = current_issue.strftime("%Y-%m-%d")
134+
params["patch"]["current_issue"] = current_issue.strftime("%Y%m%d")
135135

136136
# current_issue_date can be different from params["patch"]["current_issue"]
137137
# due to weekly cadence of nssp data. For weekly sources, issue dates in our

nssp/delphi_nssp/pull.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def get_source_data(params, logger):
5656

5757
# Generate file names of source files to download
5858
dates = pd.date_range(start=params["patch"]["start_issue"], end=params["patch"]["end_issue"])
59-
primary_source_files = [f"{date.strftime("%Y%m%d")}.csv.gz" for date in dates]
59+
primary_source_files = [f"{date.strftime('%Y%m%d')}.csv.gz" for date in dates]
6060
secondary_source_files = [f"{date.strftime('%Y%m%d')}_secondary.csv.gz" for date in dates]
6161
remote_source_files = primary_source_files + secondary_source_files
6262

@@ -79,6 +79,7 @@ def get_source_data(params, logger):
7979
logger.warning(
8080
"Source backup for this date does not exist on the remote server.", missing_filename=remote_file_name
8181
)
82+
continue
8283
sftp.get(remote_file_name, local_file_path, callback=callback_for_filename)
8384
logger.info("Transfer finished", remote_file_name=remote_file_name, local_file_path=local_file_path)
8485
num_files_transferred += 1
@@ -136,7 +137,7 @@ def pull_with_socrata_api(socrata_token: str, dataset_id: str):
136137

137138

138139
def pull_nssp_data(socrata_token: str, backup_dir: str, custom_run: bool, issue_date: Optional[str] = None, logger: Optional[logging.Logger] = None):
139-
"""Pull the latest NSSP ER visits primary dataset.
140+
"""Pull the NSSP ER visits primary dataset.
140141
141142
https://data.cdc.gov/Public-Health-Surveillance/NSSP-Emergency-Department-Visit-Trajectories-by-St/rdmq-nq56/data_preview
142143
@@ -213,7 +214,7 @@ def secondary_pull_nssp_data(
213214
elif custom_run and logger.name == "delphi_nssp.patch":
214215
if issue_date is None:
215216
raise ValueError("Issue date is required for patching")
216-
source_filename = f"{backup_dir}/secondary_{issue_date}.csv.gz"
217+
source_filename = f"{backup_dir}/{issue_date}_secondary.csv.gz"
217218
df_ervisits = pd.read_csv(source_filename)
218219
logger.info(
219220
"Number of records grabbed",

nssp/delphi_nssp/run.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ def run_module(params, logger=None):
8282
logger.warning("custom_run flag is on despite direct indicator run call. Normal indicator run continues.")
8383
custom_run = False
8484
export_dir = params["common"]["export_dir"]
85-
backup_dir = params["common"]["backup_dir"]
85+
if custom_run and logger.name == "delphi_nssp.patch":
86+
backup_dir = params["patch"]["source_dir"]
87+
else:
88+
backup_dir = params["common"]["backup_dir"]
8689
custom_run = params["common"].get("custom_run", False)
8790
issue_date = params.get("patch", {}).get("current_issue", None)
8891
socrata_token = params["indicator"]["socrata_token"]
@@ -92,7 +95,7 @@ def run_module(params, logger=None):
9295
## build the base version of the signal at the most detailed geo level you can get.
9396
## compute stuff here or farm out to another function or file
9497

95-
98+
# breakpoint()
9699
df_pull = pull_nssp_data(socrata_token, backup_dir, custom_run=custom_run, issue_date=issue_date, logger=logger)
97100

98101
## aggregate

0 commit comments

Comments
 (0)