Skip to content

Commit

Permalink
if no end_date is set and the status is waiting, then the maximum of …
Browse files Browse the repository at this point in the history
…start_date + est_days and today is used, see #5
  • Loading branch information
MarselScheer committed Oct 2, 2019
1 parent 269a8a6 commit 2c8fd7a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 15 additions & 2 deletions R/h_wrangle.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test_h_wrangle.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2c8fd7a

Please sign in to comment.