Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new function calculate_stats() #470

Merged
merged 38 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d89f2f8
update stat_ids
mrcaseb Jul 2, 2024
6cea069
News and documentation
mrcaseb Jul 2, 2024
0a01a16
start `calculate_stats()`
mrcaseb Jul 2, 2024
1b1f831
rushing/receiving yards and tds should include the stat ids for laterals
mrcaseb Jul 2, 2024
6f614c2
include half sacks and corresponding yards
mrcaseb Jul 3, 2024
58d13d0
add play information to stats df
mrcaseb Jul 3, 2024
7f01b16
implement special teams tds and defensive tds
mrcaseb Jul 3, 2024
59b2e1b
try to avoid non matches because of different team abbrs
mrcaseb Jul 3, 2024
f59b2e6
implement fumble recoveries
mrcaseb Jul 3, 2024
72884c3
more stuff (I forgot what I did here tbh)
mrcaseb Aug 2, 2024
b367fb4
add pbp stats, add documentation, combine all
mrcaseb Oct 15, 2024
7942ae7
Merge branch 'master' into new-stats-approach
mrcaseb Oct 15, 2024
d3075b1
News update
mrcaseb Oct 15, 2024
d807a30
remove irrelevant comments
mrcaseb Oct 15, 2024
a679cd3
fix pkgdown
mrcaseb Oct 16, 2024
49aefe8
add season_type and team info and fix yac stats
mrcaseb Oct 16, 2024
1d99b23
add cpoe and number of games
mrcaseb Oct 16, 2024
5c07c0a
users should be able to do the rounding themselves
mrcaseb Oct 16, 2024
bb8e20c
deleted the dot
mrcaseb Oct 16, 2024
fba04c0
implement game winning field goals
mrcaseb Oct 16, 2024
627d6a6
team variable naming consistency
mrcaseb Oct 16, 2024
28db290
add variable description
mrcaseb Oct 16, 2024
1fef4d3
fix pkgdown
mrcaseb Oct 16, 2024
5e61d0d
test column names and row numbers
mrcaseb Oct 16, 2024
34bd7ea
fix check notes
mrcaseb Oct 16, 2024
60e1e4b
not all of these are def stats actually
mrcaseb Nov 3, 2024
5401559
adjust variable explainer after def modifications
mrcaseb Nov 3, 2024
b0b9dd6
Merge branch 'master' into new-stats-approach
mrcaseb Nov 3, 2024
d0f1485
falsely counted team air yards of all game instead of play
mrcaseb Nov 3, 2024
5aa1d80
Merge branch 'new-stats-approach' of https://github.com/nflverse/nflf…
mrcaseb Nov 3, 2024
8d45b29
Add punt/kickoff returns and yardage
mrcaseb Nov 3, 2024
fd648dc
add timeouts
mrcaseb Nov 3, 2024
74094b2
Version bump and news bullet for nfl_stats_variables
mrcaseb Nov 3, 2024
cb83260
document differences to old stats
mrcaseb Nov 9, 2024
2d7a0e7
use player short name from playstats
mrcaseb Nov 9, 2024
457e5d6
deprecate old stats functions
mrcaseb Nov 10, 2024
ea1fa2c
Describe variable name differences
mrcaseb Nov 10, 2024
e1f357f
snapshot test variable types
mrcaseb Nov 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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: 4.6.1.9018
Version: 4.6.1.9019
Authors@R:
c(person(given = "Sebastian",
family = "Carl",
Expand Down Expand Up @@ -51,6 +51,7 @@ Imports:
future,
glue,
janitor,
lifecycle,
mgcv,
nflreadr (>= 1.2.0),
progressr (>= 0.6.0),
Expand All @@ -63,7 +64,6 @@ Imports:
Suggests:
DBI,
gsisdecoder,
lifecycle (>= 0.2.0),
nflseedR (>= 1.0.2),
purrr (>= 0.3.0),
rmarkdown,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(calculate_player_stats_def)
export(calculate_player_stats_kicking)
export(calculate_series_conversion_rates)
export(calculate_standings)
export(calculate_stats)
export(calculate_win_probability)
export(clean_pbp)
export(decode_player_ids)
Expand All @@ -27,6 +28,7 @@ import(dplyr)
import(fastrmodels)
importFrom(cli,rule)
importFrom(curl,curl_fetch_memory)
importFrom(data.table,"%between%")
importFrom(data.table,"%chin%")
importFrom(data.table,setDT)
importFrom(furrr,future_map)
Expand All @@ -36,11 +38,13 @@ importFrom(future,plan)
importFrom(glue,glue)
importFrom(glue,glue_sql)
importFrom(janitor,clean_names)
importFrom(lifecycle,deprecated)
importFrom(mgcv,predict.bam)
importFrom(nflreadr,nflverse_sitrep)
importFrom(progressr,progressor)
importFrom(rlang,":=")
importFrom(rlang,.data)
importFrom(rlang,.env)
importFrom(rlang,dots_list)
importFrom(rlang,inform)
importFrom(stats,na.omit)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
- `punter_player_id`, and `punter_player_name` are filled for blocked punt attempts. (#463)
- Fixed an issue affecting scores of 2022 games involving a return touchdown (#466)
- Added identification of scrambles from 1999 through 2004 with thank to Aaron Schatz (#468, #489)
- Added new function `calculate_stats()` that combines the output of all `calculate_player_stats*()` functions with a more robust and faster approach. The `calculate_player_stats*()` function will be deprecated in a future release. (#470)
- Updated the dataframe `stat_ids` with some IDs that were previously missing. (#470)
- Added new exported dataframe `nfl_stats_variables`. It lists and explains all variables returned by `calculate_stats()`. A searchable table is available at <https://www.nflfastr.com/articles/stats_variables.html>. (#470)
- nflfastR tried to fix bugs in the underlying pbp data of JAX home games prior to the 2016 season. An update of the raw pbp data resolved those bugs so nflfastR needs to remove the hard coded adjustments. This means that nflfastR <= v4.6.1 will return incorrect pbp data for all Jacksonville home games prior to the 2016 season! (#478)
- Fixed a problem where `clean_pbp()` returned `pass = 1` in actual rush plays in very rare cases. (#479)
- Removed extra lines for injury timeouts that were breaking `fixed_drive` (#482)
Expand Down
13 changes: 13 additions & 0 deletions R/aggregate_game_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

#' Get Official Game Stats
#'
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' This function was deprecated because we have a new, much better and
#' harmonized approach in [`calculate_stats()`].
#'
#' @param pbp A Data frame of NFL play-by-play data typically loaded with
#' [load_pbp()] or [build_nflfastR_pbp()]. If the data doesn't include the variable
#' `qb_epa`, the function `add_qb_epa()` will be called to add it.
Expand Down Expand Up @@ -84,6 +90,7 @@
#' \item{fantasy_points_ppr}{PPR fantasy points.}
#' }
#' @export
#' @keywords internal
#' @seealso The function [load_player_stats()] and the corresponding examples
#' on [the nflfastR website](https://www.nflfastr.com/articles/nflfastR.html#example-11-replicating-official-stats)
#' @examples
Expand All @@ -100,6 +107,12 @@
#' }
calculate_player_stats <- function(pbp, weekly = FALSE) {

lifecycle::deprecate_warn(
"5.0",
"calculate_player_stats()",
"calculate_stats()"
)

# need newer version of nflreadr to use load_players
rlang::check_installed("nflreadr (>= 1.3.0)", "to join player information.")

Expand Down
13 changes: 13 additions & 0 deletions R/aggregate_game_stats_def.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

#' Get Official Game Stats on Defense
#'
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' This function was deprecated because we have a new, much better and
#' harmonized approach in [`calculate_stats()`].
#'
#' @param pbp A Data frame of NFL play-by-play data typically loaded with
#' [load_pbp()] or [build_nflfastR_pbp()]. If the data doesn't include the variable
#' `qb_epa`, the function `add_qb_epa()` will be called to add it.
Expand All @@ -14,6 +20,7 @@
#' either at the game level or at the level of the entire data frame passed.
#' @return A data frame of defensive player stats. See dictionary (# TODO)
#' @export
#' @keywords internal
#' @seealso The function [load_player_stats()] and the corresponding examples
#' on [the nflfastR website](https://www.nflfastr.com/articles/nflfastR.html#example-11-replicating-official-stats)
#' @examples
Expand Down Expand Up @@ -59,6 +66,12 @@

calculate_player_stats_def <- function(pbp, weekly = FALSE) {

lifecycle::deprecate_warn(
"5.0",
"calculate_player_stats_def()",
"calculate_stats()"
)

# need newer version of nflreadr to use load_players
rlang::check_installed("nflreadr (>= 1.3.0)")

Expand Down
15 changes: 14 additions & 1 deletion R/aggregate_game_stats_kicking.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#' Summarize Kicking Stats
#'
#' @description Build columns that aggregate kicking stats at the game level.
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' This function was deprecated because we have a new, much better and
#' harmonized approach in [`calculate_stats()`].
#'
#' Build columns that aggregate kicking stats at the game level.
#'
#' @param pbp A Data frame of NFL play-by-play data typically loaded with
#' [load_pbp()] or [build_nflfastR_pbp()].
Expand All @@ -22,8 +28,15 @@
#' @return a dataframe of kicking stats
#' @seealso <https://nflreadr.nflverse.com/reference/load_player_stats.html> for the nflreadr function to download this from repo (`stat_type = "kicking"`)
#' @export
#' @keywords internal
calculate_player_stats_kicking <- function(pbp, weekly = FALSE) {

lifecycle::deprecate_warn(
"5.0",
"calculate_player_stats_kicking()",
"calculate_stats()"
)

# need newer version of nflreadr to use load_players
rlang::check_installed("nflreadr (>= 1.3.0)")

Expand Down
Loading
Loading