Skip to content

Commit

Permalink
Merge pull request #519 from yjunechoe/interrogate-step-labels
Browse files Browse the repository at this point in the history
Interrogate step labels
  • Loading branch information
rich-iannone committed Feb 28, 2024
2 parents 28ca29e + 841f87d commit 19b4127
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
- `"{.seg_val}"`: The current segment's value/group

These dynamic values may be useful for validations that get expanded into multiple steps.

* `interrogate()` gains two new options for printing progress in the console output:

- `progress`: Whether interrogation progress should be printed to the console (`TRUE` for interactive sessions, same as before)
- `show_step_label`: Whether each validation step's label value should be printed alongside the progress.

## Minor improvements and bug fixes

Expand Down
52 changes: 43 additions & 9 deletions R/interrogate.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@
#' A value that limits the possible number of rows returned when sampling
#' non-passing rows using the `sample_frac` option.
#'
#' @param show_step_label *Show step labels in progress*
#'
#' `scalar<logical>` // *default:* `FALSE`
#'
#' Whether to show the `label` value of each validation step in the console.
#'
#' @param progress *Show interrogation progress*
#'
#' `scalar<logical>` // *default:* `interactive()`
#'
#' Whether to show the progress of an agent's interrogation in the console.
#' Defaults to `TRUE` in interactive sessions.
#'
#' @return A `ptblank_agent` object.
#'
#' @section Examples:
Expand Down Expand Up @@ -133,7 +146,9 @@ interrogate <- function(
get_first_n = NULL,
sample_n = NULL,
sample_frac = NULL,
sample_limit = 5000
sample_limit = 5000,
show_step_label = FALSE,
progress = interactive()
) {

#
Expand Down Expand Up @@ -199,7 +214,7 @@ interrogate <- function(

# Quieting of an agent's remarks either when the agent has the
# special label `"::QUIET::"` or the session is non-interactive
if (agent$label == "::QUIET::" || !interactive()) {
if (agent$label == "::QUIET::" || !progress) {
quiet <- TRUE
} else {
quiet <- FALSE
Expand Down Expand Up @@ -701,6 +716,7 @@ interrogate <- function(
agent = agent,
i = i,
time_diff_s = time_diff_s,
show_step_label = show_step_label,
quiet = quiet
)
}
Expand Down Expand Up @@ -795,6 +811,7 @@ create_post_step_cli_output_a <- function(
agent,
i,
time_diff_s,
show_step_label,
quiet
) {

Expand Down Expand Up @@ -831,6 +848,13 @@ create_post_step_cli_output_a <- function(
)) %>%
dplyr::pull(condition)

label <- agent$validation_set[i, ]$label
if (show_step_label && !is.na(label)) {
step_label <- paste0(" - {label}")
} else {
step_label <- NULL
}

cli::cli_div(
theme = list(
span.green = list(color = "green"),
Expand All @@ -845,26 +869,33 @@ create_post_step_cli_output_a <- function(
c(
"Step {.field {i}}: an evaluation issue requires attention ",
"(", interrogation_evaluation, ").",
print_time(time_diff_s)
print_time(time_diff_s),
step_label
)
)
} else if (validation_condition == "NONE" && notify_condition == "NONE") {
cli::cli_alert_success(
c("Step {.field {i}}: {.green OK}.", print_time(time_diff_s))
c(
"Step {.field {i}}: {.green OK}.",
print_time(time_diff_s),
step_label
)
)
} else if (validation_condition != "NONE" && notify_condition == "NONE") {
if (validation_condition == "STOP") {
cli::cli_alert_danger(
c(
"Step {.field {i}}: {.red STOP} condition met.",
print_time(time_diff_s)
print_time(time_diff_s),
step_label
)
)
} else {
cli::cli_alert_warning(
c(
"Step {.field {i}}: {.yellow WARNING} condition met.",
print_time(time_diff_s)
print_time(time_diff_s),
step_label
)
)
}
Expand All @@ -874,23 +905,26 @@ create_post_step_cli_output_a <- function(
c(
"Step {.field {i}}: {.red STOP} and ",
"{.blue NOTIFY} conditions met.",
print_time(time_diff_s)
print_time(time_diff_s),
step_label
)
)
} else {
cli::cli_alert_warning(
c(
"Step {.field {i}}: {.yellow WARNING} and ",
"{.blue NOTIFY} conditions met.",
print_time(time_diff_s)
print_time(time_diff_s),
step_label
)
)
}
} else if (validation_condition == "NONE" && notify_condition != "NONE") {
cli::cli_alert_warning(
c(
"Step {.field {i}}: {.blue NOTIFY} condition met.",
print_time(time_diff_s)
print_time(time_diff_s),
step_label
)
)
}
Expand Down
17 changes: 16 additions & 1 deletion man/interrogate.Rd

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

0 comments on commit 19b4127

Please sign in to comment.