Skip to content

Commit fe3efab

Browse files
committed
changes in compliance with #205
1 parent cc92195 commit fe3efab

File tree

6 files changed

+54
-39
lines changed

6 files changed

+54
-39
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
Registry for signal names
3+
"""
4+
5+
6+
FULL_TIME = "full_time_work_prop"
7+
PART_TIME = "part_time_work_prop"
8+
COVIDNET = "covidnet"
9+
10+
SIGNALS = [
11+
FULL_TIME,
12+
PART_TIME,
13+
COVIDNET
14+
]

_template_python/delphi_NAME/handle_wip_signal.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Created: 2020-08-07
66
"""
77

8-
from delphi_epidata import Epidata
8+
import covidcast
99

1010

1111
def add_prefix(signal_names, wip_signal, prefix: str):
@@ -17,47 +17,46 @@ def add_prefix(signal_names, wip_signal, prefix: str):
1717
prefix : 'wip_'
1818
prefix for new/non public signals
1919
wip_signal : List[str] or bool
20-
Either takes a list of wip signals: [], OR
21-
incorporated all signals in the registry: True OR
22-
no signals: False
20+
a list of wip signals: [], OR
21+
all signals in the registry: True OR
22+
only signals that have never been published: False
2323
Returns
2424
-------
2525
List of signal names
2626
wip/non wip signals for further computation
2727
"""
28-
if wip_signal in ("", False):
29-
return signal_names
30-
elif wip_signal and isinstance(wip_signal, bool):
28+
29+
if wip_signal is True:
30+
return [prefix + signal for signal in signal_names]
31+
if isinstance(wip_signal, list):
32+
make_wip = set(wip_signal)
33+
return[
34+
prefix + signal if signal in make_wip else signal
35+
for signal in signal_names
36+
]
37+
if wip_signal in {False, ""}:
3138
return [
32-
(prefix + signal) if public_signal(signal)
33-
else signal
39+
signal if public_signal(signal)
40+
else prefix + signal
3441
for signal in signal_names
3542
]
36-
elif isinstance(wip_signal, list):
37-
for signal in wip_signal:
38-
if public_signal(signal):
39-
signal_names.append(prefix + signal)
40-
signal_names.remove(signal)
41-
return signal_names
42-
else:
43-
raise ValueError("Supply True | False or '' or [] | list()")
43+
raise ValueError("Supply True | False or '' or [] | list()")
4444

4545

4646
def public_signal(signal_):
47-
"""Checks if the signal name is already public using Epidata
47+
"""Checks if the signal name is already public using COVIDcast
4848
Parameters
4949
----------
5050
signal_ : str
5151
Name of the signal
5252
Returns
5353
-------
5454
bool
55-
True if the signal is not present
56-
False if the signal is present
55+
True if the signal is present
56+
False if the signal is not present
5757
"""
58-
epidata_df = Epidata.covidcast_meta()
59-
for index in range(len(epidata_df['epidata'])):
60-
if 'signal' in epidata_df['epidata'][index]:
61-
if epidata_df['epidata'][index]['signal'] == signal_:
62-
return False
63-
return True
58+
epidata_df = covidcast.metadata()
59+
for index in range(len(epidata_df)):
60+
if epidata_df['signal'][index] == signal_:
61+
return True
62+
return False

_template_python/delphi_NAME/run.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66
"""
77
from delphi_utils import read_params
88
from .handle_wip_signal import add_prefix
9+
from .constants import SIGNALS
910

1011
# Sample signals
11-
SIGNALS = ["full_time_work_prop",
12-
"covidnet",
13-
"part_time_work_prop",
14-
"completely_home_prop"
15-
]
16-
1712

1813
def run_module():
1914
"""

_template_python/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"pytest",
88
"pytest-cov",
99
"pylint",
10-
"delphi-utils"
10+
"delphi-utils",
11+
"covidcast"
1112
]
1213

1314
setup(
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"static_file_dir": "../static",
33
"export_dir": "./receiving",
4-
"cache_dir": "./cache"
4+
"cache_dir": "./cache",
5+
"wip_signal": ""
56
}

_template_python/tests/test_handle_wip_signal.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77

88

99
def test_handle_wip_signal():
10-
assert isinstance(wip_signal, (list, bool)) or wip_signal == "", "Supply True | False or "" or [] | list()"
11-
if isinstance(wip_signal, list):
12-
assert set(wip_signal).issubset(set(SIGNALS)), "signal in params don't belong in the registry"
13-
updated_signal_names = add_prefix(SIGNALS, wip_signal, prefix='wip_')
14-
assert (len(updated_signal_names) >= len(SIGNALS))
10+
signal_names = add_prefix(SIGNALS, True, prefix="wip_")
11+
assert all(s.startswith("wip_") for s in signal_names)
12+
# Test wip_signal = list
13+
signal_names = add_prefix(SIGNALS, [SIGNALS[0]], prefix="wip_")
14+
assert signal_names[0].startswith("wip_")
15+
assert all(not s.startswith("wip_") for s in signal_names[1:])
16+
# Test wip_signal = False
17+
signal_names = add_prefix(["xyzzy", SIGNALS[0]], False, prefix="wip_")
18+
assert signal_names[0].startswith("wip_")
19+
assert all(not s.startswith("wip_") for s in signal_names[1:])
1520

1621

1722
class MyTestCase(unittest.TestCase):

0 commit comments

Comments
 (0)