From 28376830e3e488a8218b9f7894432d71ef95c74f Mon Sep 17 00:00:00 2001 From: Ben Baldwin <1425357+guga31bb@users.noreply.github.com> Date: Sat, 12 Dec 2020 14:02:05 -0500 Subject: [PATCH 1/5] fix series and fixed_drive for muffed punts --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/helper_add_fixed_drives.R | 7 ++++++- R/helper_add_series_data.R | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f8480a94..6110ddab 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: nflfastR Title: Functions to Efficiently Access NFL Play by Play Data -Version: 3.2.0 +Version: 3.2.0.9000 Authors@R: c(person(given = "Sebastian", family = "Carl", diff --git a/NEWS.md b/NEWS.md index 39b583f5..82fa6890 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# nflfastR (development version) + +* Fix bug where `fixed_drive` and `series` weren't updating after muffed punt [(issue)](https://github.com/mrcaseb/nflfastR/issues/144) + # nflfastR 3.2.0 ## Models diff --git a/R/helper_add_fixed_drives.R b/R/helper_add_fixed_drives.R index 8999702f..d0fa0ebf 100644 --- a/R/helper_add_fixed_drives.R +++ b/R/helper_add_fixed_drives.R @@ -35,6 +35,11 @@ add_drive_results <- function(d) { & !is.na(dplyr::lag(.data$posteam)), 0, .data$new_drive), + # if same team has the ball as prior play, but prior play was a punt with lost fumble, it's a new drive + new_drive = dplyr::if_else( + .data$posteam == dplyr::lag(.data$posteam) & dplyr::lag(.data$fumble_lost == 1) & dplyr::lag(.data$play_type) == "punt", + 1, .data$new_drive + ), # first observation of a half is also a new drive new_drive = dplyr::if_else(.data$row == 1, 1, .data$new_drive), # if there's a missing, make it not a new drive (0) @@ -49,8 +54,8 @@ add_drive_results <- function(d) { .data$field_goal_result == "made" ~ "Field goal", .data$field_goal_result %in% c("blocked", "missed") ~ "Missed field goal", .data$safety == 1 ~ "Safety", - .data$interception == 1 | .data$fumble_lost == 1 ~ "Turnover", .data$play_type == "punt" | .data$punt_attempt == 1 ~ "Punt", + .data$interception == 1 | .data$fumble_lost == 1 ~ "Turnover", .data$down == 4 & .data$yards_gained < .data$ydstogo & .data$play_type != "no_play" ~ "Turnover on downs", .data$desc %in% c("END GAME", "END QUARTER 2", "END QUARTER 4") ~ "End of half" ) diff --git a/R/helper_add_series_data.R b/R/helper_add_series_data.R index 2f051078..b6ac56d4 100644 --- a/R/helper_add_series_data.R +++ b/R/helper_add_series_data.R @@ -44,8 +44,8 @@ add_series_data <- function(pbp) { .data$field_goal_result == "made" ~ "Field goal", .data$field_goal_result %in% c("blocked", "missed") ~ "Missed field goal", .data$safety == 1 ~ "Safety", - .data$interception == 1 | .data$fumble_lost == 1 ~ "Turnover", .data$play_type == "punt" | .data$punt_attempt == 1 ~ "Punt", + .data$interception == 1 | .data$fumble_lost == 1 ~ "Turnover", .data$down == 4 & .data$yards_gained < .data$ydstogo & .data$play_type != "no_play" ~ "Turnover on downs", .data$qb_kneel == 1 ~ "QB kneel", .data$desc %in% c("END GAME", "END QUARTER 2", "END QUARTER 4") ~ "End of half" From c10fd1902c61f1ada59ac34cd8defc4700f68648 Mon Sep 17 00:00:00 2001 From: Ben Baldwin <1425357+guga31bb@users.noreply.github.com> Date: Sat, 12 Dec 2020 14:39:51 -0500 Subject: [PATCH 2/5] update how issue is linked --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 82fa6890..56e590f9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # nflfastR (development version) -* Fix bug where `fixed_drive` and `series` weren't updating after muffed punt [(issue)](https://github.com/mrcaseb/nflfastR/issues/144) +* Fix bug where `fixed_drive` and `series` weren't updating after muffed punt (#144) # nflfastR 3.2.0 From cff2e42c1390990fe60a7f1e871840830a628432 Mon Sep 17 00:00:00 2001 From: Ben Baldwin <1425357+guga31bb@users.noreply.github.com> Date: Sat, 12 Dec 2020 14:57:02 -0500 Subject: [PATCH 3/5] fix pass detection --- R/helper_additional_functions.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/helper_additional_functions.R b/R/helper_additional_functions.R index 8eaa100f..f836261b 100644 --- a/R/helper_additional_functions.R +++ b/R/helper_additional_functions.R @@ -96,15 +96,19 @@ clean_pbp <- function(pbp, ...) { ), #if no pass is thrown, there shouldn't be a receiver receiver = dplyr::if_else( - stringr::str_detect(.data$desc, ' pass'), .data$receiver, NA_character_ + stringr::str_detect(.data$desc, ' pass '), .data$receiver, NA_character_ ), # if there's a pass, sack, or scramble, it's a pass play... - pass = dplyr::if_else(stringr::str_detect(.data$desc, "( pass)|(sacked)|(scramble)"), 1, 0), + pass = dplyr::if_else(stringr::str_detect(.data$desc, "( pass )|(sacked)|(scramble)"), 1, 0), # ...unless it says "backwards pass" and there's a rusher pass = dplyr::if_else( stringr::str_detect(.data$desc, "(backward pass)|(Backward pass)") & !is.na(.data$rusher), 0, .data$pass ), + # and make sure there's no pass on a kickoff (sometimes there's forward pass on kickoff but that's not a pass play) + pass = dplyr::if_else( + .data$kickoff_attempt == 1, 0, .data$pass + ), #if there's a rusher and it wasn't a QB kneel or pass play, it's a run play rush = dplyr::if_else(!is.na(.data$rusher) & .data$qb_kneel == 0 & .data$pass == 0, 1, 0), #fix some common QBs with inconsistent names From 5f965e94337e02dbc3c2aae70ce8655643233dcf Mon Sep 17 00:00:00 2001 From: Ben Baldwin <1425357+guga31bb@users.noreply.github.com> Date: Sat, 12 Dec 2020 14:57:52 -0500 Subject: [PATCH 4/5] news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 56e590f9..a8f0f58b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # nflfastR (development version) * Fix bug where `fixed_drive` and `series` weren't updating after muffed punt (#144) +* Fix bug where some special teams plays were incorrectly being labeled as pass plays (#131) # nflfastR 3.2.0 From fbbb51b7a49fe1ac6dcae45b4cb918732e931ec8 Mon Sep 17 00:00:00 2001 From: Ben Baldwin <1425357+guga31bb@users.noreply.github.com> Date: Sat, 12 Dec 2020 14:58:19 -0500 Subject: [PATCH 5/5] wrong number lol --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index a8f0f58b..63e6d8d6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ # nflfastR (development version) * Fix bug where `fixed_drive` and `series` weren't updating after muffed punt (#144) -* Fix bug where some special teams plays were incorrectly being labeled as pass plays (#131) +* Fix bug where some special teams plays were incorrectly being labeled as pass plays (#125) # nflfastR 3.2.0