Skip to content

Commit a4f7101

Browse files
committed
enh: update cast-api query getter function
1 parent f6a59e0 commit a4f7101

File tree

4 files changed

+24
-34
lines changed

4 files changed

+24
-34
lines changed

R/aux_data_utils.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,14 +676,14 @@ get_nhsn_data_archive <- function(disease = c("covid", "flu")) {
676676
signal = glue::glue("confirmed_admissions_{disease}_ew"),
677677
geo_type = "state",
678678
columns = c("geo_value", "time_value", "value", "report_ts_nominal_start", "report_ts_nominal_end"),
679-
limit = -1
679+
version_query = glue::glue("all<={Sys.Date()}")
680680
)
681681
nhsn_nation <- get_cast_api_data(
682682
source = "nhsn",
683683
signal = glue::glue("confirmed_admissions_{disease}_ew"),
684684
geo_type = "nation",
685685
columns = c("geo_value", "time_value", "value", "report_ts_nominal_start", "report_ts_nominal_end"),
686-
limit = -1
686+
version_query = glue::glue("all<={Sys.Date()}")
687687
)
688688
nhsn_data <- nhsn_state %>%
689689
rbind(nhsn_nation) %>%
@@ -707,14 +707,14 @@ up_to_date_nssp_state_archive <- function(disease = c("covid", "influenza")) {
707707
signal = glue::glue("pct_ed_visits_{disease}"),
708708
geo_type = "nation",
709709
columns = c("geo_value", "time_value", "value", "report_ts_nominal_start", "report_ts_nominal_end"),
710-
limit = -1
710+
version_query = glue::glue("all<={Sys.Date()}")
711711
)
712712
nssp_state <- get_cast_api_data(
713713
source = "nssp",
714714
signal = glue::glue("pct_ed_visits_{disease}"),
715715
geo_type = "state",
716716
columns = c("geo_value", "time_value", "value", "report_ts_nominal_start", "report_ts_nominal_end"),
717-
limit = -1
717+
version_query = glue::glue("all<={Sys.Date()}")
718718
)
719719
nssp_data <- nssp_state %>%
720720
rbind(nssp_national) %>%

R/utils.R

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -941,33 +941,26 @@ compare_s3_etag <- function(bucket, key, region = "us-east-1") {
941941
}
942942

943943
build_cast_api_query <- function(
944-
source = c("nssp", "nhsn"),
945-
signal = NULL,
946-
geo_type = c("state", "nation"),
944+
source,
945+
signal,
946+
geo_type,
947947
columns = NULL,
948948
fill_method = c("source", "fill_ave", "fill_zero"),
949-
limit = -1,
950-
offset = 0,
951-
versions_before = NULL,
952-
geo_value = NULL,
953-
time_value = NULL) {
954-
source <- rlang::arg_match(source)
949+
version_query = NULL) {
950+
source <- rlang::arg_match(source, values = c("nssp", "nhsn"))
951+
stopifnot(is.character(signal), length(signal) == 1L)
952+
geo_type <- rlang::arg_match(geo_type, values = c("state", "nation"))
955953
fill_method <- rlang::arg_match(fill_method)
956-
geo_type <- rlang::arg_match(geo_type)
957954
columns <- columns %||% c("geo_value", "time_value", "value")
958955

959956
httr2::request("https://delphi.cmu.edu/cast-api/epidata/v2") %>%
960957
httr2::req_url_query(
961958
source = source,
962959
signal = signal,
963960
geo_type = geo_type,
964-
versions_before = versions_before,
961+
versions_before = version_query,
965962
columns = columns,
966-
limit = limit,
967-
offset = offset,
968963
fill_method = fill_method,
969-
geo_value = geo_value,
970-
time_value = time_value,
971964
.multi = "explode"
972965
)
973966
}

scripts/covid_hosp_prod.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ parameters_and_date_targets <- rlang::list2(
201201
name = covid_data_substitutions,
202202
command = "scripts/covid_data_substitutions.csv"
203203
),
204-
tar_target(
204+
tar_change(
205205
name = nhsn_archive_data,
206+
change = get_cast_api_latest_update_date(source = "nhsn"),
206207
command = {
207208
get_nhsn_data_archive("covid")
208-
},
209-
cue = tar_cue("always")
209+
}
210210
),
211211
tar_target(
212212
name = nhsn_latest_data,
@@ -216,12 +216,12 @@ parameters_and_date_targets <- rlang::list2(
216216
filter(geo_value %nin% g_insufficient_data_geos)
217217
}
218218
),
219-
tar_target(
219+
tar_change(
220220
name = nssp_archive_data,
221+
change = get_cast_api_latest_update_date(source = "nssp"),
221222
command = {
222223
up_to_date_nssp_state_archive("covid")
223-
},
224-
cue = tar_cue("always")
224+
}
225225
),
226226
tar_target(
227227
name = nssp_latest_data,

scripts/flu_hosp_prod.R

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ parameters_and_date_targets <- rlang::list2(
242242
filter(source != "nhsn")
243243
}
244244
),
245-
tar_target(
245+
tar_change(
246246
name = nhsn_archive_data,
247+
change = get_cast_api_latest_update_date(source = "nhsn"),
247248
command = {
248249
get_nhsn_data_archive("flu")
249-
},
250-
cue = tar_cue("always")
250+
}
251251
),
252252
tar_target(
253253
name = nhsn_latest_data,
@@ -257,15 +257,12 @@ parameters_and_date_targets <- rlang::list2(
257257
filter(geo_value %nin% g_insufficient_data_geos)
258258
}
259259
),
260-
# TODO: Currently metadata queries are slow 25s, while downloading takes 0.5s. Optimize later.
261-
# tar_change(
262-
# change = get_cast_api_latest_update_date(source = "nssp"),
263-
tar_target(
260+
tar_change(
264261
name = nssp_archive_data,
262+
change = get_cast_api_latest_update_date(source = "nssp"),
265263
command = {
266264
up_to_date_nssp_state_archive("influenza")
267-
},
268-
cue = tar_cue("always")
265+
}
269266
),
270267
tar_target(
271268
name = nssp_latest_data,

0 commit comments

Comments
 (0)