-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signal Documentation Coverage Endpoint (#1584)
new `geo_coverage` endpoint with backing table and views, plus a utility to compute the table contents, as well as tests --------- Co-authored-by: Amaris Sim <[email protected]> Co-authored-by: george <[email protected]>
- Loading branch information
1 parent
828e72a
commit 5863680
Showing
7 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
integrations/acquisition/covidcast/test_coverage_crossref_update.py
This file contains 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,93 @@ | ||
"""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, CovidcastTestRow | ||
|
||
# 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): | ||
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._insert_rows([ | ||
CovidcastTestRow.make_default_row(geo_type="state", geo_value="pa"), | ||
CovidcastTestRow.make_default_row(geo_type="state", geo_value="ny"), | ||
CovidcastTestRow.make_default_row(geo_type="state", geo_value="ny", signal="sig2"), | ||
]) | ||
|
||
results = self._make_request(params = {'geo': 'state:*'}) | ||
|
||
# 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(params = {'geo': 'state:*'}) | ||
|
||
# make sure the data was actually served | ||
self.assertEqual(results, { | ||
'result': 1, | ||
'epidata': [{'signal': 'sig', 'source': 'src'}, {'signal': 'sig2', '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', | ||
}) | ||
|
||
results = self._make_request(params = {'geo': 'state:ny'}) | ||
|
||
# make sure the data was actually served | ||
self.assertEqual(results, { | ||
'result': 1, | ||
'epidata': [{'signal': 'sig', 'source': 'src'}, {'signal': 'sig2', 'source': 'src'}], | ||
'message': 'success', | ||
}) | ||
|
This file contains 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 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 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 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,33 @@ | ||
"""Updates the table for the `coverage_crossref` endpoint.""" | ||
|
||
import time | ||
|
||
from delphi.epidata.acquisition.covidcast.database import Database | ||
from delphi_utils import get_structured_logger | ||
|
||
|
||
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() | ||
finally: | ||
# clean up in success and in failure | ||
database.disconnect(True) | ||
|
||
logger.info(f"coverage_crossref returned: {coverage}") | ||
|
||
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 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 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