12
12
import numpy as np
13
13
import pandas as pd
14
14
15
+ from delphi_utils import read_params
16
+ from delphi_epidata import Epidata
17
+
15
18
from .api_config import APIConfig
16
19
from .covidnet import CovidNet
17
20
from .geo_maps import GeoMaps
18
21
22
+
23
+ SIGNALS = ["covidnet" ]
24
+
25
+
19
26
def write_to_csv (data : pd .DataFrame , out_name : str , output_path : str ):
20
27
"""
21
28
Write sensor values to csv.
@@ -72,14 +79,12 @@ def update_sensor(
72
79
right_on = ["year" , "weeknumber" ])
73
80
74
81
# Select relevant columns and standardize naming
75
- hosp_df = hosp_df .loc [:, APIConfig .HOSP_RENAME_COLS .keys ()]\
82
+ hosp_df = hosp_df .loc [:, APIConfig .HOSP_RENAME_COLS .keys ()] \
76
83
.rename (columns = APIConfig .HOSP_RENAME_COLS )
77
84
78
85
# Restrict to start and end date
79
86
hosp_df = hosp_df [
80
- (hosp_df ["date" ] >= start_date ) & (
81
- hosp_df ["date" ] < end_date )
82
- ]
87
+ (hosp_df ["date" ] >= start_date ) & (hosp_df ["date" ] < end_date )]
83
88
84
89
# Set state id to two-letter abbreviation
85
90
geo_map = GeoMaps (static_path )
@@ -93,7 +98,64 @@ def update_sensor(
93
98
hosp_df ["sample_size" ] = np .nan
94
99
95
100
# Write results
96
- out_name = "wip_covidnet"
97
- write_to_csv (hosp_df , out_name , output_path )
101
+ signals = add_prefix (SIGNALS , wip_signal = read_params ()["wip_signal" ], prefix = "wip_" )
102
+ for signal in signals :
103
+ write_to_csv (hosp_df , signal , output_path )
98
104
99
105
return hosp_df
106
+
107
+
108
+ def add_prefix (signal_names , wip_signal , prefix : str ):
109
+ """Adds prefix to signal if there is a WIP signal
110
+ Parameters
111
+ ----------
112
+ signal_names: List[str]
113
+ Names of signals to be exported
114
+ prefix : 'wip_'
115
+ prefix for new/non public signals
116
+ wip_signal : List[str] or bool
117
+ Either takes a list of wip signals: [], OR
118
+ incorporated all signals in the registry: True OR
119
+ no signals: False
120
+ Returns
121
+ -------
122
+ List of signal names
123
+ wip/non wip signals for further computation
124
+ """
125
+
126
+ if wip_signal in ("" , False ):
127
+ return signal_names
128
+ elif wip_signal and isinstance (wip_signal , bool ):
129
+ return [
130
+ (prefix + signal ) if public_signal (signal )
131
+ else signal
132
+ for signal in signal_names
133
+ ]
134
+ elif isinstance (wip_signal , list ):
135
+ for signal in wip_signal :
136
+ if public_signal (signal ):
137
+ signal_names .append (prefix + signal )
138
+ signal_names .remove (signal )
139
+ return signal_names
140
+ else :
141
+ raise ValueError ("Supply True | False or '' or [] | list()" )
142
+
143
+
144
+ def public_signal (signal_ ):
145
+ """Checks if the signal name is already public using Epidata
146
+ Parameters
147
+ ----------
148
+ signal_ : str
149
+ Name of the signal
150
+ Returns
151
+ -------
152
+ bool
153
+ True if the signal is not present
154
+ False if the signal is present
155
+ """
156
+ epidata_df = Epidata .covidcast_meta ()
157
+ for index in range (len (epidata_df ['epidata' ])):
158
+ if 'signal' in epidata_df ['epidata' ][index ]:
159
+ if epidata_df ['epidata' ][index ]['signal' ] == signal_ :
160
+ return False
161
+ return True
0 commit comments