Skip to content

Commit

Permalink
Update fileSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmcd18 committed Oct 30, 2024
1 parent 56e4965 commit 9079dac
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 46 deletions.
92 changes: 48 additions & 44 deletions R/fileSummary.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#' fileSummary("script/data-assembly/study-101.R")
#'
#' # Process all files in a directory
#' purrr::walk(list.files("script/data-assembly"), ~ fileSummary(.x))
#' purrr::walk(list.files("script/data-assembly", full.names = TRUE), ~ fileSummary(.file = .x))
#' }
#'
#' @export
Expand All @@ -42,6 +42,9 @@ fileSummary <- function(.file) {

# Initialize output list
out <- list()
out$qclog <- cli::col_red("No")
out$qcstatus <- cli::col_magenta("Not assigned")
out$prevQC <- "No previous QC"

# Get repo history and QC log
file_history <- repoHistory()
Expand All @@ -63,48 +66,49 @@ fileSummary <- function(.file) {

# Check if file is in QC log
if (nrow(qc_file) > 0) {
out$qclog <- cli::col_green("Yes")
} else {
out$qclog <- cli::col_red("No")
out$qcstatus <- cli::col_magenta("Not assigned")
}

# Process QC history
qc_file_filtered <- qc_file %>% dplyr::filter(revf != 0)

if (nrow(qc_file_filtered) > 0) {

qc_rev <-
qc_file_filtered %>%
dplyr::arrange(-as.numeric(revf)) %>%
dplyr::slice(1) %>%
dplyr::pull(revf) %>%
as.numeric()
out$qclog <- cli::col_green("Yes")

out$prevQC <-
qc_file_filtered %>%
dplyr::arrange(-as.numeric(revf)) %>%
dplyr::group_by(reviewer) %>%
dplyr::slice(1) %>%
dplyr::ungroup() %>%
dplyr::transmute(VALUE = paste0(
reviewer, ", ",
as.numeric(difftime(Sys.Date(), as.Date(time), units = "days")),
" days ago"
)) %>%
dplyr::pull()
# Process QC history
qc_file_filtered <- qc_file %>% dplyr::filter(revf != 0)

out$qcstatus <-
ifelse(
last_rev > qc_rev,
cli::col_red("Needs QC"),
cli::col_green("QC up to date")
)
# For cases where no QC has been previously completed
if (nrow(qc_file_filtered) == 0) {

out$qcstatus <- cli::col_red("Needs QC")

} else {

qc_rev <-
qc_file_filtered %>%
dplyr::arrange(-as.numeric(revf)) %>%
dplyr::slice(1) %>%
dplyr::pull(revf) %>%
as.numeric()

out$prevQC <-
qc_file_filtered %>%
dplyr::arrange(-as.numeric(revf)) %>%
dplyr::group_by(reviewer) %>%
dplyr::slice(1) %>%
dplyr::ungroup() %>%
dplyr::transmute(VALUE = paste0(
reviewer, ", ",
as.numeric(difftime(Sys.Date(), as.Date(time), units = "days")),
" days ago"
)) %>%
dplyr::pull()

out$qcstatus <-
ifelse(
last_rev > qc_rev,
cli::col_red("Needs QC"),
cli::col_green("QC up to date")
)

}

} else {
out$qcstatus <- cli::col_red("Needs QC")
out$prevQC <- "No previous QC"
}
}

# Process author history
out$authors <-
Expand All @@ -125,15 +129,15 @@ fileSummary <- function(.file) {
cli::cli_inform(glue::glue("In QC log: ", out$qclog))
cli::cli_inform(glue::glue("QC status: ", out$qcstatus))

cli::cli_verbatim("") # line break
cli::cli_inform("Previous author(s): ")
names(out$authors) <- rep(">", length(out$authors))
cli::cli_bullets(out$authors)

cli::cli_verbatim("") # line break
cli::cli_inform("Previous QCer(s): ")
names(out$prevQC) <- rep(">", length(out$prevQC))
cli::cli_bullets(out$prevQC)

cli::cli_verbatim("") # line break
cli::cli_inform("Previous author(s): ")
names(out$authors) <- rep(">", length(out$authors))
cli::cli_bullets(out$authors)

return(invisible(out))
}
2 changes: 1 addition & 1 deletion man/fileSummary.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-fileSummary.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test_that("Output structure is correct for non QCed file", {

expect_true(grepl("No", as.character(da_study_abc$qclog)))
expect_true(grepl("No previous QC", as.character(da_study_abc$prevQC)))
expect_true(grepl("Needs QC", as.character(da_study_abc$qcstatus)))
expect_true(grepl("Not assigned", as.character(da_study_abc$qcstatus)))
})

test_that("Function handles non-existent files appropriately", {
Expand Down

0 comments on commit 9079dac

Please sign in to comment.