-
Notifications
You must be signed in to change notification settings - Fork 16
handling wip signal in python template #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cc92195
handling wip signal in python template
vishakha1812 fe3efab
changes in compliance with #205
vishakha1812 7d9a59a
default prefix value
vishakha1812 9e637c9
Apply suggestions from code review
vishakha1812 c2643e5
Removed unnecessary comment
vishakha1812 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| """ | ||
| Registry for signal names | ||
| """ | ||
|
|
||
|
|
||
| ## example: | ||
| # FULL_TIME = "full_time_work_prop" | ||
| # PART_TIME = "part_time_work_prop" | ||
| # COVIDNET = "covidnet" | ||
| # | ||
| # SIGNALS = [ | ||
| # FULL_TIME, | ||
| # PART_TIME, | ||
| # COVIDNET | ||
| # ] | ||
|
|
||
| SIGNALS = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| """ | ||
| Handle signal names. | ||
|
|
||
| Author: Vishakha | ||
| Created: 2020-08-07 | ||
| """ | ||
|
|
||
| import covidcast | ||
|
|
||
|
|
||
| def add_prefix(signal_names, wip_signal, prefix="wip_"): | ||
| """Adds prefix to signal if there is a WIP signal | ||
| Parameters | ||
| ---------- | ||
| signal_names: List[str] | ||
| Names of signals to be exported | ||
| prefix : 'wip_' | ||
| prefix for new/non public signals | ||
| wip_signal : List[str] or bool | ||
| a list of wip signals: [], OR | ||
| all signals in the registry: True OR | ||
| only signals that have never been published: False | ||
| Returns | ||
| ------- | ||
| List of signal names | ||
| wip/non wip signals for further computation | ||
| """ | ||
|
|
||
| if wip_signal is True: | ||
| return [prefix + signal for signal in signal_names] | ||
| if isinstance(wip_signal, list): | ||
| make_wip = set(wip_signal) | ||
| return[ | ||
| prefix + signal if signal in make_wip else signal | ||
| for signal in signal_names | ||
| ] | ||
| if wip_signal in {False, ""}: | ||
| return [ | ||
| signal if public_signal(signal) | ||
| else prefix + signal | ||
| for signal in signal_names | ||
| ] | ||
| raise ValueError("Supply True | False or '' or [] | list()") | ||
|
|
||
|
|
||
| def public_signal(signal_): | ||
| """Checks if the signal name is already public using COVIDcast | ||
| Parameters | ||
| ---------- | ||
| signal_ : str | ||
| Name of the signal | ||
| Returns | ||
| ------- | ||
| bool | ||
| True if the signal is present | ||
| False if the signal is not present | ||
| """ | ||
| epidata_df = covidcast.metadata() | ||
| for index in range(len(epidata_df)): | ||
| if epidata_df['signal'][index] == signal_: | ||
| return True | ||
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| { | ||
| "static_file_dir": "./static", | ||
| "export_dir": "./receiving", | ||
| "cache_dir": "./cache" | ||
| "cache_dir": "./cache", | ||
| "wip_signal": "" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,8 @@ | |
| "pytest", | ||
| "pytest-cov", | ||
| "pylint", | ||
| "delphi-utils" | ||
| "delphi-utils", | ||
| "covidcast" | ||
| ] | ||
|
|
||
| setup( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| { | ||
| "static_file_dir": "../static", | ||
| "export_dir": "./receiving", | ||
| "cache_dir": "./cache" | ||
| "cache_dir": "./cache", | ||
| "wip_signal": "" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import unittest | ||
| from delphi_NAME.handle_wip_signal import add_prefix | ||
| from delphi_NAME.run import SIGNALS | ||
| from delphi_utils import read_params | ||
|
|
||
|
|
||
|
|
||
| def test_handle_wip_signal(): | ||
| # Test wip_signal = True (all signals should receive prefix) | ||
| signal_names = add_prefix(SIGNALS, True, prefix="wip_") | ||
| assert all(s.startswith("wip_") for s in signal_names) | ||
| # Test wip_signal = list (only listed signals should receive prefix) | ||
| signal_names = add_prefix(SIGNALS, [SIGNALS[0]], prefix="wip_") | ||
| assert signal_names[0].startswith("wip_") | ||
| assert all(not s.startswith("wip_") for s in signal_names[1:]) | ||
| # Test wip_signal = False (only unpublished signals should receive prefix) | ||
| signal_names = add_prefix(["xyzzy", SIGNALS[0]], False, prefix="wip_") | ||
| assert signal_names[0].startswith("wip_") | ||
| assert all(not s.startswith("wip_") for s in signal_names[1:]) | ||
|
|
||
|
|
||
| class MyTestCase(unittest.TestCase): | ||
| pass | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.