Skip to content

Commit 18d8391

Browse files
committed
fix: improve get_targets_errors (shorter name)
1 parent f3899e4 commit 18d8391

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

R/utils.R

+8-10
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,13 @@ sort_by_quantile <- function(forecasts) {
479479

480480

481481
#' Print recent targets errors.
482-
get_recent_targets_errors <- function(time_since = minutes(60)) {
483-
meta_df <- targets::tar_meta()
482+
get_targets_errors <- function(project = tar_path_store(), top_n = 10) {
483+
meta_df <- targets::tar_meta(store = project)
484484
forecast_errors <- meta_df %>%
485-
filter(time > Sys.time() - time_since, !is.na(parent), !is.na(error)) %>%
486-
arrange(desc(time)) %>%
485+
filter(!is.na(parent), !is.na(error)) %>%
487486
distinct(parent, error, .keep_all = TRUE) %>%
488-
select(time, parent, error) %>%
489-
mutate(parent = gsub("forecast_", "", parent))
487+
mutate(parent = gsub("forecast_", "", parent)) %>%
488+
slice_max(time, n = top_n)
490489

491490
# Print each error message, along with the parent target.
492491
if (nrow(forecast_errors) > 0) {
@@ -501,10 +500,9 @@ get_recent_targets_errors <- function(time_since = minutes(60)) {
501500
}
502501

503502
other_errors <- meta_df %>%
504-
filter(time > Sys.time() - time_since, !is.na(error)) %>%
505-
arrange(desc(time)) %>%
503+
filter(!is.na(error)) %>%
506504
distinct(error, .keep_all = TRUE) %>%
507-
select(time, name, error)
505+
slice_max(time, n = top_n)
508506

509507
# Print each error message, along with the parent target.
510508
if (nrow(other_errors) > 0) {
@@ -518,7 +516,7 @@ get_recent_targets_errors <- function(time_since = minutes(60)) {
518516
}
519517
}
520518

521-
return(invisible(meta_df %>% filter(time > Sys.time() - time_since)))
519+
return(invisible(meta_df %>% slice_max(time, n = top_n)))
522520
}
523521

524522
#' Retry a function.

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ make prod-flu
5050
make prod-covid
5151

5252
# The job output can be found in nohup.out
53-
# If there are errors, you can view them with the following command (replace with appropriate project)
54-
Sys.setenv(TAR_PROJECT = "covid_hosp_prod");
55-
targets::tar_meta(fields = error, complete_only = FALSE)
53+
# If there are errors, you can view the top n with the following command (replace with appropriate project)
54+
source("scripts/targets-common.R");
55+
get_targets_errors("covid_hosp_prod", top_n = 10)
5656

5757
# Automatically append the new reports to the site index and host the site on netlify
5858
# (this requires the netlify CLI to be installed and configured, talk to Dmitry about this)

0 commit comments

Comments
 (0)