Skip to content

Commit

Permalink
add defense player stats
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaseb committed Aug 17, 2023
1 parent 818bf2c commit 8f5c211
Show file tree
Hide file tree
Showing 2 changed files with 47 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 @@ -42,6 +42,9 @@ jobs:
- name: Run player_stats script
run: Rscript -e 'source("R/update_player_stats.R")'

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

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

Expand Down
44 changes: 44 additions & 0 deletions R/update_player_stats_def.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ps_season <- function(season) {
cli::cli_progress_step("Starting {.fct nflfastR::calculate_player_stats_def} for {season}!")

ps <- nflreadr::load_pbp(season) |>
nflfastR::calculate_player_stats_def(weekly = TRUE)

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

nflversedata::nflverse_save(
data_frame = ps,
file_name = glue::glue("player_stats_def_{season}"),
nflverse_type = "player stats: defense",
release_tag = "player_stats",
file_types = c("rds", "csv", "parquet", "qs", "csv.gz")
)

cli::cli_progress_done()

invisible(NULL)
}

if (Sys.getenv("NFLVERSE_REBUILD", "false") == "true") {
purrr::walk(1999:nflreadr:::most_recent_season(), ps_season)
} else {
ps_season(nflreadr:::most_recent_season())
}

cli::cli_alert_info("Saving combined data...")
stats_df <-
purrr::map(
1999:nflreadr::most_recent_season(),
~ nflreadr::qs_from_url(glue::glue("https://github.com/nflverse/nflverse-data/releases/download/player_stats/player_stats_def_{.x}.qs"))
) |>
purrr::list_rbind()

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

nflversedata::nflverse_save(
data_frame = stats_df,
file_name = "player_stats_def",
nflverse_type = "player stats: defense",
release_tag = "player_stats",
file_types = c("rds", "csv", "parquet", "qs", "csv.gz")
)

0 comments on commit 8f5c211

Please sign in to comment.