nflverse / nflfastR

A Set of Functions to Efficiently Scrape NFL Play by Play Data
https://www.nflfastr.com/
Other
414 stars 50 forks source link

PBP Scores are off esp. in 2022 #466

Closed mrcaseb closed 4 months ago

mrcaseb commented 4 months ago

image

mrcaseb commented 4 months ago

Example code, no reprex but working on my local machine

pbp_db |> 
  group_by(game_id) |> 
  summarise(
    away_score = last(away_score),
    home_score = last(home_score),
    away_pbp = last(total_away_score),
    home_pbp = last(total_home_score),
    season = last(season)
  ) |> 
  mutate(
    away_wrong = away_score != away_pbp,
    home_wrong = home_score != home_pbp,
  ) |> 
  filter(
    away_wrong == TRUE | home_wrong == TRUE
  ) |> 
  arrange(game_id) |> 
  collect() |> 
  group_by(season) |> 
  gt() |> 
  cols_label(
    contains("away") ~ "A",
    contains("home") ~ "H"
  ) |> 
  cols_hide(ends_with("wrong")) |> 
  gt_table_theme() |> 
  tab_spanner("Scores", contains("score")) |> 
  tab_spanner("PBP Scores", contains("pbp")) |> 
  cols_width(
    !contains("game_id") ~ px(40),
    TRUE ~ px(125)
  ) |> 
  tab_style(cell_borders("left"), locations = cells_body("away_pbp"))
guga31bb commented 4 months ago

Probably something dumb with return TDs again