Skip to content

Commit

Permalink
Merge pull request #146 from mrcaseb/series_fix
Browse files Browse the repository at this point in the history
fix series and fixed_drive for muffed punts
  • Loading branch information
guga31bb authored Dec 13, 2020
2 parents bbdeae8 + fbbb51b commit 0ab81be
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 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 (#125)

# nflfastR 3.2.0

## Models
Expand Down
7 changes: 6 additions & 1 deletion R/helper_add_fixed_drives.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion R/helper_add_series_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 6 additions & 2 deletions R/helper_additional_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ab81be

Please sign in to comment.