From: Benjamin Mako Hill Date: Tue, 10 Nov 2020 17:44:23 +0000 (-0800) Subject: added code to compute /days/ present or absent X-Git-Url: https://code.communitydata.science/coldcallbot-discord.git/commitdiff_plain/61d6ecd88a2207059fc7832d80e4e2bc7f43c13d added code to compute /days/ present or absent --- diff --git a/data/track_participation.R b/data/track_participation.R index 66ca3db..f616d21 100644 --- a/data/track_participation.R +++ b/data/track_participation.R @@ -7,6 +7,8 @@ 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]})) colnames(call.list) <- gsub("_", ".", colnames(call.list)) +call.list$day <- as.Date(call.list$timestamp) + call.counts <- data.frame(table(call.list$discord.name)) colnames(call.counts) <- c("discord.name", "num.calls") @@ -17,24 +19,57 @@ 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]], ",")})) -attendance.counts <- data.frame(table(attendance)) + +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) +} + +attendance <- do.call("rbind", + lapply(list.files(".", pattern="^attendance-.*tsv$"), + file.to.attendance.list)) + +attendance.counts <- data.frame(table(attendance$discord.name)) colnames(attendance.counts) <- c("discord.name", "num.present") -d <- merge(d, attendance.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d +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$day == day)[["TRUE"]] + lapply(d$discord.name, function (discord.name) { + num.present <- nrow(attendance[attendance$day == day & attendance$discord.name == discord.name,]) + data.frame(discord.name=discord.name, + days.present=(num.present/day.total)) + }) +}) + +days.tmp <- do.call("rbind", lapply(days.list, function (x) do.call("rbind", x))) + +days.tbl <- tapply(days.tmp$days.present, days.tmp$discord.name, sum) + +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") +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=length(unique(d$num.present)))) +## make some visualizations of whose here/not here +####################################################### png("questions_absence_histogram_combined.png", units="px", width=800, height=600) ggplot(d) + - aes(x=as.factor(num.calls), fill=as.factor(num.present)) + + aes(x=as.factor(num.calls), fill=days.absent, group=days.absent) + geom_bar(color="black") + - stat_count() + scale_x_discrete("Number of questions asked") + scale_y_continuous("Number of students") + - # scale_fill_brewer("Absences") + - scale_fill_manual("Absences", values=color.gradient) + + scale_fill_continuous("Days absent", low="red", high="blue")+ theme_bw() dev.off() @@ -42,10 +77,10 @@ dev.off() png("questions_absenses_boxplots.png", units="px", width=800, height=600) ggplot(data=d) + - aes(x=as.factor(num.calls), y=num.present) + + aes(x=as.factor(num.calls), y=days.absent) + geom_boxplot() + scale_x_discrete("Number of questions asked") + - scale_y_continuous("Number of questions present") + scale_y_continuous("Days absent") dev.off()