Skip to content

Commit

Permalink
Fixes to reconcile with GC and nflscrapR
Browse files Browse the repository at this point in the history
  • Loading branch information
guga31bb committed Apr 27, 2020
1 parent 843f94f commit 9627da7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 29 additions & 0 deletions R/helper_scrape_rs.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,37 @@ get_pbp_rs <- function(gameId) {
scoring_team_abbr = scoring_team_id,
scoring_team_id = scoring_team_eid,
quarter_end = end_quarter
) %>%
dplyr::mutate(
# Fill in the rows with missing posteam with the lag:
posteam = dplyr::if_else(
(quarter_end == 1 | play_type == "TIMEOUT"),
dplyr::lag(posteam),
posteam),
posteam_id = dplyr::if_else(
(quarter_end == 1 | play_type == "TIMEOUT"),
dplyr::lag(posteam_id),
posteam_id),
yardline = dplyr::if_else(
((quarter_end == 1 | play_type == "TIMEOUT") & is.na(yardline)),
dplyr::lag(yardline),
yardline),
yardline_side = dplyr::if_else(
((quarter_end == 1 | play_type == "TIMEOUT") & is.na(yardline_side)),
dplyr::lag(yardline_side),
yardline_side),
yardline_number = dplyr::if_else(
((quarter_end == 1 | play_type == "TIMEOUT") & is.na(yardline_number)),
dplyr::lag(yardline_number),
yardline_number),
yardline_side = dplyr::if_else(
yardline_number == 50,
"MID",
yardline_side
)
)


# fix for missing quarter in these games
if (gameId == 2002090803 | game_info$season[1] == 2000) {
plays <- plays %>% dplyr::mutate(
Expand Down
2 changes: 0 additions & 2 deletions R/helper_tidy_play_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ sum_play_stats <- function(play_Id, stats) {
row$kickoff_out_of_bounds <- 1
row$kickoff_attempt <- 1
row$return_team <- play_stats$teamAbbr[index]
row$kicker_player_id <- play_stats$player.esbId[index]
row$kicker_player_name <- play_stats$player.displayName[index]
} else if (play_stats$statId[index] == 50) {
row$kickoff_fair_catch <- 1
row$kickoff_attempt <- 1
Expand Down

0 comments on commit 9627da7

Please sign in to comment.