]> code.communitydata.science - coldcallbot-discord.git/blobdiff - assessment_and_tracking/track_participation.R
code to create final case discussion grades
[coldcallbot-discord.git] / assessment_and_tracking / track_participation.R
index a3a94eb7662c2e58a66df44e6e726ce87a3055da..37898e70b6ebae1affb0a676a43049f9687ee788 100644 (file)
 setwd("~/online_communities/coldcallbot/data/")
 
-library(ggplot2)
 library(data.table)
 
-gs <- read.delim("student_information.tsv")
-d <- gs[,c(2,4)]
-colnames(d) <- c("student.num", "teams.name")
+################################################
+## LOAD call_list TSV data
+################################################
 
 call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$"), function (x) {read.delim(x, stringsAsFactors=FALSE)[,1:4]}))
 
 colnames(call.list) <- gsub("_", ".", colnames(call.list))
 
-table(call.list$unique_name)
-
-call.list$day <- as.Date(call.list$timestamp)
+table(call.list$unique.name[call.list$answered])
 
 ## 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")
+## show the distribution of assessments
+prop.table(table(call.list$assessment))
 
-d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d
+call.counts <- data.frame(table(call.list$unique.name))
+colnames(call.counts) <- c("unique.name", "num.calls")
 
-## set anything that's missing to zero
-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]], ",")))
-    d.out$day <- rep(as.Date(tmp[[1]][1]), nrow(d.out))
-    return(d.out)
-}
+## create list of folks who are missing in class w/o reporting it
+absence.data.cols <- c("unique.name", "date.absent", "reported")
 
-attendance <- do.call("rbind",
-                      lapply(list.files(".", pattern="^attendance-.*tsv$"),
-                             file.to.attendance.list))
+missing.in.class <- call.list.full[!call.list.full$answered,
+                                   c("unique.name", "timestamp")]
+missing.in.class$date.absent <- as.Date(missing.in.class$timestamp)
+missing.in.class$reported <- FALSE
+missing.in.class <- missing.in.class[,absence.data.cols]
+missing.in.class <- unique(missing.in.class)
 
-## 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")]
+################################################
+## LOAD absence data TSV data
+################################################
 
-missing.in.class <- unique(missing.in.class)
+absence.google <- read.delim("absence_poll_data.tsv")
+colnames(absence.google) <- c("timestamp", "unique.name", "date.absent")
+absence.google$date.absent <- as.Date(absence.google$date.absent, format="%m/%d/%Y")
+absence.google$reported <- TRUE
+absence.google <- absence.google[,absence.data.cols]
+absence.google <- unique(absence.google)
+
+## combine the two absence lists and then create a unique subset
+absence <- rbind(missing.in.class[,absence.data.cols],
+                 absence.google[,absence.data.cols])
+
+## these are people that show up in both lists (i.e., probably they
+## submitted too late but it's worth verifying before we penalize
+## them. i'd actually remove them from the absence sheet to suppress
+## this error
+absence[duplicated(absence[,1:2]),]
+absence <- absence[!duplicated(absence[,1:2]),]
 
-setDT(attendance)
-setkey(attendance, discord.name, day)
-setDT(missing.in.class)
-setkey(missing.in.class, discord.name, day)
+## print total questions asked and absences
+absence.count <- data.frame(table(unique(absence[,c("unique.name", "date.absent")])[,"unique.name"]))
+colnames(absence.count) <- c("unique.name", "absences")
 
-## 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")
+## load up the full class list
+gs <- read.delim("student_information.tsv")
+d <- gs[,c("Your.UW.student.number", "Name.you.d.like.to.go.by.in.class")]
+colnames(d) <- c("unique.name", "short.name")
+
+## merge in the call counts
+d <- merge(d, call.counts, all.x=TRUE, all.y=FALSE, by="unique.name")
+d <- merge(d, absence.count, by="unique.name", all.x=TRUE, all.y=FALSE)
+
+d
+
+## set anything that's missing to zero
+d$num.calls[is.na(d$num.calls)] <- 0
+d$absences[is.na(d$absences)] <- 0
+
+################################################
+## list people who have been absent often or called on a lot
+################################################
 
-d <- merge(d, attendance.counts,
-           all.x=TRUE, all.y=TRUE,
-           by="discord.name")
 
-days.list <- lapply(unique(attendance$day), function (day) {
-    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))
-    })
-})
+## list students sorted in terms of (a) absences and (b) prev questions
+d[sort.list(d$absences),]
 
-days.tmp <- do.call("rbind", lapply(days.list, function (x) do.call("rbind", x)))
+d[sort.list(d$num.calls, decreasing=TRUE),]
 
-days.tbl <- tapply(days.tmp$days.present, days.tmp$discord.name, sum)
+################################################
+## build visualizations
+################################################
 
-attendance.days <- data.frame(discord.name=names(days.tbl),
-                              days.present=days.tbl,
-                              days.absent=length(list.files(".", pattern="^attendance-.*tsv$"))-days.tbl)
 
-d <- merge(d, attendance.days,
-           all.x=TRUE, all.y=TRUE, by="discord.name")
+library(ggplot2)
 
-d[sort.list(d$days.absent), c("discord.name", "num.calls", "days.absent")]
+color.gradient <- scales::seq_gradient_pal("yellow", "magenta", "Lab")(seq(0,1,length.out=range(d$absences)[2]+1))
 
-## make some visualizations of whose here/not here
-#######################################################
+table(d$num.calls, d$absences)
 
-png("questions_absence_histogram_combined.png", units="px", width=800, height=600)
+png("questions_absence_histogram_combined.png", units="px", width=600, height=400)
 
 ggplot(d) +
-    aes(x=as.factor(num.calls), fill=days.absent, group=days.absent) +
+    aes(x=as.factor(num.calls), fill=as.factor(absences)) +
     geom_bar(color="black") +
-    scale_x_discrete("Number of questions asked") +
+    stat_count() +
+    scale_x_discrete("Number of questions answered") +
     scale_y_continuous("Number of students") +
-    scale_fill_continuous("Days absent", low="red", high="blue")+
+    ##scale_fill_brewer("Absences", palette="Blues") +
+    scale_fill_manual("Absences", values=color.gradient) +
     theme_bw()
 
 dev.off()
 
-png("questions_absenses_boxplots.png", units="px", width=800, height=600)
+absence.labeller <- function (df) {
+    lapply(df, function (x) { paste("Absences:", x) })
+}
 
-ggplot(data=d) +
-    aes(x=as.factor(num.calls), y=days.absent) +
-    geom_boxplot() +
-    scale_x_discrete("Number of questions asked") +
-    scale_y_continuous("Days absent")
+## png("questions_absence_histogram_facets.png", units="px", width=600, height=400)
 
-dev.off()
+## ggplot(d) +
+##     aes(x=as.factor(num.calls)) +
+##     geom_bar() +
+##     stat_count() +
+##     scale_x_discrete("Number of questions answered") +
+##     scale_y_continuous("Number of students") +
+##     theme_bw() +
+##     facet_wrap(.~absences, ncol=5, labeller="absence.labeller")
 

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