Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Last active January 26, 2022 12:05
Show Gist options
  • Save explodecomputer/68341fa7b15d78200445c3dd99d3806a to your computer and use it in GitHub Desktop.
Save explodecomputer/68341fa7b15d78200445c3dd99d3806a to your computer and use it in GitHub Desktop.
group_agenda
library(lubridate)
library(dplyr)
library(knitr)
#' Create agenda
#'
#' Alternating weeks of Talks and Discussions.
#' Presenter for a talk leads discussion in the following week.
#'
#' @param start Start date in format "yyyy/mm/dd"
#' @param end End date in format "yyyy/mm/dd"
#' @param people Array of people
#'
#' @export
#' @return Data frame with dates, presenters and agenda
generate_agenda <- function(start, end, people)
{
a <- ymd(start)
ndays <- (ymd(end) - a) %>% as.numeric()
nweeks <- floor(ndays/7)
dates <- a + days(7 * 0:nweeks)
pres <- rep(people, times=ceiling(length(dates)/length(people)))[1:ceiling(length(dates)/2)]
dat <- tibble(
dates=dates,
presenter=rep(pres, each=2)[1:length(dates)],
what=rep(c("Talk", "Discussion"), ceiling(length(dates)/2))[1:length(dates)]
)
return(dat)
}
#' Reorder array to keep the presenting order but end with a given person
#'
#' @param people Array of people
#' @param who Who to end with
#'
#' @export
#' @return Array of people
reorder_people <- function(people, who)
{
i <- which(people == who)
if(i == length(people))
{
return(people)
}
people <- c(people[(i+1):length(people)], people[1:(i)])
return(people)
}
# People, with Sam first (thanks Sam)
set.seed(3141592)
people <- c("Sam", sample(c("Clare", "Yoonsu", "Giulio", "Gib", "Lily", "Tom", "Amanda")))
people
# Sam is presenting the first week
p1 <- generate_agenda("2022/02/01", "2022/02/14", "Sam")
# Gib not around during leave
p2 <- generate_agenda("2022/02/15", "2022/05/05", reorder_people(people[people != "Gib"], "Sam"))
# Gib back
p3 <- generate_agenda("2022/05/10", "2023/02/05", reorder_people(people, p2$presenter[nrow(p2)]))
bind_rows(p1, p2, p3) %>% as.data.frame()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment