]> code.communitydata.science - coldcallbot-discord.git/blobdiff - data/track_participation.R
updated with final participation grades (
[coldcallbot-discord.git] / data / track_participation.R
index f616d213a4bd451986c1d6e249e244a2a14d448e..9a51084d2f5effd1cb2d30dbf02f4efe5fae60cd 100644 (file)
@@ -1,14 +1,20 @@
 library(ggplot2)
+library(data.table)
 
 gs <- read.delim("student_information.tsv")
 d <- gs[,c(2,5)]
 colnames(d) <- c("student.num", "discord.name")
 
-call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$"), function (x) {read.delim(x)[,1:3]}))
+call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$"), function (x) {read.delim(x)[,1:4]}))
 colnames(call.list) <- gsub("_", ".", colnames(call.list))
 
 call.list$day <- as.Date(call.list$timestamp)
 
+## drop calls where the person wasn't present
+call.list.full <- call.list
+call.list[!call.list$answered,]
+call.list <- call.list[call.list$answered,]
+
 call.counts <- data.frame(table(call.list$discord.name))
 colnames(call.counts) <- c("discord.name", "num.calls")
 
@@ -19,7 +25,6 @@ d$num.calls[is.na(d$num.calls)] <- 0
       
 attendance <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) {d <- read.delim(x); strsplit(d[[2]], ",")}))
 
-
 file.to.attendance.list <- function (x) {
     tmp <- read.delim(x)
     d.out <- data.frame(discord.name=unlist(strsplit(tmp[[2]], ",")))
@@ -31,6 +36,22 @@ attendance <- do.call("rbind",
                       lapply(list.files(".", pattern="^attendance-.*tsv$"),
                              file.to.attendance.list))
 
+## create list of folks who are missing in class 
+missing.in.class  <- call.list.full[is.na(call.list.full$answered) |
+                                    (!is.na(call.list.full$answered) & !call.list.full$answered),
+                                    c("discord.name", "day")]
+
+missing.in.class <- unique(missing.in.class)
+
+setDT(attendance)
+setkey(attendance, discord.name, day)
+setDT(missing.in.class)
+setkey(missing.in.class, discord.name, day)
+
+## drop presence for people on missing days
+attendance[missing.in.class,]
+attendance <- as.data.frame(attendance[!missing.in.class,])
+
 attendance.counts <- data.frame(table(attendance$discord.name))
 colnames(attendance.counts) <- c("discord.name", "num.present")
 
@@ -39,9 +60,10 @@ d <- merge(d, attendance.counts,
            by="discord.name")
 
 days.list <- lapply(unique(attendance$day), function (day) {
-    day.total <- table(call.list$day == day)[["TRUE"]]
+    day.total <- table(call.list.full$day == day)[["TRUE"]]
     lapply(d$discord.name, function (discord.name) {
         num.present <- nrow(attendance[attendance$day == day & attendance$discord.name == discord.name,])
+        if (num.present/day.total > 1) {print(day)}
         data.frame(discord.name=discord.name,
                    days.present=(num.present/day.total))
     })
@@ -57,6 +79,7 @@ attendance.days <- data.frame(discord.name=names(days.tbl),
 
 d <- merge(d, attendance.days,
            all.x=TRUE, all.y=TRUE, by="discord.name")
+
 d[sort.list(d$days.absent), c("discord.name", "num.calls", "days.absent")]
 
 ## make some visualizations of whose here/not here

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