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,8 +38,7 @@ 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
45
- pd.DataFrame for relevant mappings
41
+ Read the mappings JSON file from disk to produce formatted DataFrames for relevant mappings.
46
42
47
43
Args:
48
44
infile: Mappings JSON file
@@ -52,7 +48,6 @@ def read_mappings(infile: str) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame
52
48
mmwr_info: Date-related mappings
53
49
catchment_info: Geography-related mappings
54
50
"""
55
-
56
51
with open (infile , "r" ) as f_json :
57
52
data = json .load (f_json )
58
53
@@ -76,7 +71,8 @@ def download_hosp_data(
76
71
outfile : str ,
77
72
url : str = APIConfig .HOSP_URL ):
78
73
"""
79
- Downloads hospitalization data to disk for a particular network or state
74
+ Download hospitalization data to disk for a particular network or state.
75
+
80
76
Refer to catchment_info for network & catchment ID mappings
81
77
Refer to age_info for age-group mappings
82
78
Seasons are enumerated in original mappings JSON file
@@ -89,7 +85,6 @@ def download_hosp_data(
89
85
outfile: JSON file to write the results to
90
86
url: The API URL to POST to for downloading hospitalization data
91
87
"""
92
-
93
88
download_params = {
94
89
"AppVersion" : "Public" ,
95
90
"networkid" : network_id ,
@@ -108,7 +103,7 @@ def download_all_hosp_data(
108
103
mappings_file : str , cache_path : str , parallel : bool = False
109
104
) -> List [str ]:
110
105
"""
111
- Downloads hospitalization data for all states listed in the mappings JSON file to disk.
106
+ Download hospitalization data for all states listed in the mappings JSON file to disk.
112
107
113
108
Args:
114
109
mappings_file: Mappings JSON file
@@ -118,7 +113,6 @@ def download_all_hosp_data(
118
113
Returns:
119
114
List of all downloaded JSON filenames (including the cache_path)
120
115
"""
121
-
122
116
catchment_info , _ , age_info = CovidNet .read_mappings (mappings_file )
123
117
124
118
# By state
@@ -159,15 +153,14 @@ def download_all_hosp_data(
159
153
@staticmethod
160
154
def read_all_hosp_data (state_files : List [str ]) -> pd .DataFrame :
161
155
"""
162
- Read and combine hospitalization JSON files for each state into a pd.DataFrame
156
+ Read and combine hospitalization JSON files for each state into a pd.DataFrame.
163
157
164
158
Args:
165
159
state_files: List of hospitalization JSON files for each state to read from disk
166
160
167
161
Returns:
168
162
Single pd.DataFrame with all the hospitalization data combined
169
163
"""
170
-
171
164
dfs = []
172
165
for state_file in state_files :
173
166
# Read json
0 commit comments