Skip to content

Commit ed577e8

Browse files
committed
Merge remote-tracking branch 'origin/main' into hhs-covidcast
2 parents b20cdc0 + 366cd36 commit ed577e8

File tree

7 files changed

+94
-16
lines changed

7 files changed

+94
-16
lines changed

docs/api/covidcast-signals/fb-survey.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,10 @@ also available. These have names beginning `smoothed_w`, such as
324324

325325
| Signal | Description | Survey Item |
326326
| --- | --- | --- |
327+
| `smoothed_covid_vaccinated_or_accept` | Estimated percentage of respondents who *either* have already received a COVID vaccine *or* would definitely or probably choose to get vaccinated, if a vaccine were offered to them today. <br/> **Earliest date available:** 2021-01-06 | V1 and V3 |
327328
| `smoothed_accept_covid_vaccine` | Estimated percentage of respondents who would definitely or probably choose to get vaccinated, if a COVID-19 vaccine were offered to them today. **Note:** Until January 6, 2021, all respondents answered this question; beginning on that date, only respondents who said they have not received a COVID vaccine are asked this question. <br/> **Earliest date available:** 2021-01-01 | V3 |
328329
| `smoothed_covid_vaccinated` | Estimated percentage of respondents who have already received a vaccine for COVID-19. **Note:** The Centers for Disease Control compiles data on vaccine administration across the United States. This signal may differ from CDC data because of survey biases and should not be treated as authoritative. However, the survey signal is not subject to the lags and reporting problems in official vaccination data. <br/> **Earliest date available:** 2021-01-06 | V1 |
330+
| `smoothed_worried_vaccine_side_effects` | Estimated percentage of respondents who are very or moderately concerned that they would "experience a side effect from a COVID-19 vaccination." (Asked of all respondents, including those who have already received one or more doses of a COVID-19 vaccine.) <br/> **Earliest date available:** 2021-01-12 | V9 |
329331
| `smoothed_vaccine_likely_friends` | Estimated percentage of respondents who would be more likely to get a COVID-19 vaccine if it were recommended to them by friends and family, among respondents who have not yet been vaccinated. <br/> **Earliest date available:** 2021-01-20 | V4 |
330332
| `smoothed_vaccine_likely_local_health` | Estimated percentage of respondents who would be more likely to get a COVID-19 vaccine if it were recommended to them by local health workers, among respondents who have not yet been vaccinated. <br/> **Earliest date available:** 2021-01-20 | V4 |
331333
| `smoothed_vaccine_likely_who` | Estimated percentage of respondents who would be more likely to get a COVID-19 vaccine if it were recommended to them by the World Health Organization, among respondents who have not yet been vaccinated. <br/> **Earliest date available:** 2021-01-20 | V4 |
@@ -335,9 +337,9 @@ also available. These have names beginning `smoothed_w`, such as
335337
These indicators are based on questions added in Wave 6 of the survey,
336338
introduced on December 19, 2020; however, Delphi only enabled item V1 beginning
337339
January 6, 2021. **Note:** As of January 2021, vaccination items on the survey
338-
are being revised in preparation for Wave 7. We may replace the signals above
339-
with new signals (with different names) if the underlying survey items change
340-
significantly.
340+
are being revised in preparation for later waves. We may replace the signals
341+
above with new signals (with different names) if the underlying survey items
342+
change significantly.
341343

342344
Weighted versions of these signals, using the [survey weighting described
343345
below](#survey-weighting) to be more representative of state demographics, are

integrations/acquisition/covidcast_nowcast/test_csv_uploading.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def test_uploading(self):
6868
# print full diff if something unexpected comes out
6969
self.maxDiff=None
7070

71-
receiving_dir = '/common/covidcast_nowcast/receiving/src/'
72-
success_dir = '/common/covidcast_nowcast/archive/successful/src/'
73-
failed_dir = '/common/covidcast_nowcast/archive/failed/src/'
71+
receiving_dir = '/common/covidcast_nowcast/receiving/issue_20200421/src/'
72+
success_dir = '/common/covidcast_nowcast/archive/successful/issue_20200421/src/'
73+
failed_dir = '/common/covidcast_nowcast/archive/failed/issue_20200421/src/'
7474
os.makedirs(receiving_dir, exist_ok=True)
7575

7676
# valid
@@ -125,7 +125,7 @@ def test_duplicate_row(self):
125125
# print full diff if something unexpected comes out
126126
self.maxDiff=None
127127

128-
receiving_dir = '/common/covidcast_nowcast/receiving/src/'
128+
receiving_dir = '/common/covidcast_nowcast/receiving/issue_20200425/src/'
129129
os.makedirs(receiving_dir, exist_ok=True)
130130

131131
with open(receiving_dir + '20200419_state_sig.csv', 'w') as f:
@@ -146,8 +146,8 @@ def test_duplicate_row(self):
146146
'time_value': 20200419,
147147
'geo_value': 'ca',
148148
'value': 2,
149-
'issue': 20200421,
150-
'lag': 2,
149+
'issue': 20200425,
150+
'lag': 6,
151151
'signal': 'sig',
152152
}],
153153
'message': 'success',

integrations/client/test_delphi_epidata.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,3 +471,48 @@ def test_covidcast_nowcast(self):
471471
'src', 'sig1', 'sensor', 'day', 'county', 22222222, '01001')
472472

473473
self.assertEqual(response, {'result': -2, 'message': 'no results'})
474+
475+
def test_async_epidata(self):
476+
# insert dummy data
477+
self.cur.execute('''
478+
insert into covidcast values
479+
(0, 'src', 'sig', 'day', 'county', 20200414, '11111',
480+
123, 10, 11, 12, 456, 13, 20200414, 0, 1, False),
481+
(0, 'src', 'sig', 'day', 'county', 20200414, '22222',
482+
123, 20, 21, 22, 456, 23, 20200414, 0, 1, False),
483+
(0, 'src', 'sig', 'day', 'county', 20200414, '33333',
484+
123, 30, 31, 32, 456, 33, 20200414, 0, 1, False),
485+
(0, 'src', 'sig', 'day', 'msa', 20200414, '11111',
486+
123, 40, 41, 42, 456, 43, 20200414, 0, 1, False),
487+
(0, 'src', 'sig', 'day', 'msa', 20200414, '22222',
488+
123, 50, 51, 52, 456, 53, 20200414, 0, 1, False),
489+
(0, 'src', 'sig', 'day', 'msa', 20200414, '33333',
490+
123, 60, 61, 62, 456, 634, 20200414, 0, 1, False)
491+
''')
492+
self.cnx.commit()
493+
test_output = Epidata.async_epidata([
494+
{
495+
'source': 'covidcast',
496+
'data_source': 'src',
497+
'signals': 'sig',
498+
'time_type': 'day',
499+
'geo_type': 'county',
500+
'geo_value': '11111',
501+
'time_values': '20200414'
502+
},
503+
{
504+
'source': 'covidcast',
505+
'data_source': 'src',
506+
'signals': 'sig',
507+
'time_type': 'day',
508+
'geo_type': 'county',
509+
'geo_value': '00000',
510+
'time_values': '20200414'
511+
}
512+
], batch_size=10)
513+
responses = [i[0] for i in test_output]*12
514+
# check response is same as standard covidcast call, using 24 calls to test batch sizing
515+
self.assertEqual(responses,
516+
[Epidata.covidcast('src', 'sig', 'day', 'county', 20200414, '11111'),
517+
Epidata.covidcast('src', 'sig', 'day', 'county', 20200414, '00000')]*12
518+
)

src/acquisition/covidcast_nowcast/load_sensors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from shutil import move
2+
from datetime import datetime
23
import os
34
import time
45

@@ -36,7 +37,7 @@ def main(csv_path: str = SENSOR_CSV_PATH) -> None:
3637
"""
3738
user, pw = secrets.db.epi
3839
engine = sqlalchemy.create_engine(f"mysql+pymysql://{user}:{pw}@{secrets.db.host}/{DB_NAME}")
39-
for filepath, attribute in CsvImporter.find_csv_files(csv_path):
40+
for filepath, attribute in CsvImporter.find_issue_specific_csv_files(csv_path):
4041
if attribute is None:
4142
_move_after_processing(filepath, success=False)
4243
continue

src/client/delphi_epidata.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
# External modules
1212
import requests
13+
import asyncio
14+
import warnings
1315

16+
from aiohttp import ClientSession
1417
from pkg_resources import get_distribution, DistributionNotFound
1518

1619
# Obtain package version for the user-agent. Uses the installed version by
@@ -704,3 +707,29 @@ def covidcast_nowcast(
704707

705708
# Make the API call
706709
return Epidata._request(params)
710+
711+
@staticmethod
712+
def async_epidata(param_list, batch_size=100):
713+
"""Make asynchronous Epidata calls for a list of parameters."""
714+
async def async_get(params, session):
715+
"""Helper function to make Epidata GET requests."""
716+
async with session.get(Epidata.BASE_URL, params=params) as response:
717+
return await response.json(), params
718+
719+
async def async_make_calls(param_combos):
720+
"""Helper function to asynchronously make and aggregate Epidata GET requests."""
721+
tasks = []
722+
async with ClientSession() as session:
723+
for param in param_combos:
724+
task = asyncio.ensure_future(async_get(param, session))
725+
tasks.append(task)
726+
responses = await asyncio.gather(*tasks)
727+
return responses
728+
729+
batches = [param_list[i:i+batch_size] for i in range(0, len(param_list), batch_size)]
730+
responses = []
731+
for batch in batches:
732+
loop = asyncio.get_event_loop()
733+
future = asyncio.ensure_future(async_make_calls(batch))
734+
responses += loop.run_until_complete(future)
735+
return responses

src/client/packaging/pypi/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
url='https://github.com/cmu-delphi/delphi-epidata',
1515
packages=setuptools.find_packages(),
1616
install_requires=[
17+
'aiohttp'
1718
'requests>=2.7.0',
1819
],
1920
classifiers=[

tests/acquisition/covidcast_nowcast/test_load_sensors.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def test_load_and_prepare_file(self):
2424
"test_signal",
2525
"test_time_type",
2626
"test_geo_type",
27-
"test_time_value",
28-
"test_issue_value",
29-
"test_lag_value")
27+
20201231,
28+
20210102,
29+
3)
3030

3131
test_df = load_and_prepare_file(StringIO("sensor_name,geo_value,value\ntestname,01001,1.5"), test_attributes)
3232
pd.testing.assert_frame_equal(test_df,
@@ -37,8 +37,8 @@ def test_load_and_prepare_file(self):
3737
"signal": ["test_signal"],
3838
"time_type": ["test_time_type"],
3939
"geo_type": ["test_geo_type"],
40-
"time_value": ["test_time_value"],
41-
"issue": ["test_issue_value"],
42-
"lag": ["test_lag_value"],
40+
"time_value": [20201231],
41+
"issue": [20210102],
42+
"lag": [3],
4343
"value_updated_timestamp": [12345]})
4444
)

0 commit comments

Comments
 (0)