Skip to content

Commit

Permalink
Fix groups for team targets and team air yards
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaseb committed Jan 5, 2025
1 parent 363344d commit 2308d30
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: nflfastR
Title: Functions to Efficiently Access NFL Play by Play Data
Version: 5.0.0.9001
Version: 5.0.0.9002
Authors@R:
c(person(given = "Sebastian",
family = "Carl",
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Fixed a bug where `calculate_stats()` incorrectly counted `receiving_air_yards`. (#500)
- Fixed a bug where `vegas_wp` variables were broken when `spread_line` data was missing. (#503)
- Fixed a bug where `calculate_stats()` incorrectly calculated `target_share` and `air_yards_share` when `summary_level = "season"`. (#505)

# nflfastR 5.0.0

Expand Down
8 changes: 6 additions & 2 deletions R/calculate_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ calculate_stats <- function(seasons = nflreadr::most_recent_season(),
team_stats = paste0(paste(stat_id, collapse = ";"), ";"),
team_play_air_yards = sum((stat_id %in% 111:112) * yards)
) %>%
dplyr::group_by(.data$season, .data$week, .data$team) %>%
# compute team targets and team air yards for calculation of target share
# and air yard share. Since it's relative, we need to be careful with the groups
# depending on summary level
dplyr::group_by(!!!rlang::data_syms(
if (summary_level == "season") c("season", "team") else c("season", "week", "team")
)) %>%
dplyr::mutate(
# for calculation of target share and air yard share
team_targets = sum(stat_id == 115),
team_air_yards = sum((stat_id %in% 111:112) * yards)
) %>%
Expand Down

0 comments on commit 2308d30

Please sign in to comment.