From 2c8fd7a77931df84ed327516cc24533405d12201 Mon Sep 17 00:00:00 2001 From: m Date: Wed, 2 Oct 2019 23:24:49 +0200 Subject: [PATCH] if no end_date is set and the status is waiting, then the maximum of start_date + est_days and today is used, see #5 --- R/h_wrangle.R | 17 +++++++++++++++-- tests/testthat/test_h_wrangle.R | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/R/h_wrangle.R b/R/h_wrangle.R index 1356a2b..3bec139 100644 --- a/R/h_wrangle.R +++ b/R/h_wrangle.R @@ -56,11 +56,12 @@ wrangle_raw_plan <- function(df, date_origin = "1899-12-30") { df <- h.rd_fill_with_default(df, "progress", "0") df$progress <- as.numeric(df$progress) + df <- h.rd_preprocess_status_column(df) df <- h.rd_preprocess_depends_on_column(df) df <- h.rd_preprocess_start_column(df, date_origin = date_origin) - df <- h.rd_preprocess_end_column(df, date_origin = date_origin) df <- h.rd_preprocess_est_duration_column(df) - df <- h.rd_preprocess_status_column(df) + df <- h.rd_preprocess_end_column(df, date_origin = date_origin) + df <- h.rd_preprocess_deadline_column(df, date_origin = date_origin) h.rd_check_project_section_id_unique(df) @@ -366,6 +367,18 @@ h.rd_preprocess_end_column <- function(df, date_origin) { df$end <- h.convert_numeric_date(df$end, date_origin = date_origin) df$fixed_end_date <- suppressWarnings(lubridate::ymd(df$end)) + TODAY <- lubridate::as_date(lubridate::now()) + + idx <- !is.na(df$fixed_end_date) & df$waiting + if (any(idx)) { + h.log_rows( + df, + idx, + warn_msg = glue::glue("Some entries have an -end_date- AND are in waiting status.") + ) + } + + df$fixed_end_date[is.na(df$fixed_end_date) & df$waiting] <- pmax(df$fixed_start_date + df$est_days, TODAY) df$end <- NULL h.log_end() diff --git a/tests/testthat/test_h_wrangle.R b/tests/testthat/test_h_wrangle.R index 7f05f8c..b0fb865 100644 --- a/tests/testthat/test_h_wrangle.R +++ b/tests/testthat/test_h_wrangle.R @@ -36,8 +36,9 @@ test_that( ) -d_in <- data.table::data.table(end = c("2018-09-20", "WAIT", "43530")) +d_in <- data.table::data.table(end = c("2018-09-20", "WAIT", "43530"), waiting = c(F, F, F)) d_expected <- data.table::data.table( + waiting = c(F, F, F), fixed_end_date = c(lubridate::ymd("2018-09-20"), NA, lubridate::ymd("2019-03-06")) ) test_that(