Skip to content

Commit 50d1cd6

Browse files
authored
Merge pull request #1245 from cmu-delphi/release/indicators_v0.1.16_utils_v0.1.12
Release covidcast-indicators 0.1.16
2 parents be1b829 + dea417e commit 50d1cd6

File tree

9 files changed

+349
-237
lines changed

9 files changed

+349
-237
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.15
2+
current_version = 0.1.16
33
commit = True
44
message = chore: bump covidcast-indicators to {new_version}
55
tag = False

ansible/templates/facebook-params-prod.json.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"backfill_days": 4,
55
"cache_dir": "./cache",
66
"debug": false,
7+
"delphi_survey_email_user": "{{ fb_survey_email_user }}",
8+
"delphi_survey_sftp_password": "{{ fb_survey_sftp_password }}",
9+
"delphi_survey_sftp_user": "{{ fb_survey_sftp_user }}",
10+
"sftp_options": "-o 'BatchMode=no' -o 'StrictHostKeyChecking=no' -o 'PubkeyAuthentication=no' -o 'PreferredAuthentications=password'",
711
"end_date": "2021-08-16",
812
"export_dir": "./receiving",
913
"individual_dir": "./individual",

ansible/vars.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,32 @@ python_version: "3.8.2"
1010
pyenv_python_path: "/home/{{ runtime_user }}/.pyenv/versions/{{ python_version }}/bin/python"
1111

1212
# Indicators variables
13+
# Google Health
1314
google_health_api_key: "{{ vault_google_health_api_key }}"
1415
delphi_aws_access_key_id: "{{ vault_delphi_aws_access_key_id }}"
1516
delphi_aws_secret_access_key: "{{ vault_delphi_aws_secret_access_key }}"
17+
# SafeGraph
1618
safegraph_aws_access_key_id: "{{ vault_safegraph_aws_access_key_id }}"
1719
safegraph_aws_secret_access_key: "{{ vault_safegraph_aws_secret_access_key }}"
20+
# Quidel
1821
quidel_aws_access_key_id: "{{ vault_quidel_aws_access_key_id }}"
1922
quidel_aws_secret_access_key: "{{ vault_quidel_aws_secret_access_key }}"
2023
quidel_aws_bucket_name: 'delphi-quidel-data'
24+
# Change Healthcare
2125
changehc_sftp_host: "{{ vault_changehc_sftp_host }}"
2226
changehc_sftp_port: "{{ vault_changehc_sftp_port }}"
2327
changehc_sftp_user: "{{ vault_changehc_sftp_user }}"
2428
changehc_sftp_password: "{{ vault_changehc_sftp_password }}"
29+
# NCHS
2530
nchs_mortality_token: "{{ vault_nchs_mortality_token }}"
31+
# SirCAL
2632
sir_complainsalot_slack_token: "{{ vault_sir_complainsalot_slack_token }}"
33+
# Survey
2734
fb_qualtrics_token: "{{ vault_fb_qualtrics_token }}"
2835
fb_notify_weights_email_list: "{{ vault_fb_notify_weights_email_list }}"
36+
fb_survey_email_user: "{{ vault_fb_survey_email_user }}"
37+
fb_survey_sftp_password: "{{ vault_fb_survey_sftp_password }}"
38+
fb_survey_sftp_user: "{{ vault_fb_survey_sftp_user }}"
2939
## Google Symptoms
3040
google_symptoms_account_type: "{{ vault_google_symptoms_account_type }}"
3141
google_symptoms_project_id: "{{ vault_google_symptoms_project_id }}"

ansible/vault.yaml

Lines changed: 224 additions & 216 deletions
Large diffs are not rendered by default.

facebook/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM rocker/tidyverse:latest
2+
3+
# use delphi's timezome
4+
RUN ln -s -f /usr/share/zoneinfo/America/New_York /etc/localtime
5+
6+
RUN install2.r --error \
7+
jsonlite \
8+
stringr \
9+
stringi \
10+
data.table \
11+
roxygen2 \
12+
Rcpp \
13+
BH
14+
15+
RUN R --no-restore --no-save -e 'devtools::install_version("readr", version="1.4.0")'
16+
RUN apt-get update && apt-get install -qq -y \
17+
python3-venv \
18+
sshpass \
19+
openssh-server \
20+
ssmtp
21+
22+
ADD ./delphiFacebook /facebook/delphiFacebook/
23+
ADD ./static /facebook/static/
24+
ADD ./Makefile /facebook/Makefile
25+
ADD ./run.R /facebook/run.R
26+
ADD ./monthly-files.R /facebook/monthly-files.R
27+
ADD ./contingency_tables.R /facebook/contingency_tables.R
28+
ADD ./contingency-combine.R /facebook/contingency-combine.R
29+
ADD ./ssmtp.conf /etc/ssmtp/ssmtp.conf
30+
WORKDIR /facebook/
31+
RUN make lib
32+
RUN make install

facebook/Makefile

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
SHELL:=/bin/bash --rcfile bash-init.sh
22

3-
# dry-run mode: generate all files, but do not post them anywhere, and disable all emails to outside parties.
4-
DRY:=yes
5-
ifeq ($(DRY),yes)
6-
EMAIL_SEND:=echo -e "Would send mail: echo -e \"Subject: $${SUBJECT}\n\n$${MSG}\" | sendmail [email protected]"
7-
SFTP_POST:=echo -e "Would run: sftp -b <(echo -e \"\$${BATCH}\") -P 2222 [email protected]\n$${BATCH}"
8-
DRY_MESSAGE:="[DRY-RUN] "
9-
else
10-
EMAIL_SEND:=echo -e "Subject: $${SUBJECT}\n\n$${MSG}" | sendmail [email protected]
11-
SFTP_POST:=sftp -b <(echo -e "$${BATCH}") -P 2222 [email protected]
12-
endif
13-
143
EPOCH:=2020-04-06
154
TODAY:=$(shell date +"%Y-%m-%d")
165
YESTERDAY:=$(shell date --date "$(TODAY) -1 day" +"%Y-%m-%d")
176
ONEWEEK:=$(shell date --date "$(TODAY) -7 day" +"%Y-%m-%d")
187
THREEWEEK:=$(shell date --date "$(TODAY) -21 day" +"%Y-%m-%d")
198

20-
MESSAGES:=$(TODAY).messages
9+
MESSAGES:="messages/$(TODAY).messages"
2110

2211
PYTHON:=env/bin/python
2312
QUALTRICS=$(shell $(PYTHON) -m delphi_utils get input_dir)
@@ -27,6 +16,10 @@ INDIVIDUAL=$(shell $(PYTHON) -m delphi_utils get individual_dir)
2716
ARCHIVE=$(shell $(PYTHON) -m delphi_utils get archive_dir)
2817
RECEIVING=$(shell $(PYTHON) -m delphi_utils get export_dir)
2918
FB_CC=$(shell $(PYTHON) -m delphi_utils get qualtrics.notify-bad-weights)
19+
DELPHI_SURVEY_SFTP_PASSWORD=$(shell $(PYTHON) -m delphi_utils get delphi_survey_sftp_password)
20+
DELPHI_SURVEY_SFTP_USER=$(shell $(PYTHON) -m delphi_utils get delphi_survey_sftp_user)
21+
DELPHI_SURVEY_EMAIL_USER=$(shell $(PYTHON) -m delphi_utils get delphi_survey_email_user)
22+
SFTP_OPTIONS=$(shell $(PYTHON) -m delphi_utils get sftp_options)
3023

3124
MAX_WEIGHTED=ls -1 $(WEIGHTS) | grep dap | tail -1 | sed 's/_.*//;s/-//g;'
3225

@@ -35,16 +28,34 @@ CIDS_DEST:="fb-interchange/cmu_respondent_ids"
3528
INDIVID_DEST:="fb-public-results/"
3629
RAW_DEST:="raw"
3730

31+
# dry-run mode: generate all files, but do not post them anywhere, and disable all emails to outside parties.
32+
DRY:=yes
33+
ifeq ($(DRY),yes)
34+
EMAIL_SEND:=echo -e "Would send mail: echo -e \"Subject: $${SUBJECT}\n\n$${MSG}\" | sendmail $(DELPHI_SURVEY_EMAIL_USER)"
35+
SFTP_POST:=echo -e "Would run: sshpass -p $(DELPHI_SURVEY_SFTP_PASSWORD) sftp $(SFTP_OPTIONS) -b <(echo -e \"\$${BATCH}\") -P 2222 $(DELPHI_SURVEY_SFTP_USER)\n$${BATCH}"
36+
DRY_MESSAGE:="[DRY-RUN] "
37+
else
38+
EMAIL_SEND:=echo -e "Subject: $${SUBJECT}\n\n$${MSG}" | sendmail $(DELPHI_SURVEY_EMAIL_USER)
39+
SFTP_POST:=sshpass -p $(DELPHI_SURVEY_SFTP_PASSWORD) sftp $(SFTP_OPTIONS) -b <(echo -e "$${BATCH}") -P 2222 $(DELPHI_SURVEY_SFTP_USER)
40+
endif
41+
3842
default:
3943
@echo No default implemented yet
4044

45+
scratch:
46+
mkdir scratch
47+
rm -rf scratch/*
48+
4149
tidy: receiving
42-
rm -rf tidy
50+
rm -rf tidy/$(RECEIVING)
51+
rm -rf tidy/$(INDIVIDUAL)
52+
rm -f tidy/params.json
4353
mkdir -p tidy tidy/$(RECEIVING) tidy/$(INDIVIDUAL)
4454
cp params.json tidy/
4555
mv $(RECEIVING)/*.csv tidy/$(RECEIVING)
4656
mv $(INDIVIDUAL)/*.csv* tidy/$(INDIVIDUAL)
47-
tar -czf tidy-`date +"%Y-%m-%d-%H%M%S"`.tgz tidy
57+
tar -czf scratch/tidy-`date +"%Y-%m-%d-%H%M%S"`.tgz tidy
58+
mv scratch/*.tgz tidy/
4859

4960
clean:
5061
rm -f $(RECEIVING)/*.csv $(INDIVIDUAL)/*.csv $(CIDS)/*.csv
@@ -55,7 +66,8 @@ clean-archive:
5566
install-python:
5667
python3.8 -m venv env
5768
source env/bin/activate && \
58-
pip install -e ../_delphi_utils_python && \
69+
pip install wheel && \
70+
pip install delphi_utils && \
5971
pip install -e delphiFacebook/python
6072

6173
install-R:dev
@@ -67,7 +79,6 @@ $(CIDS):
6779

6880
init-qualtrics:
6981
grep '"token": "..*"' params.json
70-
git show -s --oneline HEAD >> $(MESSAGES)
7182

7283
$(TODAY):
7384
[ -f $(QUALTRICS) ] || mkdir -p $(QUALTRICS)
@@ -99,13 +110,13 @@ $(WEIGHTS): $(TODAY)
99110
[ -f $(WEIGHTS) ] || mkdir -p $(WEIGHTS)
100111
cd "$(WEIGHTS)"; \
101112
BATCH="cd fb-interchange/cmu_respondent_weights\nls -1"; \
102-
NEW=`LC_ALL=C comm -23 <(sftp -b <(echo -e "$${BATCH}") -P 2222 [email protected] | grep "^202" | LC_ALL=C sort) <(ls -1 | LC_ALL=C sort)`; \
113+
NEW=`LC_ALL=C comm -23 <(sshpass -p $(DELPHI_SURVEY_SFTP_PASSWORD) sftp $(SFTP_OPTIONS) -b <(echo -e "$${BATCH}") -P 2222 $(DELPHI_SURVEY_SFTP_USER) | grep "^202" | LC_ALL=C sort) <(ls -1 | LC_ALL=C sort)`; \
103114
echo "New weights files:"; \
104115
echo $${NEW}; \
105116
for f in $${NEW}; do \
106117
BATCH="$${BATCH}\nget $$f"; \
107118
done; \
108-
sftp -b <(echo -e "$${BATCH}") -P 2222 [email protected] || exit 90; \
119+
sshpass -p $(DELPHI_SURVEY_SFTP_PASSWORD) sftp $(SFTP_OPTIONS) -b <(echo -e "$${BATCH}") -P 2222 $(DELPHI_SURVEY_SFTP_USER) || exit 90; \
109120
cd -; \
110121
MAX_WEIGHTED=`$(MAX_WEIGHTED)`; \
111122
EXPECTED_MAX_WEIGHTED=`date --date='$(TODAY) -3 day' +'%Y%m%d'`; \
@@ -129,11 +140,12 @@ run-R: $(CIDS)
129140
grep "scheduled core" tmp ; \
130141
[ "$$?" -eq 1 ]
131142

132-
pipeline: init-qualtrics params.json $(WEIGHTS) run-R post-cids post-individual post-done tidy
143+
pipeline: scratch init-qualtrics params.json $(WEIGHTS) run-R post-cids post-individual post-done tidy
133144
grep $(TODAY) params.json
134145
[ -f $(YESTERDAY) ] && rm $(YESTERDAY) || true
135146
touch $@
136147
echo "SUCCESS: $(DRY_MESSAGE)pipeline complete" >> $(MESSAGES)
148+
chmod o+w $(MESSAGES)
137149

138150
coverage:
139151
Rscript -e 'covr::package_coverage("delphiFacebook")'

facebook/delphiFacebook/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Depends:
1313
Imports:
1414
stats,
1515
rlang,
16-
readr,
16+
readr (<= 1.4.0),
1717
dplyr,
1818
stringi,
1919
jsonlite,

facebook/qsf-tools/generate-codebook.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ process_qsf <- function(path_to_qsf,
9292
choices <- displayed_questions %>%
9393
map(~ .x$Payload$Choices) %>%
9494
map(~ map(.x, "Display"))
95+
recode_map <- displayed_questions %>%
96+
map(~ .x$Payload$RecodeValues)
97+
98+
# Recode response options if overriding Qualtrics auto-assigned coding.
99+
ii_recode <- recode_map %>%
100+
map(~ !is.null(.x)) %>%
101+
unlist() %>%
102+
which()
103+
choices[ii_recode] <- map2(.x=choices[ii_recode], .y=recode_map[ii_recode],
104+
~ setNames(.x, .y[names(.x)])
105+
)
95106

96107
# derive from choices where users can fill in "Other" response with free text
97108
other_text_option <- displayed_questions %>%
@@ -158,11 +169,25 @@ process_qsf <- function(path_to_qsf,
158169
map(.x, "Operator"),
159170
map(.x, "RightOperand")
160171
)) %>%
172+
# Remove empty logic
161173
map(~ gsub(" Is ", "", .x)) %>%
162174
map(~ gsub("NULL NULL Is NULL NULL", "", .x)) %>%
163175
map(~ gsub(" ?NULL ?", "", .x)) %>%
176+
# Remove QID flag
164177
map(~ gsub("q://", "", .x)) %>%
178+
# Recode choice numbers
179+
map(~ gsubfn("(QID[0-9]+)(/SelectableChoice/)([0-9]+)", function(qid, selectable_text, option_code) {
180+
curr_map <- recode_map[qids == qid][[1]]
181+
182+
if ( !is.null(curr_map) ) {
183+
option_code <- curr_map[names(curr_map) == option_code]
184+
}
185+
186+
paste(c(qid, selectable_text, option_code), collapse="")
187+
}, .x)) %>%
188+
# Replace QID with question number (A2, etc)
165189
map(~ gsubfn("(QID[0-9]+)", function(qid) {items[qids == qid]}, .x)) %>%
190+
# Collapse logic into a single string.
166191
map(~ paste(.x, collapse=" "))
167192

168193
logic_type <- displayed_questions %>%

facebook/ssmtp.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Config file for sSMTP sendmail
3+
#
4+
# The person who gets all mail for userids < 1000
5+
# Make this empty to disable rewriting.
6+
root=postmaster
7+
8+
# The place where the mail goes. The actual machine name is required no
9+
# MX records are consulted. Commonly mailhosts are named mail.domain.com
10+
mailhub=localhost
11+
12+
# Where will the mail seem to come from?
13+
#rewriteDomain=
14+
15+
# The full hostname
16+
hostname=delphi.cmu.edu
17+
18+
# Are users allowed to set their own From: address?
19+
# YES - Allow the user to specify their own From: address
20+
# NO - Use the system generated From: address
21+
#FromLineOverride=YES

0 commit comments

Comments
 (0)