]> code.communitydata.science - coldcallbot-discord.git/blob - data/track_participation.R
8bce2e5def22837079349740ca86b27c93064666
[coldcallbot-discord.git] / data / track_participation.R
1 library(ggplot2)
2
3 gs <- read.delim("student_information.tsv")
4 d <- gs[,c(2,5)]
5 colnames(d) <- c("student.num", "discord.name")
6
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))
9
10 call.list$day <- as.Date(call.list$timestamp)
11
12 ## drop calls where the person wasn't present
13 call.list[!call.list$answered,]
14 call.list <- call.list[call.list$answered,]
15
16 call.counts <- data.frame(table(call.list$discord.name))
17 colnames(call.counts) <- c("discord.name", "num.calls")
18
19 d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d
20
21 ## set anything that's missing to zero
22 d$num.calls[is.na(d$num.calls)] <- 0
23       
24 attendance <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) {d <- read.delim(x); strsplit(d[[2]], ",")}))
25
26
27 file.to.attendance.list <- function (x) {
28     tmp <- read.delim(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))
31     return(d.out)
32 }
33
34 attendance <- do.call("rbind",
35                       lapply(list.files(".", pattern="^attendance-.*tsv$"),
36                              file.to.attendance.list))
37
38 attendance.counts <- data.frame(table(attendance$discord.name))
39 colnames(attendance.counts) <- c("discord.name", "num.present")
40
41 d <- merge(d, attendance.counts,
42            all.x=TRUE, all.y=TRUE,
43            by="discord.name")
44
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))
51     })
52 })
53
54 days.tmp <- do.call("rbind", lapply(days.list, function (x) do.call("rbind", x)))
55
56 days.tbl <- tapply(days.tmp$days.present, days.tmp$discord.name, sum)
57
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)
61
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")]
65
66 ## make some visualizations of whose here/not here
67 #######################################################
68
69 png("questions_absence_histogram_combined.png", units="px", width=800, height=600)
70
71 ggplot(d) +
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")+
77     theme_bw()
78
79 dev.off()
80
81 png("questions_absenses_boxplots.png", units="px", width=800, height=600)
82
83 ggplot(data=d) +
84     aes(x=as.factor(num.calls), y=days.absent) +
85     geom_boxplot() +
86     scale_x_discrete("Number of questions asked") +
87     scale_y_continuous("Days absent")
88
89 dev.off()
90

Community Data Science Collective || Want to submit a patch?