3 gs <- read.delim("student_information.tsv")
5 colnames(d) <- c("student.num", "discord.name")
7 call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$"), function (x) {read.delim(x)[,1:3]}))
8 colnames(call.list) <- gsub("_", ".", colnames(call.list))
10 call.list$day <- as.Date(call.list$timestamp)
12 ## drop calls where the person wasn't present
13 call.list[!call.list$answered,]
14 call.list <- call.list[call.list$answered,]
16 call.counts <- data.frame(table(call.list$discord.name))
17 colnames(call.counts) <- c("discord.name", "num.calls")
19 d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d
21 ## set anything that's missing to zero
22 d$num.calls[is.na(d$num.calls)] <- 0
24 attendance <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) {d <- read.delim(x); strsplit(d[[2]], ",")}))
27 file.to.attendance.list <- function (x) {
29 d.out <- data.frame(discord.name=unlist(strsplit(tmp[[2]], ",")))
30 d.out$day <- rep(as.Date(tmp[[1]][1]), nrow(d.out))
34 attendance <- do.call("rbind",
35 lapply(list.files(".", pattern="^attendance-.*tsv$"),
36 file.to.attendance.list))
38 attendance.counts <- data.frame(table(attendance$discord.name))
39 colnames(attendance.counts) <- c("discord.name", "num.present")
41 d <- merge(d, attendance.counts,
42 all.x=TRUE, all.y=TRUE,
45 days.list <- lapply(unique(attendance$day), function (day) {
46 day.total <- table(call.list$day == day)[["TRUE"]]
47 lapply(d$discord.name, function (discord.name) {
48 num.present <- nrow(attendance[attendance$day == day & attendance$discord.name == discord.name,])
49 data.frame(discord.name=discord.name,
50 days.present=(num.present/day.total))
54 days.tmp <- do.call("rbind", lapply(days.list, function (x) do.call("rbind", x)))
56 days.tbl <- tapply(days.tmp$days.present, days.tmp$discord.name, sum)
58 attendance.days <- data.frame(discord.name=names(days.tbl),
59 days.present=days.tbl,
60 days.absent=length(list.files(".", pattern="^attendance-.*tsv$"))-days.tbl)
62 d <- merge(d, attendance.days,
63 all.x=TRUE, all.y=TRUE, by="discord.name")
64 d[sort.list(d$days.absent), c("discord.name", "num.calls", "days.absent")]
66 ## make some visualizations of whose here/not here
67 #######################################################
69 png("questions_absence_histogram_combined.png", units="px", width=800, height=600)
72 aes(x=as.factor(num.calls), fill=days.absent, group=days.absent) +
73 geom_bar(color="black") +
74 scale_x_discrete("Number of questions asked") +
75 scale_y_continuous("Number of students") +
76 scale_fill_continuous("Days absent", low="red", high="blue")+
81 png("questions_absenses_boxplots.png", units="px", width=800, height=600)
84 aes(x=as.factor(num.calls), y=days.absent) +
86 scale_x_discrete("Number of questions asked") +
87 scale_y_continuous("Days absent")