]> code.communitydata.science - coldcallbot-discord.git/blob - assessment_and_tracking/track_participation.R
small changes to get track participation working
[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)
15
16 call.list$day <- as.Date(call.list$timestamp)
17
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,]
22
23 call.counts <- data.frame(table(call.list$discord.name))
24 colnames(call.counts) <- c("discord.name", "num.calls")
25
26 d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d
27
28 ## set anything that's missing to zero
29 d$num.calls[is.na(d$num.calls)] <- 0
30       
31 attendance <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) {d <- read.delim(x); strsplit(d[[2]], ",")}))
32
33 file.to.attendance.list <- function (x) {
34     tmp <- read.delim(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))
37     return(d.out)
38 }
39
40 attendance <- do.call("rbind",
41                       lapply(list.files(".", pattern="^attendance-.*tsv$"),
42                              file.to.attendance.list))
43
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")]
48
49 missing.in.class <- unique(missing.in.class)
50
51 setDT(attendance)
52 setkey(attendance, discord.name, day)
53 setDT(missing.in.class)
54 setkey(missing.in.class, discord.name, day)
55
56 ## drop presence for people on missing days
57 attendance[missing.in.class,]
58 attendance <- as.data.frame(attendance[!missing.in.class,])
59
60 attendance.counts <- data.frame(table(attendance$discord.name))
61 colnames(attendance.counts) <- c("discord.name", "num.present")
62
63 d <- merge(d, attendance.counts,
64            all.x=TRUE, all.y=TRUE,
65            by="discord.name")
66
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))
74     })
75 })
76
77 days.tmp <- do.call("rbind", lapply(days.list, function (x) do.call("rbind", x)))
78
79 days.tbl <- tapply(days.tmp$days.present, days.tmp$discord.name, sum)
80
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)
84
85 d <- merge(d, attendance.days,
86            all.x=TRUE, all.y=TRUE, by="discord.name")
87
88 d[sort.list(d$days.absent), c("discord.name", "num.calls", "days.absent")]
89
90 ## make some visualizations of whose here/not here
91 #######################################################
92
93 png("questions_absence_histogram_combined.png", units="px", width=800, height=600)
94
95 ggplot(d) +
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")+
101     theme_bw()
102
103 dev.off()
104
105 png("questions_absenses_boxplots.png", units="px", width=800, height=600)
106
107 ggplot(data=d) +
108     aes(x=as.factor(num.calls), y=days.absent) +
109     geom_boxplot() +
110     scale_x_discrete("Number of questions asked") +
111     scale_y_continuous("Days absent")
112
113 dev.off()
114

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