-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgen_cal.R
99 lines (87 loc) · 3.06 KB
/
gen_cal.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
## Function for generating the first draft of the Biostat 620s TA calendar ##
## Need to run once for TA calendar, once for lab calendar! ##
## wd = working directory where you want the .csv files
## ta_names = vector of TA names (first name only) as character vector!!
## start_date = first day of TAing. MUST BE IN QUOTES, mm/dd/yy!
## end_date = last day of TAing. MUST BE IN QUOTES, mm/dd/yy!
## no_TA_dates = dates when no TA is needed (exam dates, day after exam, holidays, etc.
## must be as mm/dd/yy
## lab = TRUE/FALSE. Is this a lab calendar or a TA calendar?
## double_days = days when two TAs are needed. ONLY NEEDED FOR TA CALENDAR, NOT LAB CALENDAR!
# Once .csv files are created for each TA, go to [email protected] account,
# or [email protected] account. Create one calendar for each TA/lab instructor.
# Then import each CVS file into each TA calendar.
# Example values:
# ta_names<-c("Hilary","Kirsten","Marie")
# start_date="09/22/11"
# end_date="10/1/11"
# no_TA_dates=c("09/23/11","09/29/11")
# double_days=c("09/22/11","09/30/11")
# ta_location<-"TA Office Hour = W2021; STATA Office Hour = W3025"
# lab_location<-"W3031"
gen_cal<-function(wd,
ta_names,
start_date,
end_date,
no_TA_dates,
lab=TRUE,
ta_location=c(),
lab_location=c(),
double_days=c()
){
setwd(wd)
library(chron)
# Create dates vector #
dts <- seq.dates(start_date,end_date)
weekdts <- weekdays(dts)
dates <- dts[weekdts!="Sat" & weekdts!="Sun" & !as.character(dts)%in%no_TA_dates]
if(lab==FALSE){
dates <- c(dates,double_days)
}
dates <- sort(c(dates,dates))
len_dates <- length(dates)
len_tas <- length(ta_names)
mult <- floor(len_dates/len_tas)
# Assign TAs to dates #
temp <- rep(NA,len_tas)
ta_sched <- 0
for(i in 1:mult){
temp<-sample(ta_names,len_tas,replace=FALSE)
ta_sched<-c(ta_sched,temp)
}
ta_sched <- ta_sched[-1]
rem <- length(dates)-length(ta_sched)
temp <- sample(ta_names,rem,replace=FALSE)
ta_sched<-c(ta_sched,temp)
# Write schedule to dataframe and write to .csv file for import into google calendar #
nms<-c('Subject','Start Date','Start Time','End Date','End Time','All Day Event','Description','Location','Private')
len_names <- length(nms)
mat <- matrix(nrow=len_dates,ncol=len_names)
mat <- data.frame(mat)
colnames(mat)<-nms
mat$Subject <- ta_sched
mat$"Start Date" <- dates
mat$"End Date" <- dates
mat$"All Day Event" <- "False"
mat$Description <- "Biostat 621 TA Schedule"
mat$Private <- "False"
if(lab==TRUE){
start_times <- c("1:30:00 PM","3:00:00 PM")
end_times <- c("3:30:00 PM","5:00:00 PM")
mat$"Start Time" <- start_times
mat$"End Time" <- end_times
mat$Location <- lab_location
}
if(lab==FALSE){
start_times <- c("12:15:00 PM","2:30:00 PM")
end_times <- c("1:15:00 PM","3:20:00 PM")
mat$"Start Time" <- start_times
mat$"End Time" <- end_times
mat$Location <- ta_location
}
for(i in 1:len_tas){
filename<-paste(ta_names[i],".csv",sep="")
temp<-mat[mat$Subject==ta_names[i],]
write.csv(temp,file=filename,quote=FALSE,row.names=FALSE)
}
}