Skip to content

Commit

Permalink
Merge pull request #94 from hubverse-org/ak/make-latest-snaphots-vers…
Browse files Browse the repository at this point in the history
…ion-agnostic/93
  • Loading branch information
annakrystalli authored Jan 17, 2025
2 parents 580cc7e + cddec0b commit 3751927
Show file tree
Hide file tree
Showing 30 changed files with 789 additions and 646 deletions.
58 changes: 57 additions & 1 deletion R/append_round.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,67 @@
#' )
#' )
#' append_round(config, new_round)
#' # Append in existing config file
#' # Append in existing config file using an older schema version
#' options(hubAdmin.schema_version = "v4.0.0")
#' config <- hubUtils::read_config_file(
#' system.file("v4-tasks.json", package = "hubAdmin")
#' )
#' # Create new round using version defined through
#' # hubAdmin.schema_version option
#' new_round <- create_round(
#' round_id_from_variable = TRUE,
#' round_id = "origin_date",
#' model_tasks = create_model_tasks(
#' create_model_task(
#' task_ids = create_task_ids(
#' create_task_id("origin_date",
#' required = NULL,
#' optional = c(
#' "2023-01-23"
#' )
#' ),
#' create_task_id("location",
#' required = "US",
#' optional = c("01", "02", "04", "05", "06")
#' ),
#' create_task_id("horizon",
#' required = 1L,
#' optional = 2:4
#' ),
#' create_task_id("age_group",
#' required = NULL,
#' optional = c("1", "2", "3", "4", "5")
#' )
#' ),
#' output_type = create_output_type(
#' create_output_type_mean(
#' is_required = TRUE,
#' value_type = "double",
#' value_minimum = 0L
#' )
#' ),
#' target_metadata = create_target_metadata(
#' create_target_metadata_item(
#' target_id = "inc hosp",
#' target_name = "Weekly incident influenza hospitalizations",
#' target_units = "rate per 100,000 population",
#' target_keys = NULL,
#' target_type = "discrete",
#' is_step_ahead = TRUE,
#' time_unit = "week"
#' )
#' )
#' )
#' ),
#' submissions_due = list(
#' relative_to = "origin_date",
#' start = -4L,
#' end = 2L
#' )
#' )
#' append_round(config, new_round)
#' # Reset option to latest schema version
#' options(hubAdmin.schema_version = "latest")
append_round <- function(config, ...) {
checkmate::assert_class(config, "config")

Expand Down
58 changes: 57 additions & 1 deletion man/append_round.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/testthat/_snaps/create_config.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# create_config functions work correctly

Code
create_config(rounds)
verify_latest_schema_version(create_config(rounds))
Output
$schema_version
[1] "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.0/tasks-schema.json"
[1] "latest"
$rounds
$rounds[[1]]
Expand Down Expand Up @@ -107,7 +107,7 @@
attr(,"type")
[1] "tasks"
attr(,"schema_id")
[1] "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.0/tasks-schema.json"
[1] "latest"
attr(,"branch")
[1] "main"

Expand Down
71 changes: 37 additions & 34 deletions tests/testthat/_snaps/create_model_task.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# create_model_task functions work correctly

Code
create_model_task(task_ids = create_task_ids(create_task_id("origin_date",
required = NULL, optional = c("2023-01-02", "2023-01-09", "2023-01-16")),
create_task_id("location", required = "US", optional = c("01", "02", "04", "05",
"06")), create_task_id("horizon", required = 1L, optional = 2:4)),
output_type = create_output_type(create_output_type_mean(is_required = TRUE,
value_type = "double", value_minimum = 0L)), target_metadata = create_target_metadata(
verify_latest_schema_version(create_model_task(task_ids = create_task_ids(
create_task_id("origin_date", required = NULL, optional = c("2023-01-02",
"2023-01-09", "2023-01-16")), create_task_id("location", required = "US",
optional = c("01", "02", "04", "05", "06")), create_task_id("horizon",
required = 1L, optional = 2:4)), output_type = create_output_type(
create_output_type_mean(is_required = TRUE, value_type = "double",
value_minimum = 0L)), target_metadata = create_target_metadata(
create_target_metadata_item(target_id = "inc hosp", target_name = "Weekly incident influenza hospitalizations",
target_units = "rate per 100,000 population", target_keys = NULL,
target_type = "discrete", is_step_ahead = TRUE, time_unit = "week")))
target_type = "discrete", is_step_ahead = TRUE, time_unit = "week"))))
Output
$task_ids
$task_ids$origin_date
Expand Down Expand Up @@ -85,26 +86,27 @@
attr(,"class")
[1] "model_task" "list"
attr(,"schema_id")
[1] "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.0/tasks-schema.json"
[1] "latest"
attr(,"branch")
[1] "main"

---

Code
create_model_task(task_ids = create_task_ids(create_task_id("origin_date",
required = NULL, optional = c("2023-01-02", "2023-01-09", "2023-01-16")),
create_task_id("location", required = "US", optional = c("01", "02", "04", "05",
"06")), create_task_id("horizon", required = 1L, optional = 2:4)),
output_type = create_output_type(create_output_type_mean(is_required = TRUE,
value_type = "double", value_minimum = 0L), create_output_type_sample(
is_required = FALSE, output_type_id_type = "character", max_length = 5L,
min_samples_per_task = 70L, max_samples_per_task = 100L, compound_taskid_set = c(
"horizon", "origin_date"), value_type = "double", value_minimum = 0L,
value_maximum = 1L)), target_metadata = create_target_metadata(
create_target_metadata_item(target_id = "inc hosp", target_name = "Weekly incident influenza hospitalizations",
target_units = "rate per 100,000 population", target_keys = NULL,
target_type = "discrete", is_step_ahead = TRUE, time_unit = "week")))
verify_latest_schema_version(create_model_task(task_ids = create_task_ids(
create_task_id("origin_date", required = NULL, optional = c("2023-01-02",
"2023-01-09", "2023-01-16")), create_task_id("location", required = "US",
optional = c("01", "02", "04", "05", "06")), create_task_id("horizon",
required = 1L, optional = 2:4)), output_type = create_output_type(
create_output_type_mean(is_required = TRUE, value_type = "double",
value_minimum = 0L), create_output_type_sample(is_required = FALSE,
output_type_id_type = "character", max_length = 5L, min_samples_per_task = 70L,
max_samples_per_task = 100L, compound_taskid_set = c("horizon",
"origin_date"), value_type = "double", value_minimum = 0L, value_maximum = 1L)),
target_metadata = create_target_metadata(create_target_metadata_item(target_id = "inc hosp",
target_name = "Weekly incident influenza hospitalizations", target_units = "rate per 100,000 population",
target_keys = NULL, target_type = "discrete", is_step_ahead = TRUE,
time_unit = "week"))))
Output
$task_ids
$task_ids$origin_date
Expand Down Expand Up @@ -213,29 +215,30 @@
attr(,"class")
[1] "model_task" "list"
attr(,"schema_id")
[1] "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.0/tasks-schema.json"
[1] "latest"
attr(,"branch")
[1] "main"

---

Code
create_model_task(task_ids = create_task_ids(create_task_id("origin_date",
required = NULL, optional = c("2023-01-02", "2023-01-09", "2023-01-16")),
create_task_id("location", required = "US", optional = c("01", "02", "04", "05",
"06")), create_task_id("target", required = NULL, optional = c("inc death",
"inc hosp")), create_task_id("horizon", required = 1L, optional = 2:4)),
output_type = create_output_type(create_output_type_mean(is_required = TRUE,
value_type = "double", value_minimum = 0L), create_output_type_median(
is_required = FALSE, value_type = "double"), create_output_type_quantile(
required = c(0.1, 0.2, 0.3, 0.4, 0.6, 0.7, 0.8, 0.9), is_required = TRUE,
value_type = "double", value_minimum = 0)), target_metadata = create_target_metadata(
verify_latest_schema_version(create_model_task(task_ids = create_task_ids(
create_task_id("origin_date", required = NULL, optional = c("2023-01-02",
"2023-01-09", "2023-01-16")), create_task_id("location", required = "US",
optional = c("01", "02", "04", "05", "06")), create_task_id("target",
required = NULL, optional = c("inc death", "inc hosp")), create_task_id(
"horizon", required = 1L, optional = 2:4)), output_type = create_output_type(
create_output_type_mean(is_required = TRUE, value_type = "double",
value_minimum = 0L), create_output_type_median(is_required = FALSE,
value_type = "double"), create_output_type_quantile(required = c(0.1, 0.2,
0.3, 0.4, 0.6, 0.7, 0.8, 0.9), is_required = TRUE, value_type = "double",
value_minimum = 0)), target_metadata = create_target_metadata(
create_target_metadata_item(target_id = "inc hosp", target_name = "Weekly incident influenza hospitalizations",
target_units = "rate per 100,000 population", target_keys = list(target = "inc hosp"),
target_type = "discrete", is_step_ahead = TRUE, time_unit = "week"),
create_target_metadata_item(target_id = "inc death", target_name = "Weekly incident influenza deaths",
target_units = "rate per 100,000 population", target_keys = list(target = "inc death"),
target_type = "discrete", is_step_ahead = TRUE, time_unit = "week")))
target_type = "discrete", is_step_ahead = TRUE, time_unit = "week"))))
Output
$task_ids
$task_ids$origin_date
Expand Down Expand Up @@ -379,7 +382,7 @@
attr(,"class")
[1] "model_task" "list"
attr(,"schema_id")
[1] "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.0/tasks-schema.json"
[1] "latest"
attr(,"branch")
[1] "main"

Expand Down
60 changes: 30 additions & 30 deletions tests/testthat/_snaps/create_model_tasks.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# create_model_tasks functions work correctly

Code
create_model_tasks(create_model_task(task_ids = create_task_ids(create_task_id(
"origin_date", required = NULL, optional = c("2023-01-02", "2023-01-09",
"2023-01-16")), create_task_id("location", required = "US", optional = c(
"01", "02", "04", "05", "06")), create_task_id("horizon", required = 1L,
optional = 2:4)), output_type = create_output_type(create_output_type_mean(
is_required = TRUE, value_type = "double", value_minimum = 0L)),
target_metadata = create_target_metadata(create_target_metadata_item(target_id = "inc hosp",
target_name = "Weekly incident influenza hospitalizations", target_units = "rate per 100,000 population",
target_keys = NULL, target_type = "discrete", is_step_ahead = TRUE,
time_unit = "week"))))
verify_latest_schema_version(create_model_tasks(create_model_task(task_ids = create_task_ids(
create_task_id("origin_date", required = NULL, optional = c("2023-01-02",
"2023-01-09", "2023-01-16")), create_task_id("location", required = "US",
optional = c("01", "02", "04", "05", "06")), create_task_id("horizon",
required = 1L, optional = 2:4)), output_type = create_output_type(
create_output_type_mean(is_required = TRUE, value_type = "double",
value_minimum = 0L)), target_metadata = create_target_metadata(
create_target_metadata_item(target_id = "inc hosp", target_name = "Weekly incident influenza hospitalizations",
target_units = "rate per 100,000 population", target_keys = NULL,
target_type = "discrete", is_step_ahead = TRUE, time_unit = "week")))))
Output
$model_tasks
$model_tasks[[1]]
Expand Down Expand Up @@ -92,30 +92,30 @@
attr(,"n")
[1] 1
attr(,"schema_id")
[1] "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.0/tasks-schema.json"
[1] "latest"
attr(,"branch")
[1] "main"

---

Code
create_model_tasks(create_model_task(task_ids = create_task_ids(create_task_id(
"origin_date", required = NULL, optional = c("2023-01-02", "2023-01-09",
"2023-01-16")), create_task_id("location", required = "US", optional = c(
"01", "02", "04", "05", "06")), create_task_id("target", required = NULL,
optional = c("inc death", "inc hosp")), create_task_id("horizon", required = 1L,
optional = 2:4)), output_type = create_output_type(create_output_type_mean(
is_required = TRUE, value_type = "double", value_minimum = 0L),
create_output_type_median(is_required = FALSE, value_type = "double"),
create_output_type_quantile(required = c(0.1, 0.2, 0.3, 0.4, 0.6, 0.7, 0.8, 0.9),
is_required = TRUE, value_type = "double", value_minimum = 0)),
target_metadata = create_target_metadata(create_target_metadata_item(target_id = "inc hosp",
target_name = "Weekly incident influenza hospitalizations", target_units = "rate per 100,000 population",
target_keys = list(target = "inc hosp"), target_type = "discrete",
is_step_ahead = TRUE, time_unit = "week"), create_target_metadata_item(
target_id = "inc death", target_name = "Weekly incident influenza deaths",
target_units = "rate per 100,000 population", target_keys = list(target = "inc death"),
target_type = "discrete", is_step_ahead = TRUE, time_unit = "week"))),
verify_latest_schema_version(create_model_tasks(create_model_task(task_ids = create_task_ids(
create_task_id("origin_date", required = NULL, optional = c("2023-01-02",
"2023-01-09", "2023-01-16")), create_task_id("location", required = "US",
optional = c("01", "02", "04", "05", "06")), create_task_id("target",
required = NULL, optional = c("inc death", "inc hosp")), create_task_id(
"horizon", required = 1L, optional = 2:4)), output_type = create_output_type(
create_output_type_mean(is_required = TRUE, value_type = "double",
value_minimum = 0L), create_output_type_median(is_required = FALSE,
value_type = "double"), create_output_type_quantile(required = c(0.1, 0.2,
0.3, 0.4, 0.6, 0.7, 0.8, 0.9), is_required = TRUE, value_type = "double",
value_minimum = 0)), target_metadata = create_target_metadata(
create_target_metadata_item(target_id = "inc hosp", target_name = "Weekly incident influenza hospitalizations",
target_units = "rate per 100,000 population", target_keys = list(target = "inc hosp"),
target_type = "discrete", is_step_ahead = TRUE, time_unit = "week"),
create_target_metadata_item(target_id = "inc death", target_name = "Weekly incident influenza deaths",
target_units = "rate per 100,000 population", target_keys = list(target = "inc death"),
target_type = "discrete", is_step_ahead = TRUE, time_unit = "week"))),
create_model_task(task_ids = create_task_ids(create_task_id("origin_date",
required = NULL, optional = c("2023-01-02", "2023-01-09", "2023-01-16")),
create_task_id("location", required = "US", optional = c("01", "02", "04", "05",
Expand All @@ -126,7 +126,7 @@
target_metadata = create_target_metadata(create_target_metadata_item(target_id = "flu hosp rt chng",
target_name = "Weekly influenza hospitalization rate change", target_units = "rate per 100,000 population",
target_keys = list(target = "flu hosp rt chng"), target_type = "nominal",
is_step_ahead = TRUE, time_unit = "week"))))
is_step_ahead = TRUE, time_unit = "week")))))
Output
$model_tasks
$model_tasks[[1]]
Expand Down Expand Up @@ -363,7 +363,7 @@
attr(,"n")
[1] 2
attr(,"schema_id")
[1] "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.0/tasks-schema.json"
[1] "latest"
attr(,"branch")
[1] "main"

Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/_snaps/create_output_type.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# create_output_type functions work correctly

Code
create_output_type(create_output_type_mean(is_required = TRUE, value_type = "double",
value_minimum = 0L), create_output_type_median(is_required = FALSE,
value_type = "double"), create_output_type_quantile(required = c(0.1, 0.2,
0.3, 0.4, 0.6, 0.7, 0.8, 0.9), is_required = TRUE, value_type = "double",
value_minimum = 0))
verify_latest_schema_version(create_output_type(create_output_type_mean(
is_required = TRUE, value_type = "double", value_minimum = 0L),
create_output_type_median(is_required = FALSE, value_type = "double"),
create_output_type_quantile(required = c(0.1, 0.2, 0.3, 0.4, 0.6, 0.7, 0.8, 0.9),
is_required = TRUE, value_type = "double", value_minimum = 0)))
Output
$output_type
$output_type$mean
Expand Down Expand Up @@ -65,7 +65,7 @@
attr(,"n")
[1] 3
attr(,"schema_id")
[1] "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.0/tasks-schema.json"
[1] "latest"
attr(,"branch")
[1] "main"

Expand Down
Loading

0 comments on commit 3751927

Please sign in to comment.