1717from .api_config import APIConfig
1818
1919class CovidNet :
20- """
21- Methods for downloading and loading COVID-NET data
22- """
20+ """Methods for downloading and loading COVID-NET data."""
2321
2422 @staticmethod
2523 def download_mappings (
2624 url : str = APIConfig .INIT_URL ,
2725 outfile : str = "./init.json" ):
2826 """
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.
3028
3129 Args:
3230 url: The API URL to GET from
3331 outfile: The output JSON file to write to
3432 """
35-
3633 params = {"appVersion" : "Public" }
3734 data = requests .get (url , params ).json ()
3835 with open (outfile , "w" ) as f_json :
@@ -41,7 +38,8 @@ def download_mappings(
4138 @staticmethod
4239 def read_mappings (infile : str ) -> Tuple [pd .DataFrame , pd .DataFrame , pd .DataFrame ]:
4340 """
44- Reads the mappings JSON file from disk to produce formatted
41+ Read the mappings JSON file from disk to produce formatted.
42+
4543 pd.DataFrame for relevant mappings
4644
4745 Args:
@@ -52,7 +50,6 @@ def read_mappings(infile: str) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame
5250 mmwr_info: Date-related mappings
5351 catchment_info: Geography-related mappings
5452 """
55-
5653 with open (infile , "r" ) as f_json :
5754 data = json .load (f_json )
5855
@@ -76,7 +73,8 @@ def download_hosp_data(
7673 outfile : str ,
7774 url : str = APIConfig .HOSP_URL ):
7875 """
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+
8078 Refer to catchment_info for network & catchment ID mappings
8179 Refer to age_info for age-group mappings
8280 Seasons are enumerated in original mappings JSON file
@@ -89,7 +87,6 @@ def download_hosp_data(
8987 outfile: JSON file to write the results to
9088 url: The API URL to POST to for downloading hospitalization data
9189 """
92-
9390 download_params = {
9491 "AppVersion" : "Public" ,
9592 "networkid" : network_id ,
@@ -108,7 +105,7 @@ def download_all_hosp_data(
108105 mappings_file : str , cache_path : str , parallel : bool = False
109106 ) -> List [str ]:
110107 """
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.
112109
113110 Args:
114111 mappings_file: Mappings JSON file
@@ -118,7 +115,6 @@ def download_all_hosp_data(
118115 Returns:
119116 List of all downloaded JSON filenames (including the cache_path)
120117 """
121-
122118 catchment_info , _ , age_info = CovidNet .read_mappings (mappings_file )
123119
124120 # By state
@@ -159,15 +155,14 @@ def download_all_hosp_data(
159155 @staticmethod
160156 def read_all_hosp_data (state_files : List [str ]) -> pd .DataFrame :
161157 """
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.
163159
164160 Args:
165161 state_files: List of hospitalization JSON files for each state to read from disk
166162
167163 Returns:
168164 Single pd.DataFrame with all the hospitalization data combined
169165 """
170-
171166 dfs = []
172167 for state_file in state_files :
173168 # Read json
0 commit comments