Skip to content

Commit

Permalink
add playstats code
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaseb committed Nov 28, 2023
1 parent 0df81eb commit f8cd258
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/automated_pbp_update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- name: Run pbp update
run: Rscript -e 'source("R/update_pbp.R")'

- name: Run play stats update
run: Rscript -e 'source("R/update_playstats.R")'

- name: Run player_stats script
run: Rscript -e 'source("R/update_player_stats.R")'

Expand Down
25 changes: 25 additions & 0 deletions R/update_playstats.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
save_playstats <- function(season) {

playstats <- nflfastR:::build_playstats(seasons = season)

attr(playstats,"nflfastR_version") <- packageVersion("nflfastR")

nflversedata::nflverse_save(
data_frame = playstats,
file_name = glue::glue("play_stats_{season}"),
nflverse_type = "play by play stats",
release_tag = "playstats",
file_types = c("rds"),
repo = "nflverse/nflverse-pbp"
)

cli::cli_alert_success("Saved {season} play stats data.")
}

future::plan(future::multisession)
if(Sys.getenv("NFLVERSE_REBUILD","false")=="true"){
purrr::walk(1999:nflreadr::most_recent_season(), save_playstats)
} else {
save_playstats(nflreadr::most_recent_season())
}
future::plan(future::sequential)

0 comments on commit f8cd258

Please sign in to comment.