Skip to content

Commit

Permalink
Merge pull request #422 from nflverse/fix-kick-distance
Browse files Browse the repository at this point in the history
set kick distance through stat ids
  • Loading branch information
mrcaseb authored Aug 31, 2023
2 parents d5d9d68 + 85ddd92 commit 76e100c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 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: 4.5.1.9007
Version: 4.5.1.9008
Authors@R:
c(person(given = "Sebastian",
family = "Carl",
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- The function `calculate_series_conversion_rates()` no longer returns `NA` values if a small subset of pbp data is missing series on offense or defense. (#417)
- `fixed_drive` now correctly increments on plays where posteam lost a fumble but remains posteam because defteam also lost a fumble during the same play. (#419)
- nflfastR now fixes missing drive number counts in raw pbp data in order to provide accurate drive information. (#420)
- nflfastR now returns `kick_distance` on punts and kickoffs resulting in touchbacks. (#421)
- nflfastR now returns correct `kick_distance` on all punts and kickoffs. (#422)


# nflfastR 4.5.1
Expand Down
5 changes: 5 additions & 0 deletions R/helper_tidy_play_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ sum_play_stats <- function(play_Id, stats) {
row$punter_player_name <- play_stats$player.displayName[index]
row$kick_distance <- play_stats$yards[index]
} else if (stat_id == 30) {
# yards always zero for stat_id 30 (punt inside 20) so we don't write kick_distance here
row$punt_inside_twenty <- 1
row$punt_attempt <- 1
row$punter_player_id <- play_stats$player.esbId[index]
Expand All @@ -218,6 +219,7 @@ sum_play_stats <- function(play_Id, stats) {
row$kick_distance <- play_stats$yards[index]
} else if (stat_id == 32) {
row$punt_attempt <- 1
row$kick_distance <- play_stats$yards[index]
row$punter_player_id <- play_stats$player.esbId[index]
row$punter_player_name <- play_stats$player.displayName[index]
} else if (stat_id == 33) {
Expand Down Expand Up @@ -283,17 +285,20 @@ sum_play_stats <- function(play_Id, stats) {
row$kicker_player_name <- play_stats$player.displayName[index]
row$kick_distance <- play_stats$yards[index]
} else if (stat_id == 42) {
# yards always zero for stat_id 42 so we don't write kick_distance here
row$kickoff_inside_twenty <- 1
row$kickoff_attempt <- 1
row$kicker_player_id <- play_stats$player.esbId[index]
row$kicker_player_name <- play_stats$player.displayName[index]
} else if (stat_id == 43) {
row$kickoff_in_endzone <- 1
row$kickoff_attempt <- 1
row$kick_distance <- play_stats$yards[index]
row$kicker_player_id <- play_stats$player.esbId[index]
row$kicker_player_name <- play_stats$player.displayName[index]
} else if (stat_id == 44) {
row$kickoff_attempt <- 1
row$kick_distance <- play_stats$yards[index]
row$kicker_player_id <- play_stats$player.esbId[index]
row$kicker_player_name <- play_stats$player.displayName[index]
} else if (stat_id == 45) {
Expand Down
Binary file modified tests/testthat/expected_pbp.rds
Binary file not shown.

0 comments on commit 76e100c

Please sign in to comment.