Guest User

Untitled

a guest
Oct 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. library(tidyverse)
  2.  
  3. regs_tossups <- read_tsv("tossups.tsv")
  4.  
  5. regs_games_played <- regs_tossups %>%
  6. filter(!is.na(team), packet != "S", !is.na(buzz_location_pct)) %>%
  7. distinct(team, packet) %>%
  8. count(team)
  9.  
  10. # Change based on set categories
  11. regs_category_counts <- tribble(
  12. ~category, ~tu_count,
  13. "Literature", 4,
  14. "History", 4,
  15. "Science", 4,
  16. "Arts", 3,
  17. "RMPSS", 4,
  18. "Other", 1
  19. )
  20.  
  21. regs_bpa <- regs_tossups %>%
  22. filter(!is.na(buzz_location_pct)) %>%
  23. left_join(regs_games_played %>% mutate(max_gets = 20*n)) %>%
  24.  
  25. mutate(conv_flag = ifelse(buzz_value == "10", 1, 0),
  26. #Uncomment below line if set has powers
  27. #conv_flag = ifelse(buzz_value %in% c("15","10"), 1, 0),
  28. buzz_location_pct = ifelse(is.na(buzz_location_pct), 1, round(buzz_location_pct, 2)),
  29. buzz_location_pct = factor(buzz_location_pct, levels = seq(0,1,.01))) %>%
  30. group_by(player, team, max_gets, buzz_location_pct) %>%
  31. summarize(gets = sum(conv_flag)) %>%
  32. complete(nesting(player, team, max_gets), buzz_location_pct, fill = list(gets = 0)) %>%
  33. group_by(player, team) %>%
  34. mutate(cum_gets = cumsum(gets),
  35. conv_pct = cum_gets/max_gets,
  36. buzz_location_pct = buzz_location_pct %>% as.character() %>% as.numeric()) %>%
  37. ungroup() %>%
  38. mutate(player = paste0(player, " (", team, ")")) %>%
  39. group_by(player, team) %>%
  40. summarize(BPA = sum(conv_pct)) %>%
  41. arrange(-BPA)
Add Comment
Please, Sign In to add comment