diff --git a/.github/workflows/automated_pbp_update.yaml b/.github/workflows/automated_pbp_update.yaml index fe7bff6d..e86729f8 100644 --- a/.github/workflows/automated_pbp_update.yaml +++ b/.github/workflows/automated_pbp_update.yaml @@ -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")' diff --git a/R/update_playstats.R b/R/update_playstats.R new file mode 100644 index 00000000..e83517a2 --- /dev/null +++ b/R/update_playstats.R @@ -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)