1 setwd("~/online_communities/coldcallbot/data/")
6 gs <- read.delim("student_information.tsv")
8 colnames(d) <- c("student.num", "teams.name")
10 call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$"), function (x) {read.delim(x, stringsAsFactors=FALSE)[,1:4]}))
12 colnames(call.list) <- gsub("_", ".", colnames(call.list))
14 table(call.list$unique_name[call.list$answered])
18 call.list$day <- as.Date(call.list$timestamp)
20 ## drop calls where the person wasn't present
21 call.list.full <- call.list
22 call.list[!call.list$answered,]
23 call.list <- call.list[call.list$answered,]
25 call.counts <- data.frame(table(call.list$discord.name))
26 colnames(call.counts) <- c("discord.name", "num.calls")
28 d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d
30 ## set anything that's missing to zero
31 d$num.calls[is.na(d$num.calls)] <- 0
33 attendance <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) {d <- read.delim(x); strsplit(d[[2]], ",")}))
35 file.to.attendance.list <- function (x) {
37 d.out <- data.frame(discord.name=unlist(strsplit(tmp[[2]], ",")))
38 d.out$day <- rep(as.Date(tmp[[1]][1]), nrow(d.out))
42 attendance <- do.call("rbind",
43 lapply(list.files(".", pattern="^attendance-.*tsv$"),
44 file.to.attendance.list))
46 ## create list of folks who are missing in class
47 missing.in.class <- call.list.full[is.na(call.list.full$answered) |
48 (!is.na(call.list.full$answered) & !call.list.full$answered),
49 c("discord.name", "day")]
51 missing.in.class <- unique(missing.in.class)
54 setkey(attendance, discord.name, day)
55 setDT(missing.in.class)
56 setkey(missing.in.class, discord.name, day)
58 ## drop presence for people on missing days
59 attendance[missing.in.class,]
60 attendance <- as.data.frame(attendance[!missing.in.class,])
62 attendance.counts <- data.frame(table(attendance$discord.name))
63 colnames(attendance.counts) <- c("discord.name", "num.present")
65 d <- merge(d, attendance.counts,
66 all.x=TRUE, all.y=TRUE,
69 days.list <- lapply(unique(attendance$day), function (day) {
70 day.total <- table(call.list.full$day == day)[["TRUE"]]
71 lapply(d$discord.name, function (discord.name) {
72 num.present <- nrow(attendance[attendance$day == day & attendance$discord.name == discord.name,])
73 if (num.present/day.total > 1) {print(day)}
74 data.frame(discord.name=discord.name,
75 days.present=(num.present/day.total))
79 days.tmp <- do.call("rbind", lapply(days.list, function (x) do.call("rbind", x)))
81 days.tbl <- tapply(days.tmp$days.present, days.tmp$discord.name, sum)
83 attendance.days <- data.frame(discord.name=names(days.tbl),
84 days.present=days.tbl,
85 days.absent=length(list.files(".", pattern="^attendance-.*tsv$"))-days.tbl)
87 d <- merge(d, attendance.days,
88 all.x=TRUE, all.y=TRUE, by="discord.name")
90 d[sort.list(d$days.absent), c("discord.name", "num.calls", "days.absent")]
92 ## make some visualizations of whose here/not here
93 #######################################################
95 png("questions_absence_histogram_combined.png", units="px", width=800, height=600)
98 aes(x=as.factor(num.calls), fill=days.absent, group=days.absent) +
99 geom_bar(color="black") +
100 scale_x_discrete("Number of questions asked") +
101 scale_y_continuous("Number of students") +
102 scale_fill_continuous("Days absent", low="red", high="blue")+
107 png("questions_absenses_boxplots.png", units="px", width=800, height=600)
110 aes(x=as.factor(num.calls), y=days.absent) +
112 scale_x_discrete("Number of questions asked") +
113 scale_y_continuous("Days absent")