18
18
from .load_data import load_combined_data , load_cli_data
19
19
from .update_sensor import CHCSensorUpdator
20
20
21
+ def retrieve_files (params , filedate ):
22
+ """Return filenames of relevant files, downloading them if necessary
23
+ """
24
+ if params ["input_denom_file" ] is None :
21
25
22
- def run_module (): # pylint: disable=too-many-branches,too-many-statements
26
+ ## download recent files from FTP server
27
+ logging .info ("downloading recent files through SFTP" )
28
+ if "covid" in params ["types" ]:
29
+ download_covid (params ["cache_dir" ], params ["ftp_conn" ])
30
+ if "cli" in params ["types" ]:
31
+ download_cli (params ["cache_dir" ], params ["ftp_conn" ])
32
+
33
+ denom_file = "%s/%s_All_Outpatients_By_County.dat.gz" % (params ["cache_dir" ],filedate )
34
+ covid_file = "%s/%s_Covid_Outpatients_By_County.dat.gz" % (params ["cache_dir" ],filedate )
35
+ flu_file = "%s/%s_Flu_Patient_Count_By_County.dat.gz" % (params ["cache_dir" ],filedate )
36
+ mixed_file = "%s/%s_Mixed_Patient_Count_By_County.dat.gz" % (params ["cache_dir" ],filedate )
37
+ flu_like_file = "%s/%s_Flu_Like_Patient_Count_By_County.dat.gz" % (params ["cache_dir" ],filedate )
38
+ covid_like_file = "%s/%s_Covid_Like_Patient_Count_By_County.dat.gz" % (params ["cache_dir" ],filedate )
39
+ else :
40
+ denom_file = params ["input_denom_file" ]
41
+ covid_file = params ["input_covid_file" ]
42
+ flu_file = params ["input_flu_file" ]
43
+ mixed_file = params ["input_mixed_file" ]
44
+ flu_like_file = params ["input_flu_like_file" ]
45
+ covid_like_file = params ["input_covid_like_file" ]
46
+
47
+ file_dict = {"denom" : denom_file }
48
+ if "covid" in params ["types" ]:
49
+ file_dict ["covid" ] = covid_file
50
+ if "cli" in params ["types" ]:
51
+ file_dict ["flu" ] = flu_file
52
+ file_dict ["mixed" ] = mixed_file
53
+ file_dict ["flu_like" ] = flu_like_file
54
+ file_dict ["covid_like" ] = covid_like_file
55
+ return file_dict
56
+
57
+
58
+ def make_asserts (params ):
59
+ """Assert that for each type, filenames are either all present or all absent
60
+ """
61
+ if "covid" in params ["types" ]:
62
+ assert (params ["input_denom_file" ] is None ) == (params ["input_covid_file" ] is None ), \
63
+ "exactly one of denom and covid files are provided"
64
+ if "cli" in params ["types" ]:
65
+ if params ["input_denom_file" ] is None :
66
+ assert params ["input_flu_file" ] is None and \
67
+ params ["input_mixed_file" ] is None and \
68
+ params ["input_flu_like_file" ] is None and \
69
+ params ["input_covid_like_file" ] is None ,\
70
+ "files must be all present or all absent"
71
+ else :
72
+ assert params ["input_flu_file" ] is not None and \
73
+ params ["input_mixed_file" ] is not None and \
74
+ params ["input_flu_like_file" ] is not None and \
75
+ params ["input_covid_like_file" ] is not None ,\
76
+ "files must be all present or all absent"
77
+
78
+
79
+ def run_module ():
23
80
"""Run the delphi_changehc module.
24
81
"""
25
82
26
83
params = read_params ()
27
84
28
85
logging .basicConfig (level = logging .DEBUG )
29
86
30
- # the filenames are expected to be in the format:
31
- # Denominator: "YYYYMMDD_All_Outpatients_By_County.dat.gz"
32
- # Numerator: "YYYYMMDD_Covid_Outpatients_By_County.dat.gz"
33
-
34
- assert (params ["input_denom_file" ] is None ) == (params ["input_covid_file" ] is None ), \
35
- "exactly one of denom and covid files are provided"
87
+ make_asserts (params )
36
88
37
89
if params ["drop_date" ] is None :
38
90
# files are dropped about 8pm the day after the issue date
@@ -42,28 +94,7 @@ def run_module(): # pylint: disable=too-many-branches,too-many-statements
42
94
dropdate_dt = datetime .strptime (params ["drop_date" ], "%Y-%m-%d" )
43
95
filedate = dropdate_dt .strftime ("%Y%m%d" )
44
96
45
- if params ["input_denom_file" ] is None :
46
-
47
- ## download recent files from FTP server
48
- logging .info ("downloading recent files through SFTP" )
49
- if "covid" in params ["types" ]:
50
- download_covid (params ["cache_dir" ], params ["ftp_conn" ])
51
- if "cli" in params ["types" ]:
52
- download_cli (params ["cache_dir" ], params ["ftp_conn" ])
53
-
54
- input_denom_file = "%s/%s_All_Outpatients_By_County.dat.gz" % (params ["cache_dir" ],filedate )
55
- input_covid_file = "%s/%s_Covid_Outpatients_By_County.dat.gz" % (params ["cache_dir" ],filedate )
56
- input_flu_file = "%s/%s_Flu_Patient_Count_By_County.dat.gz" % (params ["cache_dir" ],filedate )
57
- input_mixed_file = "%s/%s_Mixed_Patient_Count_By_County.dat.gz" % (params ["cache_dir" ],filedate )
58
- input_flu_like_file = "%s/%s_Flu_Like_Patient_Count_By_County.dat.gz" % (params ["cache_dir" ],filedate )
59
- input_covid_like_file = "%s/%s_Covid_Like_Patient_Count_By_County.dat.gz" % (params ["cache_dir" ],filedate )
60
- else :
61
- input_denom_file = params ["input_denom_file" ]
62
- input_covid_file = params ["input_covid_file" ]
63
- input_flu_file = params ["input_flu_file" ]
64
- input_mixed_file = params ["input_mixed_file" ]
65
- input_flu_like_file = params ["input_flu_like_file" ]
66
- input_covid_like_file = params ["input_covid_like_file" ]
97
+ file_dict = retrieve_files (params , filedate )
67
98
68
99
dropdate = str (dropdate_dt .date ())
69
100
@@ -114,11 +145,11 @@ def run_module(): # pylint: disable=too-many-branches,too-many-statements
114
145
params ["se" ]
115
146
)
116
147
if numtype == "covid" :
117
- data = load_combined_data (input_denom_file ,
118
- input_covid_file ,dropdate_dt ,"fips" )
148
+ data = load_combined_data (file_dict [ "denom" ] ,
149
+ file_dict [ "covid" ] ,dropdate_dt ,"fips" )
119
150
elif numtype == "cli" :
120
- data = load_cli_data (input_denom_file , input_flu_file , input_mixed_file ,
121
- input_flu_like_file , input_covid_like_file ,dropdate_dt ,"fips" )
151
+ data = load_cli_data (file_dict [ "denom" ], file_dict [ "flu" ], file_dict [ "mixed" ] ,
152
+ file_dict [ "flu_like" ], file_dict [ "covid_like" ] ,dropdate_dt ,"fips" )
122
153
su_inst .update_sensor (
123
154
data ,
124
155
params ["export_dir" ]
0 commit comments