-
Notifications
You must be signed in to change notification settings - Fork 3
/
roster_tests.R
56 lines (50 loc) · 2.05 KB
/
roster_tests.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
library(tidyverse)
source("combine_roster_data.R")
roster <- combine_roster_data("2020-09-03")
seasons <- 2011:2019
pbp <- purrr::map_df(seasons, function(x) {
readRDS(
url(
glue::glue("https://raw.githubusercontent.com/guga31bb/nflfastR-data/master/data/play_by_play_{x}.rds")
)
)
}) #%>%
# nflfastR::clean_pbp() # added fresh clean_pbp after some changes
pass <- pbp %>%
group_by(season, posteam, passer, passer_jersey_number) %>%
summarise(plays = n()) %>%
mutate(join = stringr::str_extract(passer, "(?<=\\.[:space:]?)[:graph:]+(?=\\b)")) %>%
filter(!is.na(passer), !is.na(passer_jersey_number)) %>%
left_join(
roster,
by = c("season" = "team.season", "posteam" = "team.abbr", "join", "passer_jersey_number" = "teamPlayers.jerseyNumber")
)
rec <- pbp %>%
group_by(season, posteam, receiver, receiver_jersey_number) %>%
summarise(plays = n()) %>%
mutate(join = stringr::str_extract(receiver, "(?<=\\.[:space:]?)[:graph:]+(?=\\b)")) %>%
filter(!is.na(receiver), !is.na(receiver_jersey_number)) %>%
left_join(
roster,
by = c("season" = "team.season", "posteam" = "team.abbr", "join", "receiver_jersey_number" = "teamPlayers.jerseyNumber")
)
rush <- pbp %>%
group_by(season, posteam, rusher, rusher_jersey_number) %>%
summarise(plays = n()) %>%
mutate(join = stringr::str_extract(rusher, "(?<=\\.[:space:]?)[:graph:]+(?=\\b)")) %>%
filter(!is.na(rusher), !is.na(rusher_jersey_number)) %>%
left_join(
roster,
by = c("season" = "team.season", "posteam" = "team.abbr", "join", "rusher_jersey_number" = "teamPlayers.jerseyNumber")
)
join_error_rush <- rush %>% filter(is.na(teamPlayers.position))
join_error_rec <- rec %>% filter(is.na(teamPlayers.position))
join_error_pass <- pass %>% filter(is.na(teamPlayers.position))
join_error <- dplyr::bind_rows(join_error_pass, join_error_rec, join_error_rush) %>%
dplyr::select(
season, posteam, join, plays,
passer, passer_jersey_number,
rusher, rusher_jersey_number,
receiver, receiver_jersey_number
) %>%
dplyr::arrange(desc(plays))