]> code.communitydata.science - coldcallbot-discord.git/blob - assessment_and_tracking/track_participation.R
report on the number of questions answered, not just asked
[coldcallbot-discord.git] / assessment_and_tracking / track_participation.R
1 setwd("~/online_communities/coldcallbot/data/")
2
3 library(ggplot2)
4 library(data.table)
5
6 gs <- read.delim("student_information.tsv")
7 d <- gs[,c(2,4)]
8 colnames(d) <- c("student.num", "teams.name")
9
10 call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$"), function (x) {read.delim(x, stringsAsFactors=FALSE)[,1:4]}))
11
12 colnames(call.list) <- gsub("_", ".", colnames(call.list))
13
14 table(call.list$unique_name[call.list$answered])
15
16 exit()
17
18 call.list$day <- as.Date(call.list$timestamp)
19
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,]
24
25 call.counts <- data.frame(table(call.list$discord.name))
26 colnames(call.counts) <- c("discord.name", "num.calls")
27
28 d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d
29
30 ## set anything that's missing to zero
31 d$num.calls[is.na(d$num.calls)] <- 0
32       
33 attendance <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) {d <- read.delim(x); strsplit(d[[2]], ",")}))
34
35 file.to.attendance.list <- function (x) {
36     tmp <- read.delim(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))
39     return(d.out)
40 }
41
42 attendance <- do.call("rbind",
43                       lapply(list.files(".", pattern="^attendance-.*tsv$"),
44                              file.to.attendance.list))
45
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")]
50
51 missing.in.class <- unique(missing.in.class)
52
53 setDT(attendance)
54 setkey(attendance, discord.name, day)
55 setDT(missing.in.class)
56 setkey(missing.in.class, discord.name, day)
57
58 ## drop presence for people on missing days
59 attendance[missing.in.class,]
60 attendance <- as.data.frame(attendance[!missing.in.class,])
61
62 attendance.counts <- data.frame(table(attendance$discord.name))
63 colnames(attendance.counts) <- c("discord.name", "num.present")
64
65 d <- merge(d, attendance.counts,
66            all.x=TRUE, all.y=TRUE,
67            by="discord.name")
68
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))
76     })
77 })
78
79 days.tmp <- do.call("rbind", lapply(days.list, function (x) do.call("rbind", x)))
80
81 days.tbl <- tapply(days.tmp$days.present, days.tmp$discord.name, sum)
82
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)
86
87 d <- merge(d, attendance.days,
88            all.x=TRUE, all.y=TRUE, by="discord.name")
89
90 d[sort.list(d$days.absent), c("discord.name", "num.calls", "days.absent")]
91
92 ## make some visualizations of whose here/not here
93 #######################################################
94
95 png("questions_absence_histogram_combined.png", units="px", width=800, height=600)
96
97 ggplot(d) +
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")+
103     theme_bw()
104
105 dev.off()
106
107 png("questions_absenses_boxplots.png", units="px", width=800, height=600)
108
109 ggplot(data=d) +
110     aes(x=as.factor(num.calls), y=days.absent) +
111     geom_boxplot() +
112     scale_x_discrete("Number of questions asked") +
113     scale_y_continuous("Days absent")
114
115 dev.off()
116

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