-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Infectious-Disease-Modeling-Hubs/validate_pr
[WIP] Add validate_pr fn
- Loading branch information
Showing
70 changed files
with
2,602 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#' Check hub correctly configured | ||
#' | ||
#' Checks that `admin` and `tasks` configuration files in directory `hub-config` | ||
#' are valid. | ||
#' @inherit check_valid_round_id return params | ||
#' | ||
#' @export | ||
check_config_hub_valid <- function(hub_path) { | ||
valid_config <- hubUtils::validate_hub_config(hub_path) %>% | ||
suppressMessages() %>% | ||
suppressWarnings() | ||
|
||
check <- all(unlist(valid_config)) | ||
|
||
if (check) { | ||
details <- NULL | ||
} else { | ||
details <- cli::format_inline( | ||
"Config file{?s} {.val {names(valid_config)[!unlist(valid_config)]}} invalid." | ||
) | ||
} | ||
|
||
capture_check_cnd( | ||
check = check, | ||
file_path = basename(hub_path), | ||
msg_subject = "All hub config files", | ||
msg_attribute = "valid.", | ||
msg_verbs = c("are", "must be"), | ||
error = TRUE, | ||
details = details | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#' Raise conditions stored in a `hub_validations` object | ||
#' | ||
#' This is meant to be used in CI workflows to raise conditions from | ||
#' `hub_validations` objects. | ||
#' | ||
#' @param x A `hub_validations` object | ||
#' | ||
#' @return An error if one of the elements of `x` is of class `check_failure`, | ||
#' `check_error`, `check_exec_error` or `check_exec_warning`. | ||
#' `TRUE` invisibly otherwise. | ||
#' | ||
#' @export | ||
check_for_errors <- function(x) { | ||
flag_checks <- x[purrr::map_lgl(x, ~not_pass(.x))] | ||
|
||
class(flag_checks) <- c("hub_validations", "list") | ||
|
||
if (length(flag_checks) > 0) { | ||
print(flag_checks) | ||
rlang::abort( | ||
"\nThe validation checks produced some failures/errors reported above." | ||
) | ||
} | ||
|
||
return(invisible(TRUE)) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#' Checks submission is within the valid submission window for a given round. | ||
#' | ||
#' @inherit check_tbl_col_types params return | ||
#' | ||
#' @importFrom lubridate %within% | ||
#' @export | ||
check_submission_time <- function(hub_path, file_path) { | ||
config_tasks <- hubUtils::read_config(hub_path, "tasks") | ||
submission_config <- get_file_round_config(file_path, hub_path)[["submissions_due"]] | ||
hub_tz <- get_hub_timezone(hub_path) | ||
|
||
if (!is.null(submission_config[["relative_to"]])) { | ||
tbl <- read_model_out_file( | ||
file_path = file_path, | ||
hub_path = hub_path | ||
) | ||
relative_date <- as.Date( | ||
unique(tbl[[submission_config[["relative_to"]]]]) | ||
) | ||
submission_window <- get_submission_window( | ||
start = relative_date + submission_config[["start"]], | ||
end = relative_date + submission_config[["end"]], | ||
hub_tz | ||
) | ||
} else { | ||
submission_window <- get_submission_window( | ||
start = submission_config[["start"]], | ||
end = submission_config[["end"]], | ||
hub_tz | ||
) | ||
} | ||
check <- Sys.time() %within% submission_window | ||
|
||
if (check) { | ||
details <- NULL | ||
} else { | ||
details <- cli::format_inline( | ||
"Current time {.val {Sys.time()}} is outside window {.val {submission_window}}." | ||
) | ||
} | ||
|
||
capture_check_cnd( | ||
check = check, | ||
file_path = file_path, | ||
msg_subject = "Submission time", | ||
msg_attribute = "within accepted submission window for round.", | ||
details = details | ||
) | ||
} | ||
|
||
get_submission_window <- function(start, end, hub_tz) { | ||
submit_window_start <- lubridate::ymd(start, tz = hub_tz) | ||
submit_window_end <- lubridate::ymd_hms(paste(end, "23:59:59"), | ||
tz = hub_tz | ||
) | ||
|
||
lubridate::interval( | ||
start = submit_window_start, | ||
end = submit_window_end | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#' Check model output data tbl round ID matches submission round ID. | ||
#' | ||
#' @inherit check_tbl_unique_round_id params details return | ||
#' @export | ||
check_tbl_match_round_id <- function(tbl, file_path, hub_path, | ||
round_id_col = NULL) { | ||
check_round_id_col <- check_valid_round_id_col( | ||
tbl, file_path, hub_path, round_id_col) | ||
|
||
if (is_info(check_round_id_col)) { | ||
return(check_round_id_col) | ||
} | ||
if (is_failure(check_round_id_col)) { | ||
class(check_round_id_col)[1] <- "check_error" | ||
check_round_id_col$call <- rlang::call_name(rlang::current_call()) | ||
return(check_round_id_col) | ||
} | ||
|
||
if (is.null(round_id_col)) { | ||
round_id_col <- get_file_round_id_col(file_path, hub_path) | ||
} | ||
round_id <- parse_file_name(file_path)$round_id | ||
|
||
round_id_match <- tbl[[round_id_col]] == round_id | ||
check <- all(round_id_match) | ||
|
||
if (check) { | ||
details <- NULL | ||
} else { | ||
unmatched_round_ids <- unique(tbl[[round_id_col]][!round_id_match]) | ||
details <- cli::format_inline( | ||
"{.var round_id} {cli::qty(length(unmatched_round_ids))} | ||
value{?s} {.val {unmatched_round_ids}} {?does/do} not match | ||
submission {.var round_id} {.val {round_id}}" | ||
) | ||
} | ||
|
||
capture_check_cnd( | ||
check = check, | ||
file_path = file_path, | ||
msg_subject = cli::format_inline( | ||
"All {.var round_id_col} {.val {round_id_col}} values" | ||
), | ||
msg_attribute = "submission {.var round_id} from file name.", | ||
msg_verbs = c("match", "must match"), | ||
error = TRUE, | ||
details = details | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.