Skip to content

Instantly share code, notes, and snippets.

@benmarwick
Last active April 5, 2026 23:50
Show Gist options
  • Select an option

  • Save benmarwick/9c5c9784cab5c60197b985c6af9cfafd to your computer and use it in GitHub Desktop.

Select an option

Save benmarwick/9c5c9784cab5c60197b985c6af9cfafd to your computer and use it in GitHub Desktop.
CSSS 490 weekly discussion group assignments
library(tidyverse)
gradebook <- read_csv("2024-03-28T1049_Grades-CS&SS_490_A.csv")
# random assignments into groups with leader and backup leader
gradebook <-
gradebook %>%
filter(!Student %in% c(NA, "Points Possible", "Student, Test"))
n_people_per_group <- 6 # six people per group
how_many_groups <-
floor(nrow(gradebook) / n_people_per_group)
how_many_reps <-
(nrow(gradebook) / how_many_groups)
group_numbers <-
rep(1:how_many_groups,
length.out = nrow(gradebook))
# check to see this is going to work
# should equal zero, -ve number is ok too
(how_many_groups * n_people_per_group) - nrow(gradebook)
new_cols <- paste0("week_", 1:10, "_discussion_group")
gradebook_groups <-
gradebook %>%
select(Student) %>%
mutate(!!!setNames(rep(NA, length(new_cols)), new_cols)) %>%
mutate(
across(
.cols = starts_with("week"),
.fns = ~sample(group_numbers)
)
)
group_composition <-
c(rep("member", (n_people_per_group - 2)),
"deputy", "leader")
draws <- as.vector(replicate(how_many_groups,
sample(group_composition)))
length(draws)
# check to see this is going to work
# should equal zero
length(draws) - nrow(gradebook)
if(length(draws) - nrow(gradebook) == 0){
NULL
} else {
draws <- c(draws, group_composition[1:abs(length(draws) - nrow(gradebook))])
}
# check it again
# should equal zero
length(draws) - nrow(gradebook)
gradebook_groups_roles_list <- NULL
for(i in 2:ncol(gradebook_groups)){
col_name <- names(gradebook_groups[, c(1, i)])
new_col_name <- paste0("week_", i-1, "_discussion_role")
gradebook_groups_roles <-
gradebook_groups %>%
select(all_of(col_name)) %>%
arrange(across(all_of(col_name[2]))) %>%
mutate(!!new_col_name := draws) %>%
arrange(across(all_of(col_name[1])))
gradebook_groups_roles_list[[i]] <-
gradebook_groups_roles
}
gradebook_groups_roles_tbl <-
gradebook_groups_roles_list %>%
compact %>%
reduce(left_join, by = "Student")
# check to see if each group has a leader and a deputy
# which groups lack a leader? has at least a leader or deputy
gradebook_groups_roles_tbl %>%
select(Student,
starts_with("week_1_")) %>%
mutate(situation = ifelse(str_detect(week_1_discussion_role,
"leader|deputy"), TRUE, FALSE)) %>%
group_by(week_1_discussion_group) %>%
tally(situation) %>% View
gradebook_groups_roles_tbl %>%
write_csv("gradebook_groups_roles.csv")
library(tidyverse)
## Introduction
# This code will take grades from Poll Everywhere and prepare them
# for uploading to Canvas. It will do one week (one column in Canvas) only.
## Get the Canvas gradebook
# Go to the Canvas course page, go to the gradebook for that
# course, click 'Actions' then 'Export'. That will download a CSV file to
# your computer. Move that file into the same folder as this R Markdown file.
# Make sure that the assignment that we are updating is 'published' so
# we get the column in the exported gradebook
# set the week that we are working on
this_is_week_n <- 1
# how many Canvas gradebook points is each week worth?
canvas_points <- 100
library(tidyverse)
# update the Canvas gradebook file name here
canvas_gradebook <- "2026-04-05T1614_Grades-CSSS_490_A.csv"
#---- read in the Canvas gradebook data
# we export the Canvas gradebook, and the column 'SIS Login ID' is the UW Net ID for each student
# this is the spreadsheet with Student ID from Perusall and Student ID that Canvas needs
# we got the Student ID from the student in a Canvas Quiz
student_id_data <-
read_csv(canvas_gradebook) %>%
filter(!is.na(`SIS Login ID`)) %>%
# make a column of the UW Net ID for joining with Perusall data
mutate(uw_net_id = `SIS Login ID`) %>%
# select only the relevant columns for this assignment
# and those required to join
select(
Student,
ID,
`SIS User ID`,
`SIS Login ID`,
Section,
uw_net_id,
contains("participation")
)
## Get the Poll Everywhere gradebook
# This process has a few steps that need to occur on the polleverywhere
# webpage to generate the CSV file we need here.
# 1. Go to https://www.polleverywhere.com/my/polls
# 2. Select only the polls used in the week we are focussing on (check the box next to the poll)
# 3. Click the 'Report' button at the top of the page
# 4. Choose 'Gradebook'
# 5. Update the name of the report with something like 'ARCHY 208 WI21 Week 1 Report'
# 6. In the panel on the right, click 'Select Run', then 'All runs'
# 7. Click 'Download' on the lower right of the page
# 8. Move the CSV file into the same folder is this script file
poll_everywhere_gradebook <- "csss-490-sp26-week-1-report_gradebook_1710093.csv"
#---- read in the Poll Everywhere gradebook data
# this is the sheet with the grades from Poll Everywhere, we need to download a fresh CSV for each week.
poll_everywhere_data <-
read_csv(poll_everywhere_gradebook) %>%
mutate(uw_net_id = str_remove(`Email`, "@uw.edu")) %>%
mutate(prop_polls_responded = Participation / 100) %>%
select(uw_net_id, prop_polls_responded)
## Join Poll Everywhere grades to Canvas
# First, we set the week number we are working on. If we are updating
# grades for week 3, then we change the value here to 3. This will
# identify the relevant columns from the gradebooks.
# Second, we join the Perusall grades to the Canvas gradebook:
canvas_assignment_regex <- glue::glue(
"Week ",
this_is_week_n,
" Participation \\("
)
canvas_assignment_column_name <-
str_subset(names(student_id_data), canvas_assignment_regex)
# join the two and drop unwanted cols
upload_to_canvas_gradebook <-
student_id_data %>%
# select relevant cols only
select(
Student,
ID,
`SIS User ID`,
`SIS Login ID`,
Section,
uw_net_id,
all_of(canvas_assignment_column_name)
) %>%
# join the data
left_join(
poll_everywhere_data %>%
select(uw_net_id, prop_polls_responded)
) %>%
# change NA to zero
mutate(
prop_polls_responded := ifelse(
is.na((prop_polls_responded)),
0,
(prop_polls_responded)
)
) %>%
# update column name with assignment name
mutate(
!!canvas_assignment_column_name := prop_polls_responded * canvas_points
) %>%
# drop unwanted cols to prep for Canvas upload
select(-uw_net_id, -prop_polls_responded)
# Third, we export to CSV, ready to upload to Canvas:
# ---- export to CSV
write_csv(
upload_to_canvas_gradebook,
glue::glue(
"poll_everywhere_week_",
this_is_week_n,
"_upload_to_canvas_gradebook",
".csv"
)
)
# Now go to Canvas and upload
## Clean up
# delete all the CSV files in this directory
# so we have a clean slate ready for next week
map(fs::dir_ls(glob = "*.csv"), fs::file_delete)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment