Last active
April 7, 2021 22:01
-
-
Save ryanrosenberg/62a205b8e70a761ffaf74faa33266a78 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
library(tidyverse) | |
regs_tossups <- read_tsv("tossups.tsv") | |
regs_games_played <- regs_tossups %>% | |
filter(!is.na(team), packet != "S", !is.na(buzz_location_pct)) %>% | |
distinct(team, packet) %>% | |
count(team) | |
# Change based on set categories | |
regs_category_counts <- tribble( | |
~category, ~tu_count, | |
"Literature", 4, | |
"History", 4, | |
"Science", 4, | |
"Arts", 3, | |
"RMPSS", 4, | |
"Other", 1 | |
) | |
regs_bpa <- regs_tossups %>% | |
filter(!is.na(buzz_location_pct)) %>% | |
left_join(regs_games_played %>% mutate(max_gets = 20*n)) %>% | |
mutate(conv_flag = ifelse(buzz_value == "10", 1, 0), | |
#Uncomment below line if set has powers | |
#conv_flag = ifelse(buzz_value %in% c("15","10"), 1, 0), | |
buzz_location_pct = ifelse(is.na(buzz_location_pct), 1, round(buzz_location_pct, 2)), | |
buzz_location_pct = factor(buzz_location_pct, levels = seq(0,1,.01))) %>% | |
group_by(player, team, max_gets, buzz_location_pct) %>% | |
summarize(gets = sum(conv_flag)) %>% | |
complete(nesting(player, team, max_gets), buzz_location_pct, fill = list(gets = 0)) %>% | |
group_by(player, team) %>% | |
mutate(cum_gets = cumsum(gets), | |
conv_pct = cum_gets/max_gets, | |
buzz_location_pct = buzz_location_pct %>% as.character() %>% as.numeric()) %>% | |
ungroup() %>% | |
mutate(player = paste0(player, " (", team, ")")) %>% | |
group_by(player, team) %>% | |
summarize(BPA = sum(conv_pct)) %>% | |
arrange(-BPA) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment