Skip to content

Commit d3270c9

Browse files
committed
signal naming using wip_signal parameter
1 parent 3fffd54 commit d3270c9

File tree

4 files changed

+33181
-9
lines changed

4 files changed

+33181
-9
lines changed

cdc_covidnet/delphi_cdc_covidnet/update_sensor.py

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@
1212
import numpy as np
1313
import pandas as pd
1414

15+
from delphi_utils import read_params
16+
from delphi_epidata import Epidata
17+
1518
from .api_config import APIConfig
1619
from .covidnet import CovidNet
1720
from .geo_maps import GeoMaps
1821

22+
23+
SIGNALS = ["covidnet"]
24+
25+
1926
def write_to_csv(data: pd.DataFrame, out_name: str, output_path: str):
2027
"""
2128
Write sensor values to csv.
@@ -72,14 +79,12 @@ def update_sensor(
7279
right_on=["year", "weeknumber"])
7380

7481
# 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()] \
7683
.rename(columns=APIConfig.HOSP_RENAME_COLS)
7784

7885
# Restrict to start and end date
7986
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)]
8388

8489
# Set state id to two-letter abbreviation
8590
geo_map = GeoMaps(static_path)
@@ -93,7 +98,64 @@ def update_sensor(
9398
hosp_df["sample_size"] = np.nan
9499

95100
# 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)
98104

99105
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

cdc_covidnet/params.json.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"cache_dir": "./cache",
55
"start_date": "2020-03-07",
66
"end_date": "",
7-
"parallel": false
7+
"parallel": false,
8+
"wip_signal": ""
89
}

0 commit comments

Comments
 (0)