From 6ae6b431666659ebf1d1d4c2451bfff3b1418aec Mon Sep 17 00:00:00 2001 From: Sebastian Carl Date: Wed, 13 Nov 2024 15:12:48 +0100 Subject: [PATCH] don't release empty data --- R/update_stats.R | 138 ++++++++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 61 deletions(-) diff --git a/R/update_stats.R b/R/update_stats.R index 0c007c4f..2cd1bc0e 100644 --- a/R/update_stats.R +++ b/R/update_stats.R @@ -17,21 +17,25 @@ release_stats <- function(season){ ) attr(stats_week_team, "nflfastR_version") <- as.character(packageVersion("nflfastR")) - nflversedata::nflverse_save( - data_frame = stats_week_player, - file_name = glue::glue("stats_player_week_{season}"), - nflverse_type = "player stats: week level", - release_tag = "player_stats", - file_types = c("rds", "csv", "parquet", "qs", "csv.gz") - ) - - nflversedata::nflverse_save( - data_frame = stats_week_team, - file_name = glue::glue("stats_team_week_{season}"), - nflverse_type = "team stats: week level", - release_tag = "player_stats", - file_types = c("rds", "csv", "parquet", "qs", "csv.gz") - ) + if (nrow(stats_week_player) > 0){ + nflversedata::nflverse_save( + data_frame = stats_week_player, + file_name = glue::glue("stats_player_week_{season}"), + nflverse_type = "player stats: week level", + release_tag = "player_stats", + file_types = c("rds", "csv", "parquet", "qs", "csv.gz") + ) + } + + if (nrow(stats_week_team) > 0){ + nflversedata::nflverse_save( + data_frame = stats_week_team, + file_name = glue::glue("stats_team_week_{season}"), + nflverse_type = "team stats: week level", + release_tag = "player_stats", + file_types = c("rds", "csv", "parquet", "qs", "csv.gz") + ) + } # PLAYER SEASON LEVEL SUMMARY ################################################ @@ -59,29 +63,35 @@ release_stats <- function(season){ ) attr(stats_regpost_player, "nflfastR_version") <- as.character(packageVersion("nflfastR")) - nflversedata::nflverse_save( - data_frame = stats_reg_player, - file_name = glue::glue("stats_player_reg_{season}"), - nflverse_type = "player stats: season level", - release_tag = "player_stats", - file_types = c("rds", "csv", "parquet", "qs", "csv.gz") - ) - - nflversedata::nflverse_save( - data_frame = stats_post_player, - file_name = glue::glue("stats_player_post_{season}"), - nflverse_type = "team stats: season level", - release_tag = "player_stats", - file_types = c("rds", "csv", "parquet", "qs", "csv.gz") - ) - - nflversedata::nflverse_save( - data_frame = stats_regpost_player, - file_name = glue::glue("stats_player_regpost_{season}"), - nflverse_type = "team stats: season level", - release_tag = "player_stats", - file_types = c("rds", "csv", "parquet", "qs", "csv.gz") - ) + if (nrow(stats_reg_player) > 0){ + nflversedata::nflverse_save( + data_frame = stats_reg_player, + file_name = glue::glue("stats_player_reg_{season}"), + nflverse_type = "player stats: season level", + release_tag = "player_stats", + file_types = c("rds", "csv", "parquet", "qs", "csv.gz") + ) + } + + if (nrow(stats_post_player) > 0){ + nflversedata::nflverse_save( + data_frame = stats_post_player, + file_name = glue::glue("stats_player_post_{season}"), + nflverse_type = "team stats: season level", + release_tag = "player_stats", + file_types = c("rds", "csv", "parquet", "qs", "csv.gz") + ) + } + + if (nrow(stats_regpost_player) > 0){ + nflversedata::nflverse_save( + data_frame = stats_regpost_player, + file_name = glue::glue("stats_player_regpost_{season}"), + nflverse_type = "team stats: season level", + release_tag = "player_stats", + file_types = c("rds", "csv", "parquet", "qs", "csv.gz") + ) + } # TEAM SEASON LEVEL SUMMARY ################################################## @@ -109,29 +119,35 @@ release_stats <- function(season){ ) attr(stats_regpost_team, "nflfastR_version") <- as.character(packageVersion("nflfastR")) - nflversedata::nflverse_save( - data_frame = stats_reg_team, - file_name = glue::glue("stats_team_reg_{season}"), - nflverse_type = "player stats: season level", - release_tag = "player_stats", - file_types = c("rds", "csv", "parquet", "qs", "csv.gz") - ) - - nflversedata::nflverse_save( - data_frame = stats_post_team, - file_name = glue::glue("stats_team_post_{season}"), - nflverse_type = "team stats: season level", - release_tag = "player_stats", - file_types = c("rds", "csv", "parquet", "qs", "csv.gz") - ) - - nflversedata::nflverse_save( - data_frame = stats_regpost_team, - file_name = glue::glue("stats_team_regpost_{season}"), - nflverse_type = "team stats: season level", - release_tag = "player_stats", - file_types = c("rds", "csv", "parquet", "qs", "csv.gz") - ) + if (nrow(stats_reg_team) > 0){ + nflversedata::nflverse_save( + data_frame = stats_reg_team, + file_name = glue::glue("stats_team_reg_{season}"), + nflverse_type = "player stats: season level", + release_tag = "player_stats", + file_types = c("rds", "csv", "parquet", "qs", "csv.gz") + ) + } + + if (nrow(stats_post_team) > 0){ + nflversedata::nflverse_save( + data_frame = stats_post_team, + file_name = glue::glue("stats_team_post_{season}"), + nflverse_type = "team stats: season level", + release_tag = "player_stats", + file_types = c("rds", "csv", "parquet", "qs", "csv.gz") + ) + } + + if (nrow(stats_regpost_team) > 0){ + nflversedata::nflverse_save( + data_frame = stats_regpost_team, + file_name = glue::glue("stats_team_regpost_{season}"), + nflverse_type = "team stats: season level", + release_tag = "player_stats", + file_types = c("rds", "csv", "parquet", "qs", "csv.gz") + ) + } cli::cli_progress_done() invisible(NULL)