Skip to content

Commit 97c0032

Browse files
authored
Merge pull request #1300 from cmu-delphi/release/indicators_v0.1.22_utils_v0.1.16
Release covidcast-indicators 0.1.22
2 parents c1d416a + 907164c commit 97c0032

File tree

15 files changed

+178
-19
lines changed

15 files changed

+178
-19
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.21
2+
current_version = 0.1.22
33
commit = True
44
message = chore: bump covidcast-indicators to {new_version}
55
tag = False

_delphi_utils_python/.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 delphi_utils to {new_version}
55
tag = False

_delphi_utils_python/delphi_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
from .signal import add_prefix
1515
from .nancodes import Nans
1616

17-
__version__ = "0.1.15"
17+
__version__ = "0.1.16"

_delphi_utils_python/delphi_utils/export.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def create_export_csv(
7070
even if there is no data for the day. If false, only the days present are written.
7171
logger: Optional[logging.Logger]
7272
Pass a logger object here to log information about contradictory missing codes.
73+
weekly_dates: Optional[bool]
74+
Whether the output data are weekly or not. If True, will prefix files with
75+
"weekly_YYYYWW" where WW is the epiweek instead of the usual YYYYMMDD for daily files.
7376
7477
Returns
7578
---------

_delphi_utils_python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
setup(
2727
name="delphi_utils",
28-
version="0.1.15",
28+
version="0.1.16",
2929
description="Shared Utility Functions for Indicators",
3030
long_description=long_description,
3131
long_description_content_type="text/markdown",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
["smoothed_vaccine_barrier_language_tried", "msa"], ["smoothed_wvaccine_barrier_language_tried", "msa"],
7373
["smoothed_vaccine_barrier_no_appointments_tried", "msa"], ["smoothed_wvaccine_barrier_no_appointments_tried", "msa"],
7474
["smoothed_vaccine_barrier_none_tried", "msa"], ["smoothed_wvaccine_barrier_none_tried", "msa"],
75-
["smoothed_wvaccine_barrier_technical_difficulties_tried", "msa"], ["smoothed_vaccine_barrier_technical_difficulties_tried", "msa"],
76-
["smoothed_wvaccine_barrier_technology_access_tried", "msa"], ["smoothed_wvaccine_barrier_technology_access_tried", "msa"],
75+
["smoothed_vaccine_barrier_technical_difficulties_tried", "msa"], ["smoothed_wvaccine_barrier_technical_difficulties_tried", "msa"],
76+
["smoothed_vaccine_barrier_technology_access_tried", "msa"], ["smoothed_wvaccine_barrier_technology_access_tried", "msa"],
7777
["smoothed_vaccine_barrier_time_tried", "msa"], ["smoothed_wvaccine_barrier_time_tried", "msa"],
7878
["smoothed_vaccine_barrier_travel_tried", "msa"], ["smoothed_wvaccine_barrier_travel_tried", "msa"],
7979
["smoothed_vaccine_barrier_type_tried", "msa"], ["smoothed_wvaccine_barrier_type_tried", "msa"]

facebook/delphiFacebook/R/responses.R

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ load_response_one <- function(input_filename, params, contingency_run) {
170170
input_data <- bodge_v4_translation(input_data, wave)
171171
input_data <- bodge_C6_C8(input_data, wave)
172172
input_data <- bodge_B13(input_data, wave)
173+
input_data <- bodge_E1(input_data, wave)
173174

174175
input_data <- code_symptoms(input_data, wave)
175176
input_data <- code_hh_size(input_data, wave)
@@ -486,6 +487,34 @@ bodge_B13 <- function(input_data, wave) {
486487
return(input_data)
487488
}
488489

490+
#' Fix E1_* names in Wave 11 data after ~June 16, 2021.
491+
#'
492+
#' Items E1_1 through E1_4 are part of a matrix. Qualtrics, for unknown reasons,
493+
#' switched to naming these E1_4 through E1_7 in June. Convert back to the
494+
#' intended names.
495+
#'
496+
#' @param input_data data frame of responses, before subsetting to select
497+
#' variables
498+
#' @param wave integer indicating survey version
499+
#'
500+
#' @return corrected data frame
501+
#' @importFrom dplyr rename
502+
bodge_E1 <- function(input_data, wave) {
503+
E14_present <- all(c("E1_1", "E1_2", "E1_3", "E1_4") %in% names(input_data))
504+
E47_present <- all(c("E1_4", "E1_5", "E1_6", "E1_7") %in% names(input_data))
505+
assert(!(E14_present && E47_present), "fields E1_1-E1_4 should not be present at the same time as fields E1_4-E1_7")
506+
507+
if ( E47_present ) {
508+
input_data <- rename(input_data,
509+
E1_1 = "E1_4",
510+
E1_2 = "E1_5",
511+
E1_3 = "E1_6",
512+
E1_4 = "E1_7"
513+
)
514+
}
515+
return(input_data)
516+
}
517+
489518
#' Process module assignment column.
490519
#'
491520
#' Rename `module` and recode to A/B/`NA`. Note: module assignment column name

facebook/delphiFacebook/man/bodge_E1.Rd

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

facebook/delphiFacebook/unit-tests/testthat/test-responses.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,43 @@ test_that("B13 bodge works correctly", {
349349
input)
350350
})
351351

352+
test_that("E1 bodge works correctly", {
353+
input <- tibble(
354+
E1_1 = c(1, 2, 3, 1),
355+
E1_2 = c(1, 2, 3, 2),
356+
E1_3 = c(1, 2, 3, 3),
357+
E1_4 = c(1, 2, 3, 4)
358+
)
359+
expect_equal(bodge_E1(input, wave = NA), input)
360+
361+
input_4_to_7 <- tibble(
362+
E1_4 = c(1, 2, 3, 1),
363+
E1_5 = c(1, 2, 3, 2),
364+
E1_6 = c(1, 2, 3, 3),
365+
E1_7 = c(1, 2, 3, 4)
366+
)
367+
368+
expect_equal(bodge_E1(input_4_to_7, wave = NA), input)
369+
370+
input_mixed <- tibble(
371+
E1_4 = c(1, 2, 3, 1),
372+
E1_2 = c(1, 2, 3, 2),
373+
E1_3 = c(1, 2, 3, 3),
374+
E1_7 = c(1, 2, 3, 4)
375+
)
376+
expect_equal(bodge_E1(input_mixed, wave = NA), input_mixed)
377+
378+
input_both <- tibble(
379+
E1_1 = c(1, 2, 3, 1),
380+
E1_2 = c(1, 2, 3, 2),
381+
E1_3 = c(1, 2, 3, 3),
382+
E1_4 = c(1, 2, 3, 1),
383+
E1_5 = c(1, 2, 3, 2),
384+
E1_6 = c(1, 2, 3, 3),
385+
E1_7 = c(1, 2, 3, 4)
386+
)
387+
expect_error(bodge_E1(input_both, wave = NA),
388+
"fields E1_1-E1_4 should not be present at the same time as fields E1_4-E1_7"
389+
)
390+
})
391+

facebook/qsf-tools/generate-codebook.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ process_qsf <- function(path_to_qsf,
326326

327327
if (any(is.na(qdf$description))) {
328328
nonlabelled_items <- qdf$variable[is.na(qdf$description)]
329-
stop(sprintf("items %s do not have a short name assigned",
329+
stop(sprintf("items %s do not have a description provided",
330330
paste(nonlabelled_items, collapse=", "))
331331
)
332332
}
@@ -396,7 +396,14 @@ add_static_fields <- function(codebook,
396396
path_to_static_fields="./static/static_microdata_fields.csv") {
397397
static_fields <- get_static_fields(wave, path_to_static_fields)
398398

399-
return(bind_rows(codebook, static_fields))
399+
codebook <- bind_rows(codebook, static_fields) %>%
400+
filter(!(variable == "module" & wave < 11), # module field is only available for wave >= 11
401+
!(variable %in% c("wave", "UserLanguage", "fips") & wave < 4), # wave, UserLangauge, and fips fields are only available for wave >= 4
402+
!(variable == "w12_treatment" & wave == 12.5), # experimental arm field is only available for wave == 12.5
403+
variable != "Random_Number"
404+
)
405+
406+
return(codebook)
400407
}
401408

402409
#' Load dataframe of non-Qualtrics data fields
@@ -417,8 +424,7 @@ get_static_fields <- function(wave,
417424
response_option_randomization = col_character()
418425
)) %>%
419426
mutate(wave = wave) %>%
420-
select(wave, everything()) %>%
421-
filter(!(variable == "module" & wave < 11))
427+
select(wave, everything())
422428

423429
return(static_fields)
424430
}

0 commit comments

Comments
 (0)