-
Notifications
You must be signed in to change notification settings - Fork 67
Signal Documentation Coverage Endpoint #1584
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 24 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
b0934b5
first pass at coverage endpoint
nolangormley 1a06e2e
added SQL to schemas
nolangormley 55d13cb
added load table and function to recompute data
nolangormley 16fe7b7
modified endpoint to use geo_sets, allowing multiple geos in filter
nolangormley 85a972e
removed indexes from load table, fixed index declaration on main table
nolangormley c2baf02
added CLI and tests
nolangormley 233ccd2
fixed sonar suggestions
nolangormley 65c040a
more sonar issues
nolangormley 3c404b2
ignore sonar test
aysim319 a5555a5
removed unessesary index rebuild, fixed indexes in ddl sql file
nolangormley 31200bd
Merge branch 'sig_doc_coverage' of github.com:cmu-delphi/delphi-epida…
nolangormley 26c6450
updated SQL to use transaction instead of load table
nolangormley 1f26061
updated integration test, removed SQL alias
nolangormley a0f631f
adding alias back in
nolangormley 8da0326
Update src/maintenance/coverage_crossref_updater.py
nolangormley 8a46b84
Update src/acquisition/covidcast/database.py
nolangormley f0e60f0
Update src/acquisition/covidcast/database.py
nolangormley d9f9260
Update src/acquisition/covidcast/database.py
nolangormley 38b9e7b
Update src/maintenance/coverage_crossref_updater.py
nolangormley 59d0ec8
Update integrations/acquisition/covidcast/test_coverage_crossref_upda…
nolangormley 0bf61b7
Update src/server/endpoints/covidcast.py
nolangormley 8a59022
Update integrations/acquisition/covidcast/test_coverage_crossref_upda…
nolangormley d8c5efa
Merge branch 'sig_doc_coverage' of github.com:cmu-delphi/delphi-epida…
nolangormley a458730
added test coverage and fixed groupby
nolangormley 62b7475
Update src/maintenance/coverage_crossref_updater.py
nolangormley 269c108
Update src/maintenance/coverage_crossref_updater.py
nolangormley b0be91f
Update src/maintenance/coverage_crossref_updater.py
nolangormley 3b137d8
Update integrations/acquisition/covidcast/test_coverage_crossref_upda…
nolangormley e50624c
Merge branch 'sig_doc_coverage' of github.com:cmu-delphi/delphi-epida…
nolangormley 1604845
added some test cases
nolangormley 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
105 changes: 105 additions & 0 deletions
105
integrations/acquisition/covidcast/test_coverage_crossref_update.py
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,105 @@ | ||
"""Integration tests for the covidcast `geo_coverage` endpoint.""" | ||
|
||
# standard library | ||
import json | ||
import unittest | ||
|
||
# third party | ||
import mysql.connector | ||
import requests | ||
|
||
# first party | ||
from delphi_utils import Nans | ||
from delphi.epidata.client.delphi_epidata import Epidata | ||
import delphi.operations.secrets as secrets | ||
import delphi.epidata.acquisition.covidcast.database as live | ||
from delphi.epidata.maintenance.coverage_crossref_updater import main | ||
from delphi.epidata.acquisition.covidcast.test_utils import CovidcastBase | ||
|
||
# use the local instance of the Epidata API | ||
BASE_URL = 'http://delphi_web_epidata/epidata' # NOSONAR | ||
|
||
|
||
class CoverageCrossrefTests(CovidcastBase): | ||
"""Tests coverage crossref updater.""" | ||
|
||
def localSetUp(self): | ||
"""Perform per-test setup.""" | ||
self._db._cursor.execute('TRUNCATE TABLE `coverage_crossref`') | ||
|
||
@staticmethod | ||
def _make_request(params=None): | ||
if params is None: | ||
params = {'geo': 'state:*'} | ||
response = requests.get(f"{Epidata.BASE_URL}/covidcast/geo_coverage", params=params, auth=Epidata.auth) | ||
response.raise_for_status() | ||
return response.json() | ||
|
||
def test_caching(self): | ||
"""Populate, query, cache, query, and verify the cache.""" | ||
|
||
# insert dummy data | ||
self._db._cursor.execute(''' | ||
INSERT INTO `signal_dim` (`signal_key_id`, `source`, `signal`) | ||
VALUES | ||
(42, 'src', 'sig'); | ||
''') | ||
self._db._cursor.execute(''' | ||
INSERT INTO `geo_dim` (`geo_key_id`, `geo_type`, `geo_value`) | ||
VALUES | ||
(96, 'state', 'pa'), | ||
(97, 'state', 'wa'); | ||
''') | ||
self._db._cursor.execute(f''' | ||
INSERT INTO | ||
`epimetric_latest` (`epimetric_id`, `signal_key_id`, `geo_key_id`, `time_type`, | ||
`time_value`, `value_updated_timestamp`, | ||
`value`, `stderr`, `sample_size`, | ||
`issue`, `lag`, `missing_value`, | ||
`missing_stderr`,`missing_sample_size`) | ||
VALUES | ||
(15, 42, 96, 'day', 20200422, | ||
123, 1, 2, 3, 20200422, 0, {Nans.NOT_MISSING}, {Nans.NOT_MISSING}, {Nans.NOT_MISSING}), | ||
(16, 42, 97, 'day', 20200422, | ||
789, 1, 2, 3, 20200423, 1, {Nans.NOT_MISSING}, {Nans.NOT_MISSING}, {Nans.NOT_MISSING}) | ||
''') | ||
self._db.commit() | ||
nolangormley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
results = self._make_request() | ||
|
||
# make sure the tables are empty | ||
self.assertEqual(results, { | ||
'result': -2, | ||
'epidata': [], | ||
'message': 'no results', | ||
}) | ||
|
||
# update the coverage crossref table | ||
main() | ||
|
||
results = self._make_request() | ||
melange396 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# make sure the data was actually served | ||
self.assertEqual(results, { | ||
'result': 1, | ||
'epidata': [{'signal': 'sig', 'source': 'src'}], | ||
'message': 'success', | ||
}) | ||
|
||
results = self._make_request(params = {'geo': 'hrr:*'}) | ||
|
||
# make sure the tables are empty | ||
self.assertEqual(results, { | ||
'result': -2, | ||
'epidata': [], | ||
'message': 'no results', | ||
}) | ||
|
||
results = self._make_request(params = {'geo': 'state:pa'}) | ||
|
||
# make sure the data was actually served | ||
self.assertEqual(results, { | ||
'result': 1, | ||
'epidata': [{'signal': 'sig', 'source': 'src'}], | ||
'message': 'success', | ||
}) |
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Updates the table for the `coverage_crossref` endpoint.""" | ||
|
||
# standard library | ||
import argparse | ||
import sys | ||
import time | ||
|
||
# first party | ||
from delphi.epidata.acquisition.covidcast.database import Database | ||
from delphi_utils import get_structured_logger | ||
from delphi.epidata.client.delphi_epidata import Epidata | ||
nolangormley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def main(): | ||
"""Updates the table for the `coverage_crossref`.""" | ||
|
||
logger = get_structured_logger("coverage_crossref_updater") | ||
start_time = time.time() | ||
database = Database() | ||
database.connect() | ||
|
||
# compute and update coverage_crossref | ||
try: | ||
coverage = database.compute_coverage_crossref() | ||
except: | ||
# clean up before failing | ||
database.disconnect(True) | ||
raise | ||
nolangormley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
result = ("success",1) | ||
if coverage==0: | ||
result = ("no results",-2) | ||
|
||
logger.info('coverage_crossref result: %s (code %d)' % result) | ||
|
||
nolangormley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
logger.info( | ||
"Generated and updated covidcast geo/signal coverage", | ||
total_runtime_in_seconds=round(time.time() - start_time, 2)) | ||
return True | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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
Oops, something went wrong.
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.