Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check duration, addressing #66 #114

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: kyber
Title: Set Up Learning Cohorts on GitHub
Version: 0.1.0
Version: 0.1.0.9000
Authors@R:
c(person(given = "Sean",
family = "Kross",
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(add_gitignore)
export(add_team_members)
export(add_team_to_repo)
export(call_agenda)
export(check_duration)
export(create_batch_certificates)
export(create_certificate)
export(create_github_clinic)
Expand All @@ -19,6 +20,7 @@ export(md_agenda)
export(short_names)
import(knitr)
importFrom(cli,cli_abort)
importFrom(cli,cli_alert_info)
importFrom(dplyr,.data)
importFrom(dplyr,arrange)
importFrom(dplyr,filter)
Expand Down
34 changes: 4 additions & 30 deletions R/call_agenda.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,11 @@ call_agenda <- function(registry_url, cohort_id, call_number,
call = call_number)
cohort_name <- date_start <- type <- NULL

cohort_type_ <- cohort_registry %>%
filter(cohort_name == cohort_id) %>%
pull(cohort_type)

template_files <- call_registry %>%
filter(call == call_number) %>%
filter(cohort_type == cohort_type_) %>%
as.character() %>%
keep(~nzchar(file_ext(.x)))

not_rmd <- template_files %>%
file_ext() %>%
keep(nzchar) %>%
map_lgl(~!grepl("[R|r]md$", .x))

if(any(not_rmd)){
warning(paste(
"The following file(s) are not Rmd files which may cause errors:",
paste(template_files[not_rmd], collapse = ", ")
))
}

templates_installed <- (template_files %in% basename(kyber_file()))
cohort_type_ <- get_cohort_type(cohort_registry, cohort_id)
template_files <- get_template_files(call_registry, call_number, cohort_type_)

if(!all(templates_installed)){
stop(paste(
"The following template file(s) could not be found:",
paste(template_files[!templates_installed], collapse = ", ")
))
}
warn_if_any_not_rmd(template_files)
stop_if_any_templates_not_installed(template_files)

template_files <- template_files %>%
map_chr(kyber_file)
Expand Down Expand Up @@ -178,4 +153,3 @@ durations_to_start_times <- function(durations, start) {
#durations[durations == max(durations)] <- 0
start_time + minutes(cumsum(durations))
}

38 changes: 38 additions & 0 deletions R/check_duration.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#' Check the duration of call
#'
#' @inheritParams call_agenda
#' @importFrom cli cli_alert_info
#' @export
check_duration <- function(registry_url, cohort_id, call_number,
cohort_sheet = "cohort_metadata",
call_sheet = "call_metadata"){
cohort_registry <- read_sheet(registry_url, cohort_sheet, col_types = "c")
call_registry <- read_sheet(registry_url, call_sheet, col_types = "c")

cohort_type_ <- get_cohort_type(cohort_registry, cohort_id)
template_files <- get_template_files(call_registry, call_number, cohort_type_)

warn_if_any_not_rmd(template_files)
stop_if_any_templates_not_installed(template_files)

template_files <- template_files %>%
map_chr(kyber_file)

template_params <- template_files %>%
map(yaml_front_matter) %>%
map(~.x$params)

durations <- template_params %>%
map_dbl(~ ifelse(is.null(.x$duration), NA, .x$duration))

total_duration <- template_params %>%
map_dbl(~ ifelse(is.null(.x$total_duration), NA, .x$total_duration))

paste("Specified total duration:",
(list_flatten(template_params))$total_duration, "minutes") %>%
cli_alert_info()
paste("Calculated total duration:",
sum(durations, na.rm = TRUE), "minutes") %>%
cli_alert_info()
invisible()
}
39 changes: 39 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,42 @@ fmt_schedule_dates <- function(date_range){
map_chr(~ifelse(nchar(.x) == 1, paste0("0", .x), .x))
paste0(months_, "/", days_)
}

get_cohort_type <- function(cohort_registry, cohort_id) {
cohort_registry %>%
filter(cohort_name == cohort_id) %>%
pull(cohort_type)
}

get_template_files <- function(call_registry, call_number, cohort_type_) {
call_registry %>%
filter(call == call_number) %>%
filter(cohort_type == cohort_type_) %>%
as.character() %>%
keep(~nzchar(file_ext(.x)))
}

warn_if_any_not_rmd <- function(template_files) {
not_rmd <- template_files %>%
file_ext() %>%
keep(nzchar) %>%
map_lgl(~!grepl("[R|r]md$", .x))

if(any(not_rmd)){
warning(paste(
"The following file(s) are not Rmd files which may cause errors:",
paste(template_files[not_rmd], collapse = ", ")
))
}
}

stop_if_any_templates_not_installed <- function(template_files) {
templates_installed <- (template_files %in% basename(kyber_file()))

if(!all(templates_installed)){
stop(paste(
"The following template file(s) could not be found:",
paste(template_files[!templates_installed], collapse = ", ")
))
}
}
29 changes: 29 additions & 0 deletions man/check_duration.Rd

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

Loading