Skip to content

Commit

Permalink
handle v3 samples when checking required values
Browse files Browse the repository at this point in the history
  • Loading branch information
annakrystalli committed May 20, 2024
1 parent 2957a82 commit 8285a60
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 6 deletions.
3 changes: 3 additions & 0 deletions R/check_tbl_values_required.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
check_tbl_values_required <- function(tbl, round_id, file_path, hub_path) {
tbl[["value"]] <- NULL
config_tasks <- hubUtils::read_config(hub_path, "tasks")
if (hubUtils::is_v3_config(config_tasks)) {
tbl[tbl$output_type == "sample", "output_type_id"] <- NA
}
req <- hubData::expand_model_out_val_grid(
config_tasks,
round_id = round_id,
Expand Down
14 changes: 8 additions & 6 deletions inst/testhubs/samples/hub-config/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
"optional": [0, 1, 2, 3]
},
"location": {
"required": null,
"optional": [
"required": [
"US",
"01",
"01"
],
"optional": [
"02",
"04",
"05"
Expand Down Expand Up @@ -120,10 +121,11 @@
"optional": [0, 1, 2, 3]
},
"location": {
"required": null,
"optional": [
"required": [
"US",
"01",
"01"
],
"optional": [
"02",
"04",
"05"
Expand Down
41 changes: 41 additions & 0 deletions tests/testthat/_snaps/check_tbl_values_required.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,44 @@
$ use_cli_format: logi TRUE
- attr(*, "class")= chr [1:5] "check_failure" "hub_check" "rlang_warning" "warning" ...

# check_tbl_values_required works with v3 spec samples

Code
check_tbl_values_required(tbl = tbl, round_id = round_id, file_path = file_path,
hub_path = hub_path)
Output
<message/check_success>
Message:
Required task ID/output type/output type ID combinations all present.

---

Code
check_tbl_values_required(tbl = tbl, round_id = round_id, file_path = file_path,
hub_path = hub_path)
Output
<warning/check_failure>
Warning:
Required task ID/output type/output type ID combinations missing. See `missing` attribute for details.

---

Code
missing
Output
# A tibble: 21 x 7
location reference_date horizon target_end_date target output_type
<chr> <date> <int> <date> <chr> <chr>
1 US 2022-10-22 0 2022-10-22 wk flu hosp rate~ pmf
2 US 2022-10-22 0 2022-10-22 wk flu hosp rate~ pmf
3 US 2022-10-22 0 2022-10-22 wk flu hosp rate~ pmf
4 US 2022-10-22 0 2022-10-22 wk flu hosp rate~ pmf
5 US 2022-10-22 1 2022-10-29 wk flu hosp rate~ pmf
6 US 2022-10-22 1 2022-10-29 wk flu hosp rate~ pmf
7 US 2022-10-22 1 2022-10-29 wk flu hosp rate~ pmf
8 US 2022-10-22 1 2022-10-29 wk flu hosp rate~ pmf
9 US 2022-10-22 2 2022-11-05 wk flu hosp rate~ pmf
10 US 2022-10-22 2 2022-11-05 wk flu hosp rate~ pmf
# i 11 more rows
# i 1 more variable: output_type_id <chr>

43 changes: 43 additions & 0 deletions tests/testthat/test-check_tbl_values_required.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,46 @@ test_that(
)
}
)

test_that("check_tbl_values_required works with v3 spec samples", {
hub_path <- system.file("testhubs/samples", package = "hubValidations")
file_path <- "Flusight-baseline/2022-10-22-Flusight-baseline.csv"
round_id <- "2022-10-22"
tbl <- read_model_out_file(
file_path = file_path,
hub_path = hub_path,
coerce_types = "chr"
)
expect_snapshot(
check_tbl_values_required(
tbl = tbl,
round_id = round_id,
file_path = file_path,
hub_path = hub_path
)
)
# Remove US location to test missing required values identified and reported
# correctly.
tbl <- tbl[tbl$location != "US", ]
expect_snapshot(
check_tbl_values_required(
tbl = tbl,
round_id = round_id,
file_path = file_path,
hub_path = hub_path
)
)
missing <- check_tbl_values_required(
tbl = tbl,
round_id = round_id,
file_path = file_path,
hub_path = hub_path
)$missing
expect_snapshot(missing)
expect_equal(
unique(missing$output_type),
c("pmf", "sample", "mean", "median")
)
expect_true(all(missing$location == "US"))

})

0 comments on commit 8285a60

Please sign in to comment.