17
17
from .api_config import APIConfig
18
18
19
19
class CovidNet :
20
- """
21
- Methods for downloading and loading COVID-NET data
22
- """
20
+ """Methods for downloading and loading COVID-NET data."""
23
21
24
22
@staticmethod
25
23
def download_mappings (
26
24
url : str = APIConfig .INIT_URL ,
27
25
outfile : str = "./init.json" ):
28
26
"""
29
- Downloads the JSON file with all mappings (age, mmwr, catchments etc.) to disk
27
+ Download the JSON file with all mappings (age, mmwr, catchments etc.) to disk.
30
28
31
29
Args:
32
30
url: The API URL to GET from
33
31
outfile: The output JSON file to write to
34
32
"""
35
-
36
33
params = {"appVersion" : "Public" }
37
34
data = requests .get (url , params ).json ()
38
35
with open (outfile , "w" ) as f_json :
@@ -41,7 +38,8 @@ def download_mappings(
41
38
@staticmethod
42
39
def read_mappings (infile : str ) -> Tuple [pd .DataFrame , pd .DataFrame , pd .DataFrame ]:
43
40
"""
44
- Reads the mappings JSON file from disk to produce formatted
41
+ Read the mappings JSON file from disk to produce formatted.
42
+
45
43
pd.DataFrame for relevant mappings
46
44
47
45
Args:
@@ -52,7 +50,6 @@ def read_mappings(infile: str) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame
52
50
mmwr_info: Date-related mappings
53
51
catchment_info: Geography-related mappings
54
52
"""
55
-
56
53
with open (infile , "r" ) as f_json :
57
54
data = json .load (f_json )
58
55
@@ -76,7 +73,8 @@ def download_hosp_data(
76
73
outfile : str ,
77
74
url : str = APIConfig .HOSP_URL ):
78
75
"""
79
- Downloads hospitalization data to disk for a particular network or state
76
+ Download hospitalization data to disk for a particular network or state.
77
+
80
78
Refer to catchment_info for network & catchment ID mappings
81
79
Refer to age_info for age-group mappings
82
80
Seasons are enumerated in original mappings JSON file
@@ -89,7 +87,6 @@ def download_hosp_data(
89
87
outfile: JSON file to write the results to
90
88
url: The API URL to POST to for downloading hospitalization data
91
89
"""
92
-
93
90
download_params = {
94
91
"AppVersion" : "Public" ,
95
92
"networkid" : network_id ,
@@ -108,7 +105,7 @@ def download_all_hosp_data(
108
105
mappings_file : str , cache_path : str , parallel : bool = False
109
106
) -> List [str ]:
110
107
"""
111
- Downloads hospitalization data for all states listed in the mappings JSON file to disk.
108
+ Download hospitalization data for all states listed in the mappings JSON file to disk.
112
109
113
110
Args:
114
111
mappings_file: Mappings JSON file
@@ -118,7 +115,6 @@ def download_all_hosp_data(
118
115
Returns:
119
116
List of all downloaded JSON filenames (including the cache_path)
120
117
"""
121
-
122
118
catchment_info , _ , age_info = CovidNet .read_mappings (mappings_file )
123
119
124
120
# By state
@@ -159,15 +155,14 @@ def download_all_hosp_data(
159
155
@staticmethod
160
156
def read_all_hosp_data (state_files : List [str ]) -> pd .DataFrame :
161
157
"""
162
- Read and combine hospitalization JSON files for each state into a pd.DataFrame
158
+ Read and combine hospitalization JSON files for each state into a pd.DataFrame.
163
159
164
160
Args:
165
161
state_files: List of hospitalization JSON files for each state to read from disk
166
162
167
163
Returns:
168
164
Single pd.DataFrame with all the hospitalization data combined
169
165
"""
170
-
171
166
dfs = []
172
167
for state_file in state_files :
173
168
# Read json
0 commit comments