Skip to content

Commit

Permalink
updating with flattening of schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
bomeara committed Feb 11, 2020
1 parent 95841c3 commit f612651
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(availability_fill)
export(guest_availability)
export(host_import)
export(possible_availability_create)
export(schedule_flatten)
export(schedule_summary)
export(time_interpolate)
export(times_format)
32 changes: 28 additions & 4 deletions R/schedule.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ availability_fill <- function(possible_availability, guests, desired_length=60,
return(possible_availability)
}

#' Convert schedule to easier information
#' Convert schedule to easier information for a person
#' @param person The person to make the schedule for
#' @param availability_array 3d array of availability with entries 0, 1, and 2
#' @param is_host If TRUE, do for host; otherwise, do guest
#' @param host_rooms The vector of host rooms: room is entry, host name is names
#' @return A data.frame of times, the person being met, and the room
#' @export
schedule_summary <- function(person, availability_array, is_host=TRUE, host_rooms) {
schedule_summary <- function(person, availability_array, is_host=TRUE, host_rooms=NULL) {
local_schedule <- data.frame()
if(is_host) {
local_schedule <- availability_array[person, ,]
Expand All @@ -129,13 +129,13 @@ schedule_summary <- function(person, availability_array, is_host=TRUE, host_room
matching_people <- names(which(local_schedule[,col_index]==2))
simple_schedule$Person[col_index] <- paste0(matching_people, collapse=", ")
if(is_host) {
if (length(matching_people)>0) {
if (length(matching_people)>0 & !is.null(host_rooms)) {
simple_schedule$Room[col_index] <- host_rooms[person]
} else {
simple_schedule$Room[col_index] <- ""
}
} else {
if (length(matching_people)>0) {
if (length(matching_people)>0 & !is.null(host_rooms)) {
simple_schedule$Room[col_index] <- host_rooms[matching_people[1]]
} else {
simple_schedule$Room[col_index] <- ""
Expand All @@ -144,3 +144,27 @@ schedule_summary <- function(person, availability_array, is_host=TRUE, host_room
}
return(simple_schedule)
}

#' Flatten everyone's schedules to one data.frame
#' @param availability_array 3d array of availability with entries 0, 1, and 2
#' @param is_host If TRUE, do for host; otherwise, do guest
#' @return a data.frame of times and who each person (host or guest) is meeting with at each time
#' @export
schedule_flatten <- function(availability_array, is_host=TRUE) {
people <- c()
if(is_host) {
people <- dimnames(availability_array)$host
} else {
people <- dimnames(availability_array)$guest
}
people <- sort(people)
schedule_flat <- data.frame(Times=dimnames(availability_array)$times, stringsAsFactors=FALSE)
for (i in seq_along(people)) {
local_schedule <- schedule_summary(person=people[i], availability_array=availability_array, is_host=is_host)
if(max(nchar(local_schedule$Person))>0) { #So, toss a person if they have no meetings
schedule_flat$NewPerson <- local_schedule$Person
colnames(schedule_flat)[ncol(schedule_flat)] <- people[i]
}
}
return(schedule_flat)
}
19 changes: 19 additions & 0 deletions man/schedule_flatten.Rd

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

6 changes: 3 additions & 3 deletions man/schedule_summary.Rd

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

0 comments on commit f612651

Please sign in to comment.