From d77f32f5c1deaa19c4ebb5ac931a7f7844a46368 Mon Sep 17 00:00:00 2001 From: Nathan TeBlunthuis Date: Tue, 29 Dec 2020 17:22:35 -0800 Subject: [PATCH 1/8] Explain how to configure the bot with discord. --- README | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/README b/README index da52a4d..611926e 100644 --- a/README +++ b/README @@ -6,9 +6,22 @@ module available in PyPi and installable like: $ pip3 install discord -I don't have details on how I set up my own Discord bot and/or invited -it to my server but I hope you'll add to this file as you do this and -figure out what needs to happen. +Setting up the Bot +===================================== + +The documentation for the `discord` python package +(https://discordpy.readthedocs.io/en/latest/discord.html) does a good +job explaining how to set up a Discord bot with your server. Follow +the steps there, with one important exception: + +1. On the "Bot" tab in the discord application configuration page you +need to enable both "Privileged Gateway Intents." This allows the bot +to see who is present and active in the channel. + +Finally, you need to copy your bot'ss Token (also found on the "Bot" tab) +into coldcallbot.py. Pass it as the argument to `ccb.run()`. + + Using the Cold Call Bot ====================================== -- 2.39.2 From d8e662b5c3f43a682a64dbc8da33290977692b98 Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Tue, 6 Apr 2021 16:28:00 -0700 Subject: [PATCH 2/8] reworking the script to work with COMMLD570A (editted) this commit was editted to not include student details - new manual version of the coldcallbot - minor tweaks to make things less discord specific - changes for new URLs, filenames, and such --- assessment_and_tracking/track_enrolled.R | 18 ++++++------ coldcall.py | 36 ++++++++++++++---------- coldcallboy-manual.py | 15 ++++++++++ data/download_data.sh | 4 +++ 4 files changed, 49 insertions(+), 24 deletions(-) create mode 100755 coldcallboy-manual.py create mode 100755 data/download_data.sh diff --git a/assessment_and_tracking/track_enrolled.R b/assessment_and_tracking/track_enrolled.R index 563384d..f0d0fcb 100644 --- a/assessment_and_tracking/track_enrolled.R +++ b/assessment_and_tracking/track_enrolled.R @@ -1,4 +1,4 @@ -myuw <- read.csv("myuw-COM_482_A_autumn_2020_students.csv") +myuw <- read.csv("myuw-COMMLD_570_A_spring_2021_students.csv") gs <- read.delim("student_information.tsv") ## these are students who dropped the class (should be empty) @@ -10,14 +10,14 @@ myuw[!myuw$StudentNo %in% gs$Your.UW.student.number,] ## read all the folks who have been called and see who is missing from ## the google sheet -call.list <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) { - d <- read.delim(x) - strsplit(d[[2]], ",") -}) -) -present <- unique(call.list) -present[!present %in% gs[["Your.username.on.the.class.Discord.server"]]] +## call.list <- unlist(lapply(list.files(".", pattern="^attendance-.*tsv$"), function (x) { +## d <- read.delim(x) +## strsplit(d[[2]], ",") +## }) +## ) +## present <- unique(call.list) +## present[!present %in% gs[["Your.username.on.the.class.Discord.server"]]] ## and never attended class.. -gs[["Your.username.on.the.class.Discord.server"]][!gs[["Your.username.on.the.class.Discord.server"]] %in% present] +## gs[["Your.username.on.the.class.Discord.server"]][!gs[["Your.username.on.the.class.Discord.server"]] %in% present] diff --git a/coldcall.py b/coldcall.py index 1905844..1ba96a5 100644 --- a/coldcall.py +++ b/coldcall.py @@ -8,19 +8,21 @@ from csv import DictReader import os.path import re -import discord class ColdCall(): - def __init__ (self): + def __init__ (self, record_attendance=True): self.today = str(datetime.date(datetime.now())) # how much less likely should it be that a student is called upon? - self.weight = 2 + self.weight = 2 + self.record_attendance = record_attendance # filenames self.__fn_studentinfo = "data/student_information.tsv" self.__fn_daily_calllist = f"data/call_list-{self.today}.tsv" self.__fn_daily_attendance = f"data/attendance-{self.today}.tsv" + self.preferred_names = self.__get_preferred_names() + def __load_prev_questions(self): previous_questions = defaultdict(int) @@ -29,21 +31,24 @@ class ColdCall(): with open(f"./data/{fn}", 'r') as f: for row in DictReader(f, delimiter="\t"): if not row["answered"] == "FALSE": - previous_questions[row["discord_name"]] += 1 + previous_questions[row["unique_name"]] += 1 return previous_questions - - def __get_preferred_name(self, selected_student): - # translate the discord name into the preferred students name, - # if possible, otherwise return the discord name + + def __get_preferred_names(self): + # translate the unique name into the preferred students name, + # if possible, otherwise return the unique name preferred_names = {} with open(self.__fn_studentinfo, 'r') as f: for row in DictReader(f, delimiter="\t"): - preferred_names[row["Your username on the class Discord server"]] = row["Name you'd like to go by in class"] + preferred_names[row["Your username on the class Teams server"]] = row["Name you'd like to go by in class"] - if selected_student in preferred_names: - return preferred_names[selected_student] + return(preferred_names) + + def __get_preferred_name(self, selected_student): + if selected_student in self.preferred_names: + return self.preferred_names[selected_student] else: return None @@ -59,7 +64,7 @@ class ColdCall(): weights[s] = weights[s] / self.weight # choose one student from the weighted list - print(weights) + # print(weights) # DEBUG LINE return choices(list(weights.keys()), weights=list(weights.values()), k=1)[0] def __record_attendance(self, students_present): @@ -78,7 +83,7 @@ class ColdCall(): # if it's the first one of the day, write it out if not os.path.exists(self.__fn_daily_calllist): with open(self.__fn_daily_calllist, "w") as f: - print("\t".join(["discord_name", "timestamp", "answered", "assessment"]), file=f) + print("\t".join(["unique_name", "timestamp", "answered", "assessment"]), file=f) # open for appending the student with open(self.__fn_daily_calllist, "a") as f: @@ -89,7 +94,8 @@ class ColdCall(): selected_student = self.__select_student_from_list(students_present) # record the called-upon student in the right place - self.__record_attendance(students_present) + if self.record_attendance: + self.__record_attendance(students_present) self.__record_coldcall(selected_student) preferred_name = self.__get_preferred_name(selected_student) @@ -100,7 +106,7 @@ class ColdCall(): return coldcall_message # cc = ColdCall() - + # test_student_list = ["jordan", "Kristen Larrick", "Madison Heisterman", "Maria.Au20", "Laura (Alia) Levi", "Leona Aklipi", "anne", "emmaaitelli", "ashleylee", "allie_partridge", "Tiana_Cole", "Hamin", "Ella Qu", "Shizuka", "Ben Baird", "Kim Do", "Isaacm24", "Sam Bell", "Courtneylg"] # print(cc.coldcall(test_student_list)) diff --git a/coldcallboy-manual.py b/coldcallboy-manual.py new file mode 100755 index 0000000..3bb580c --- /dev/null +++ b/coldcallboy-manual.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 + +from coldcall import ColdCall +import re + +## create the coldcall object +cc = ColdCall(record_attendance=False) + +student_list = cc.preferred_names + +# print out 100 students + +for i in range(100): + print(f"{i}. {cc.coldcall(student_list)} [ ] [ ]\n") + diff --git a/data/download_data.sh b/data/download_data.sh new file mode 100755 index 0000000..8687509 --- /dev/null +++ b/data/download_data.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +wget 'https://docs.google.com/spreadsheets/d/FIXME/export?gid=FIXME&format=tsv' -O 'student_information.tsv' + -- 2.39.2 From 914f5973c38ae40a2d51f8425806c2bbed2f035f Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Tue, 20 Apr 2021 11:24:50 -0700 Subject: [PATCH 3/8] renamed manual coldcall bot script it's a /bot/, not a boy --- coldcallboy-manual.py => coldcallbot-manual.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename coldcallboy-manual.py => coldcallbot-manual.py (100%) diff --git a/coldcallboy-manual.py b/coldcallbot-manual.py similarity index 100% rename from coldcallboy-manual.py rename to coldcallbot-manual.py -- 2.39.2 From f590bf88bc365b092f938de8dcc36a061a5cb2ea Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Tue, 20 Apr 2021 11:26:36 -0700 Subject: [PATCH 4/8] start list at 1 instead of 0 --- coldcallbot-manual.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coldcallbot-manual.py b/coldcallbot-manual.py index 3bb580c..a4268ea 100755 --- a/coldcallbot-manual.py +++ b/coldcallbot-manual.py @@ -11,5 +11,5 @@ student_list = cc.preferred_names # print out 100 students for i in range(100): - print(f"{i}. {cc.coldcall(student_list)} [ ] [ ]\n") + print(f"{i + 1}. {cc.coldcall(student_list)} [ ] [ ]\n") -- 2.39.2 From 95a99775721432eca7480aff7249449c5e0b35f3 Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Tue, 4 May 2021 12:32:14 -0700 Subject: [PATCH 5/8] small changes to get track participation working --- assessment_and_tracking/track_participation.R | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/assessment_and_tracking/track_participation.R b/assessment_and_tracking/track_participation.R index 9a51084..a3a94eb 100644 --- a/assessment_and_tracking/track_participation.R +++ b/assessment_and_tracking/track_participation.R @@ -1,13 +1,18 @@ +setwd("~/online_communities/coldcallbot/data/") + library(ggplot2) library(data.table) gs <- read.delim("student_information.tsv") -d <- gs[,c(2,5)] -colnames(d) <- c("student.num", "discord.name") +d <- gs[,c(2,4)] +colnames(d) <- c("student.num", "teams.name") + +call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$"), function (x) {read.delim(x, stringsAsFactors=FALSE)[,1:4]})) -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)) +table(call.list$unique_name) + call.list$day <- as.Date(call.list$timestamp) ## drop calls where the person wasn't present -- 2.39.2 From da8f47aa270b563087b6ceddf349b7fe70e4f03b Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Tue, 4 May 2021 12:49:03 -0700 Subject: [PATCH 6/8] report on the number of questions answered, not just asked --- assessment_and_tracking/track_participation.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/assessment_and_tracking/track_participation.R b/assessment_and_tracking/track_participation.R index a3a94eb..698041c 100644 --- a/assessment_and_tracking/track_participation.R +++ b/assessment_and_tracking/track_participation.R @@ -11,7 +11,9 @@ call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$" colnames(call.list) <- gsub("_", ".", colnames(call.list)) -table(call.list$unique_name) +table(call.list$unique_name[call.list$answered]) + +exit() call.list$day <- as.Date(call.list$timestamp) -- 2.39.2 From 3bd4c9c2a60797346868989dd63341e48e87da70 Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Mon, 31 May 2021 17:06:09 -0700 Subject: [PATCH 7/8] updated grade code - COMMLD570A did not penalize/track absences at all so i cut this completely --- .../compute_final_case_grades.R | 95 +++++------------- assessment_and_tracking/track_participation.R | 99 +------------------ 2 files changed, 28 insertions(+), 166 deletions(-) diff --git a/assessment_and_tracking/compute_final_case_grades.R b/assessment_and_tracking/compute_final_case_grades.R index 60a60f3..b26270b 100644 --- a/assessment_and_tracking/compute_final_case_grades.R +++ b/assessment_and_tracking/compute_final_case_grades.R @@ -1,36 +1,23 @@ ## load in the data ################################# -case.sessions <- 15 -myuw <- read.csv("myuw-COM_482_A_autumn_2020_students.csv", stringsAsFactors=FALSE) +myuw <- read.csv("myuw-COMMLD_570_A_spring_2021_students.csv", stringsAsFactors=FALSE) ## class-level variables -question.grades <- c("GOOD"=100, "FAIR"=100-(50/3.3), "BAD"=100-(50/(3.3)*2)) -missed.question.penalty <- (50/3.3) * 0.2 ## 1/5 of a full point on the GPA scale +question.grades <- c("GOOD"=100, "FAIR"=100-(50/3.3), "WEAK"=100-(50/(3.3)*2)) source("../assessment_and_tracking/track_participation.R") setwd("case_grades") -rownames(d) <- d$discord.name +rownames(d) <- d$unique.name ## show the distribution of assessments -table(call.list.full$assessment) -prop.table(table(call.list.full$assessment)) -table(call.list.full$answered) -prop.table(table(call.list.full$answered)) +table(call.list$assessment) +prop.table(table(call.list$assessment)) +table(call.list$answered) +prop.table(table(call.list$answered)) -total.questions.asked <- nrow(call.list.full) - -## create new column with number of questions present -d$prop.asked <- d$num.calls / d$num.present - -## generate statistics using these new variables -prop.asks.quantiles <- quantile(d$prop.asked, probs=seq(0,1, 0.01)) -prop.asks.quantiles <- prop.asks.quantiles[!duplicated(prop.asks.quantiles)] - -## this is generating broken stuff but it's not used for anything -d$prop.asked.quant <- cut(d$prop.asked, breaks=prop.asks.quantiles, - labels=names(prop.asks.quantiles)[1:(length(prop.asks.quantiles)-1)]) +total.questions.asked <- nrow(call.list) ## generate grades ########################################################## @@ -39,81 +26,47 @@ d$part.grade <- NA ## print the median number of questions for (a) everybody and (b) ## people that have been present 75% of the time -median(d$num.calls[d$days.absent < 0.25*case.sessions]) median(d$num.calls) questions.cutoff <- median(d$num.calls) ## helper function to generate average grade minus number of missing -gen.part.grade <- function (x.discord.name) { - q.scores <- question.grades[call.list$assessment[call.list$discord.name == x.discord.name]] +gen.part.grade <- function (x.unique.name) { + q.scores <- question.grades[call.list$assessment[call.list$unique.name == x.unique.name]] base.score <- mean(q.scores, na.rm=TRUE) ## number of missing days - missing.days <- nrow(missing.in.class[missing.in.class$discord.name == x.discord.name,]) + # missing.days <- nrow(missing.in.class[missing.in.class$unique.name == x.unique.name,]) ## return the final score - data.frame(discord.name=x.discord.name, - part.grade=(base.score - missing.days * missed.question.penalty)) + data.frame(unique.name=x.unique.name, + part.grade=(base.score)) } -tmp <- do.call("rbind", lapply(d$discord.name[d$num.calls >= questions.cutoff], gen.part.grade)) - -d[as.character(tmp$discord.name), "part.grade"] <- tmp$part.grade - -## next handle the folks *under* the median - -## first we handle the zeros -## step 1: first double check the people who have zeros and ensure that they didn't "just" get unlucky" -d[d$num.calls == 0,] -## set those people to 0 :( -d$part.grade[d$num.calls == 0] <- 0 +tmp <- do.call("rbind", lapply(d$unique.name, gen.part.grade)) -## step 2 is to handle folks who got unlucky in the normal way -tmp <- do.call("rbind", lapply(d$discord.name[is.na(d$part.grade) & d$prop.asked <= median(d$prop.asked)], gen.part.grade)) -d[as.character(tmp$discord.name), "part.grade"] <- tmp$part.grade - -## the people who are left are lucky and still undercounted so we'll penalize them -d[is.na(d$part.grade),] -penalized.discord.names <- d$discord.name[is.na(d$part.grade)] +d[as.character(tmp$unique.name), "part.grade"] <- tmp$part.grade ## generate the baseline participation grades as per the process above -tmp <- do.call("rbind", lapply(penalized.discord.names, gen.part.grade)) -d[as.character(tmp$discord.name), "part.grade"] <- tmp$part.grade - -## now add "zeros" for every questions that is below the normal -d[as.character(penalized.discord.names),"part.grade"] <- (( - (questions.cutoff - d[as.character(penalized.discord.names),"num.calls"] * 0) + - (d[as.character(penalized.discord.names),"num.calls"] * d[as.character(penalized.discord.names),"part.grade"]) ) - / questions.cutoff) - -d[as.character(penalized.discord.names),] ## map part grades back to 4.0 letter scale and points d$part.4point <-round((d$part.grade / (50/3.3)) - 2.6, 2) -d[sort.list(d$prop.asked), c("discord.name", "num.calls", "num.present", - "prop.asked", "prop.asked.quant", "part.grade", "part.4point", - "days.absent")] - -d[sort.list(d$part.4point), c("discord.name", "num.calls", "num.present", - "prop.asked", "prop.asked.quant", "part.grade", "part.4point", - "days.absent")] +d[sort.list(d$part.4point),] ## writing out data -quantile(d$num.calls, probs=(0:100*0.01)) d.print <- merge(d, myuw[,c("StudentNo", "FirstName", "LastName", "UWNetID")], by.x="student.num", by.y="StudentNo") write.csv(d.print, file="final_participation_grades.csv") -library(rmarkdown) +## library(rmarkdown) -for (x.discord.name in d$discord.name) { - render(input="../../assessment_and_tracking/student_report_template.Rmd", - output_format="html_document", - output_file=paste("../data/case_grades/student_reports/", - d.print$UWNetID[d.print$discord.name == x.discord.name], - sep="")) -} +## for (x.unique.name in d$unique.name) { +## render(input="../../assessment_and_tracking/student_report_template.Rmd", +## output_format="html_document", +## output_file=paste("../data/case_grades/student_reports/", +## d.print$UWNetID[d.print$unique.name == x.unique.name], +## sep="")) +## } diff --git a/assessment_and_tracking/track_participation.R b/assessment_and_tracking/track_participation.R index 698041c..28b8a4e 100644 --- a/assessment_and_tracking/track_participation.R +++ b/assessment_and_tracking/track_participation.R @@ -5,7 +5,7 @@ library(data.table) gs <- read.delim("student_information.tsv") d <- gs[,c(2,4)] -colnames(d) <- c("student.num", "teams.name") +colnames(d) <- c("student.num", "unique.name") call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$"), function (x) {read.delim(x, stringsAsFactors=FALSE)[,1:4]})) @@ -13,104 +13,13 @@ colnames(call.list) <- gsub("_", ".", colnames(call.list)) table(call.list$unique_name[call.list$answered]) -exit() - -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") - -d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="discord.name"); d - -## 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) -} - -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") - -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)) - }) -}) - -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")] - -## 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=days.absent, group=days.absent) + - geom_bar(color="black") + - scale_x_discrete("Number of questions asked") + - scale_y_continuous("Number of students") + - scale_fill_continuous("Days absent", low="red", high="blue")+ - theme_bw() - -dev.off() - -png("questions_absenses_boxplots.png", units="px", width=800, height=600) - -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") +call.counts <- data.frame(table(call.list$unique.name)) +colnames(call.counts) <- c("unique.name", "num.calls") -dev.off() +d <- merge(d, call.counts, all.x=TRUE, all.y=TRUE, by="unique.name"); d -- 2.39.2 From cda1cb3b3ca0de52548b97f4c23f2dc7f8cb220a Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Wed, 5 Jan 2022 13:51:02 +0900 Subject: [PATCH 8/8] remove references to boy (should be bot, obvs) --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index da52a4d..d07038e 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ Setting up the Discord Bot ====================================== -I run the Discord boy from my laptop. It requires the discord Python +I run the Discord bot from my laptop. It requires the discord Python module available in PyPi and installable like: $ pip3 install discord @@ -31,7 +31,7 @@ Daily Process You need to start the bot from the laptop each day. I do that by: - $ ./coldcallboy.py + $ ./coldcallbot.py The bot will run in the terminal, print out data as it works including detailed weights as it goes, and it will record data into files in the -- 2.39.2