Last active
February 7, 2024 17:03
-
-
Save benmarwick/680158aa0c2f2a292eb9c70e467201e2 to your computer and use it in GitHub Desktop.
ARCHY course time overlaps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "AY24-25 ARCHY course time overlaps" | |
format: html | |
execute: | |
echo: false | |
warning: false | |
self-contained: true | |
--- | |
```{r} | |
library(tidyverse) | |
library(googlesheets4) | |
library(googledrive) | |
library(lubridate) | |
library(shadowtext) | |
# this URL goes the the specific sheet for a specific academic year | |
archy_course_planning_url <- | |
"https://docs.google.com/spreadsheets/d/1qu6Dl1ua2dLnkeR-j3ek1OJWAEVATlIdSJzjpH8CoAQ/edit#gid=1536906775" | |
options( | |
# gargle_oauth_cache = here::here(".secrets"), | |
# gargle_verbosity = "debug", | |
gargle_oauth_email = "bmarwick@uw.edu" | |
) | |
#drive_auth(email = "bmarwick@uw.edu") | |
#gs4_auth() # was what made it work | |
archy_course_planning <- | |
range_read(archy_course_planning_url, | |
col_types = "c") %>% | |
# convert times to a format R knows | |
mutate(`Time start` = parse_date_time(`Time start`, '%I:%M:%S %p'), | |
`Time end` = parse_date_time(`Time end`, '%I:%M:%S %p')) | |
``` | |
```{r} | |
format_time_label <- function(x) { | |
hour(x) | |
} | |
get_the_quarter <- function(quarter = "AU"){ | |
archy_course_planning %>% | |
filter(Quarter == quarter) %>% | |
select(`Course #`, | |
Title, | |
Mon:Fri, | |
`Time start`, | |
`Time end`) %>% | |
pivot_longer(cols = Mon:Fri, | |
names_to = "day") %>% | |
drop_na(value) %>% | |
mutate(day = factor(day, c("Mon", "Tue", "Wed", "Thu", "Fri"))) %>% | |
mutate(crse1 = str_sub(`Course #`, 1,1), | |
crse2 = str_sub(`Course #`, 2,3)) %>% | |
group_by(crse1, crse2) %>% | |
filter(crse1 == min(crse1)) | |
} | |
plot_the_schedule <- function(quarter, | |
dodge_width = 0.5){ | |
ggplot(quarter, | |
aes(xmin = `Time start`, | |
xmax = `Time end`, | |
y = day, | |
label = Title)) + | |
annotate("rect", | |
xmin = parse_date_time("8:30:00 AM", '%I:%M:%S %p'), | |
xmax = parse_date_time("6:00:00 PM", '%I:%M:%S %p'), | |
ymax = c(0.5, 2.5, 4.5), | |
ymin = c(1.5, 3.5, 5.5), | |
fill = "grey80", | |
alpha = 0.4) + | |
geom_linerange(aes(color = `Course #`), | |
position = position_dodge(width = dodge_width), | |
size = 3) + | |
geom_shadowtext(aes(label = `Course #`, | |
x = `Time start`, | |
group = `Course #`), | |
position = position_dodge2(width = dodge_width), | |
size = 3, | |
bg.colour= "white", | |
colour = "black") + | |
scale_y_discrete(breaks = c("Mon", "Tue", "Wed", "Thu", "Fri"), | |
labels = c("Mon", "Tue", "Wed", "Thu", "Fri"), | |
drop=FALSE) + | |
scale_x_datetime(date_breaks = "1 hour", | |
labels = format_time_label | |
) + | |
labs(x = "Time of day", | |
y = "") + | |
theme_minimal() + | |
theme(legend.position = "bottom") | |
} | |
``` | |
# Fall classes | |
```{r} | |
au <- get_the_quarter("AU") | |
plot_the_schedule(au) | |
``` | |
# Winter classes | |
```{r} | |
wi <- get_the_quarter("WI") | |
plot_the_schedule(wi) | |
``` | |
# Spring classes | |
```{r} | |
sp <- get_the_quarter("SP") | |
plot_the_schedule(sp) | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment