Skip to content

Commit c93f8cc

Browse files
committed
Merge branch 'main' into upsert-nowcast
2 parents 67df27a + e6715c0 commit c93f8cc

File tree

12 files changed

+384
-244
lines changed

12 files changed

+384
-244
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,12 @@ also available. These have names beginning `smoothed_w`, such as
325325
| Signal | Description | Survey Item |
326326
| --- | --- | --- |
327327
| `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/> **First Available:** 2021-01-01 | V3 |
328-
| `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/> **First Available:** 2021-06-01 | V1 |
328+
| `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/> **First Available:** 2021-01-06 | V1 |
329+
| `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/> **First Available:** 2021-01-20 | V4 |
330+
| `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/> **First Available:** 2021-01-20 | V4 |
331+
| `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/> **First Available:** 2021-01-20 | V4 |
332+
| `smoothed_vaccine_likely_govt_health` | Estimated percentage of respondents who would be more likely to get a COVID-19 vaccine if it were recommended to them by government health officials, among respondents who have not yet been vaccinated. <br/> **First Available:** 2021-01-20 | V4 |
333+
| `smoothed_vaccine_likely_politicians` | Estimated percentage of respondents who would be more likely to get a COVID-19 vaccine if it were recommended to them by politicians, among respondents who have not yet been vaccinated. <br/> **First Available:** 2021-01-20 | V4 |
329334

330335
These indicators are based on questions added in Wave 6 of the survey,
331336
introduced on December 19, 2020; however, Delphi only enabled item V1 beginning

src/acquisition/covid_hosp/common/database.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self,
1717
connection,
1818
table_name=None,
1919
columns_and_types=None,
20-
additional_fields=tuple()):
20+
additional_fields=None):
2121
"""Create a new Database object.
2222
2323
Parameters
@@ -26,20 +26,20 @@ def __init__(self,
2626
An open connection to a database.
2727
table_name : str
2828
The name of the table which holds the dataset.
29-
columns_and_types : list[tuple[str, Callable[str, ...]]]
30-
List of CSV columns in order of appearance in the database. The first
31-
element of each tuple is the CSV column name, and the second element is a
32-
function which converts a string into the appropriate datatype for the
33-
column.
29+
columns_and_types : tuple[str, str, Callable]
30+
List of 3-tuples of (CSV header name, SQL column name, data type) for
31+
all the columns in the CSV file.
3432
additional_fields : tuple[str]
35-
Tuple of additional fields to include at the end of the row which are not
36-
present in the CSV data.
33+
List of 2-tuples of (value, SQL column name) fordditional fields to include
34+
at the end of the row which are not present in the CSV data.
3735
"""
3836

3937
self.connection = connection
4038
self.table_name = table_name
39+
self.publication_col_name = "issue" if table_name == 'covid_hosp_state_timeseries' else \
40+
'publication_date'
4141
self.columns_and_types = columns_and_types
42-
self.additional_fields = additional_fields
42+
self.additional_fields = additional_fields if additional_fields is not None else []
4343

4444
@classmethod
4545
@contextmanager
@@ -152,16 +152,19 @@ def insert_dataset(self, publication_date, dataframe):
152152

153153
num_columns = 2 + len(self.columns_and_types) + len(self.additional_fields)
154154
value_placeholders = ', '.join(['%s'] * num_columns)
155-
sql = f'INSERT INTO `{self.table_name}` VALUES ({value_placeholders})'
156-
155+
columns = ', '.join(f'`{i[1]}`' for i in self.columns_and_types + self.additional_fields)
156+
sql = f'INSERT INTO `{self.table_name}` (`id`, `{self.publication_col_name}`, {columns}) ' \
157+
f'VALUES ({value_placeholders})'
157158
id_and_publication_date = (0, publication_date)
158159
with self.new_cursor() as cursor:
159160
for _, row in dataframe.iterrows():
160161
values = []
161-
for name, dtype in self.columns_and_types:
162+
for name, _, dtype in self.columns_and_types:
162163
if isinstance(row[name], float) and math.isnan(row[name]):
163164
values.append(None)
164165
else:
165166
values.append(dtype(row[name]))
166167
cursor.execute(sql,
167-
id_and_publication_date + tuple(values) + self.additional_fields)
168+
id_and_publication_date +
169+
tuple(values) +
170+
tuple(i[0] for i in self.additional_fields))

0 commit comments

Comments
 (0)