4 gs <- read.delim("student_information.tsv")
6 colnames(d) <- c("student.num", "discord.name")
8 call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$"), function (x) {read.delim(x)[,1:4]}))
9 colnames(call.list) <- gsub("_", ".", colnames(call.list))
11 call.list$day <- as.Date(call.list$timestamp)
13 ## drop calls where the person wasn't present
14 call.list.full <- call.list
15 call.list[!call.list$answered,]
16 call.list <- call.list[call.list$answered,]
18 call.counts <- data.frame(table(call.list$discord.name))
19 colnames(call.counts) <- c("discord.name", "num.calls")
21 d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d
23 ## set anything that's missing to zero
24 d$num.calls[is.na(d$num.calls)] <- 0
26 attendance <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) {d <- read.delim(x); strsplit(d[[2]], ",")}))
28 file.to.attendance.list <- function (x) {
30 d.out <- data.frame(discord.name=unlist(strsplit(tmp[[2]], ",")))
31 d.out$day <- rep(as.Date(tmp[[1]][1]), nrow(d.out))
35 attendance <- do.call("rbind",
36 lapply(list.files(".", pattern="^attendance-.*tsv$"),
37 file.to.attendance.list))
39 ## create list of folks who are missing in class
40 missing.in.class <- call.list.full[is.na(call.list.full$answered) |
41 (!is.na(call.list.full$answered) & !call.list.full$answered),
42 c("discord.name", "day")]
44 missing.in.class <- unique(missing.in.class)
47 setkey(attendance, discord.name, day)
48 setDT(missing.in.class)
49 setkey(missing.in.class, discord.name, day)
51 ## drop presence for people on missing days
52 attendance[missing.in.class,]
53 attendance <- as.data.frame(attendance[!missing.in.class,])
55 attendance.counts <- data.frame(table(attendance$discord.name))
56 colnames(attendance.counts) <- c("discord.name", "num.present")
58 d <- merge(d, attendance.counts,
59 all.x=TRUE, all.y=TRUE,
62 days.list <- lapply(unique(attendance$day), function (day) {
63 day.total <- table(call.list.full$day == day)[["TRUE"]]
64 lapply(d$discord.name, function (discord.name) {
65 num.present <- nrow(attendance[attendance$day == day & attendance$discord.name == discord.name,])
66 if (num.present/day.total > 1) {print(day)}
67 data.frame(discord.name=discord.name,
68 days.present=(num.present/day.total))
72 days.tmp <- do.call("rbind", lapply(days.list, function (x) do.call("rbind", x)))
74 days.tbl <- tapply(days.tmp$days.present, days.tmp$discord.name, sum)
76 attendance.days <- data.frame(discord.name=names(days.tbl),
77 days.present=days.tbl,
78 days.absent=length(list.files(".", pattern="^attendance-.*tsv$"))-days.tbl)
80 d <- merge(d, attendance.days,
81 all.x=TRUE, all.y=TRUE, by="discord.name")
83 d[sort.list(d$days.absent), c("discord.name", "num.calls", "days.absent")]
85 ## make some visualizations of whose here/not here
86 #######################################################
88 png("questions_absence_histogram_combined.png", units="px", width=800, height=600)
91 aes(x=as.factor(num.calls), fill=days.absent, group=days.absent) +
92 geom_bar(color="black") +
93 scale_x_discrete("Number of questions asked") +
94 scale_y_continuous("Number of students") +
95 scale_fill_continuous("Days absent", low="red", high="blue")+
100 png("questions_absenses_boxplots.png", units="px", width=800, height=600)
103 aes(x=as.factor(num.calls), y=days.absent) +
105 scale_x_discrete("Number of questions asked") +
106 scale_y_continuous("Days absent")