]> code.communitydata.science - coldcallbot-discord.git/blob - assessment_and_tracking/track_participation.R
added placeholder readme file
[coldcallbot-discord.git] / assessment_and_tracking / track_participation.R
1 library(ggplot2)
2 library(data.table)
3
4 gs <- read.delim("student_information.tsv")
5 d <- gs[,c(2,5)]
6 colnames(d) <- c("student.num", "discord.name")
7
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))
10
11 call.list$day <- as.Date(call.list$timestamp)
12
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,]
17
18 call.counts <- data.frame(table(call.list$discord.name))
19 colnames(call.counts) <- c("discord.name", "num.calls")
20
21 d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d
22
23 ## set anything that's missing to zero
24 d$num.calls[is.na(d$num.calls)] <- 0
25       
26 attendance <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) {d <- read.delim(x); strsplit(d[[2]], ",")}))
27
28 file.to.attendance.list <- function (x) {
29     tmp <- read.delim(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))
32     return(d.out)
33 }
34
35 attendance <- do.call("rbind",
36                       lapply(list.files(".", pattern="^attendance-.*tsv$"),
37                              file.to.attendance.list))
38
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")]
43
44 missing.in.class <- unique(missing.in.class)
45
46 setDT(attendance)
47 setkey(attendance, discord.name, day)
48 setDT(missing.in.class)
49 setkey(missing.in.class, discord.name, day)
50
51 ## drop presence for people on missing days
52 attendance[missing.in.class,]
53 attendance <- as.data.frame(attendance[!missing.in.class,])
54
55 attendance.counts <- data.frame(table(attendance$discord.name))
56 colnames(attendance.counts) <- c("discord.name", "num.present")
57
58 d <- merge(d, attendance.counts,
59            all.x=TRUE, all.y=TRUE,
60            by="discord.name")
61
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))
69     })
70 })
71
72 days.tmp <- do.call("rbind", lapply(days.list, function (x) do.call("rbind", x)))
73
74 days.tbl <- tapply(days.tmp$days.present, days.tmp$discord.name, sum)
75
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)
79
80 d <- merge(d, attendance.days,
81            all.x=TRUE, all.y=TRUE, by="discord.name")
82
83 d[sort.list(d$days.absent), c("discord.name", "num.calls", "days.absent")]
84
85 ## make some visualizations of whose here/not here
86 #######################################################
87
88 png("questions_absence_histogram_combined.png", units="px", width=800, height=600)
89
90 ggplot(d) +
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")+
96     theme_bw()
97
98 dev.off()
99
100 png("questions_absenses_boxplots.png", units="px", width=800, height=600)
101
102 ggplot(data=d) +
103     aes(x=as.factor(num.calls), y=days.absent) +
104     geom_boxplot() +
105     scale_x_discrete("Number of questions asked") +
106     scale_y_continuous("Days absent")
107
108 dev.off()
109

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