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)
16 call.list$day <- as.Date(call.list$timestamp)
18 ## drop calls where the person wasn't present
19 call.list.full <- call.list
20 call.list[!call.list$answered,]
21 call.list <- call.list[call.list$answered,]
23 call.counts <- data.frame(table(call.list$discord.name))
24 colnames(call.counts) <- c("discord.name", "num.calls")
26 d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d
28 ## set anything that's missing to zero
29 d$num.calls[is.na(d$num.calls)] <- 0
31 attendance <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) {d <- read.delim(x); strsplit(d[[2]], ",")}))
33 file.to.attendance.list <- function (x) {
35 d.out <- data.frame(discord.name=unlist(strsplit(tmp[[2]], ",")))
36 d.out$day <- rep(as.Date(tmp[[1]][1]), nrow(d.out))
40 attendance <- do.call("rbind",
41 lapply(list.files(".", pattern="^attendance-.*tsv$"),
42 file.to.attendance.list))
44 ## create list of folks who are missing in class
45 missing.in.class <- call.list.full[is.na(call.list.full$answered) |
46 (!is.na(call.list.full$answered) & !call.list.full$answered),
47 c("discord.name", "day")]
49 missing.in.class <- unique(missing.in.class)
52 setkey(attendance, discord.name, day)
53 setDT(missing.in.class)
54 setkey(missing.in.class, discord.name, day)
56 ## drop presence for people on missing days
57 attendance[missing.in.class,]
58 attendance <- as.data.frame(attendance[!missing.in.class,])
60 attendance.counts <- data.frame(table(attendance$discord.name))
61 colnames(attendance.counts) <- c("discord.name", "num.present")
63 d <- merge(d, attendance.counts,
64 all.x=TRUE, all.y=TRUE,
67 days.list <- lapply(unique(attendance$day), function (day) {
68 day.total <- table(call.list.full$day == day)[["TRUE"]]
69 lapply(d$discord.name, function (discord.name) {
70 num.present <- nrow(attendance[attendance$day == day & attendance$discord.name == discord.name,])
71 if (num.present/day.total > 1) {print(day)}
72 data.frame(discord.name=discord.name,
73 days.present=(num.present/day.total))
77 days.tmp <- do.call("rbind", lapply(days.list, function (x) do.call("rbind", x)))
79 days.tbl <- tapply(days.tmp$days.present, days.tmp$discord.name, sum)
81 attendance.days <- data.frame(discord.name=names(days.tbl),
82 days.present=days.tbl,
83 days.absent=length(list.files(".", pattern="^attendance-.*tsv$"))-days.tbl)
85 d <- merge(d, attendance.days,
86 all.x=TRUE, all.y=TRUE, by="discord.name")
88 d[sort.list(d$days.absent), c("discord.name", "num.calls", "days.absent")]
90 ## make some visualizations of whose here/not here
91 #######################################################
93 png("questions_absence_histogram_combined.png", units="px", width=800, height=600)
96 aes(x=as.factor(num.calls), fill=days.absent, group=days.absent) +
97 geom_bar(color="black") +
98 scale_x_discrete("Number of questions asked") +
99 scale_y_continuous("Number of students") +
100 scale_fill_continuous("Days absent", low="red", high="blue")+
105 png("questions_absenses_boxplots.png", units="px", width=800, height=600)
108 aes(x=as.factor(num.calls), y=days.absent) +
110 scale_x_discrete("Number of questions asked") +
111 scale_y_continuous("Days absent")