Skip to content

Commit

Permalink
10 request advanced season stats for all positions (#12)
Browse files Browse the repository at this point in the history
* Renamed helpers.R to helpers_stats.R to develop more helper functions in separate files

* Helpers to clean up rosters like player names and teams for continuity

* Obtain player snap share filtered for position and season

* Capabilities to obtain advanced stats with NFL Next Gen Stats (NGS) and Pro Football Reference (PFR) with an additional helpers file to validate if seasons within range of data

* Helper functions replace_team_names and replace_player_names now include documentation formatted for use with roxygen2

* Modified function documentation to fix warnings when installing

* Function to obtain player data for season and position, allows for obtaining player IDs for several platforms

* pkgdown build for GitHub site documentation

* Minor updates to stats for pbp/pfr. Update to ngs stats, don't need to use summarize. NGS stats are cumulative when you define week == 0

* Minor updates to all arguments so all season arguments are seasons and all position arguments are labeled as position

* Combine all WR stats from pbp, pfr, ngs

* Modify replace_player_names() to allow for defining the name of the column containing a player's name, so that it can be used on all functions

* New capabilities with functions to get QB/RB/WR/TE season stats from play-by-play data, NFL Next Gen Stats (NGS) and Pro Football Reference (PFR). Functions still need documentation

* Update documentation and site to fully resolve issue
  • Loading branch information
nolmacdonald authored Oct 7, 2024
1 parent 5967869 commit efd74fd
Show file tree
Hide file tree
Showing 80 changed files with 9,355 additions and 1,042 deletions.
18 changes: 18 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,30 @@ export(calc_fpts)
export(calc_fpts_common_formats)
export(calc_fpts_ppg_common_formats)
export(get_pbp_data)
export(get_player_data)
export(get_qb_combined_stats_season)
export(get_qb_ngs_advstats_season)
export(get_qb_pbp_stats)
export(get_qb_pfr_advstats_season)
export(get_rb_combined_stats_season)
export(get_rb_ngs_advstats_season)
export(get_rb_pbp_stats)
export(get_rb_pfr_advstats_season)
export(get_snap_share)
export(get_te_combined_stats_season)
export(get_te_ngs_advstats_season)
export(get_te_pbp_stats)
export(get_te_pfr_advstats_season)
export(get_wr_combined_stats_season)
export(get_wr_ngs_advstats_season)
export(get_wr_pbp_stats)
export(get_wr_pfr_advstats_season)
export(load_data_from_db)
export(load_data_from_nflreadr)
export(replace_player_names)
export(replace_team_names)
export(validate_ngs_season)
export(validate_pbp_db)
export(validate_pbp_season)
export(validate_pbp_weeks)
export(validate_pfr_season)
88 changes: 84 additions & 4 deletions R/calculate_fpts.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
################################################################################
# Author: Nolan MacDonald
# Purpose:
# Calculate total fantasy points and points per game (PPG) based on standard
# scoring formats.
# Code Style Guide:
# styler::tidyverse_style(), lintr::use_lintr(type = "tidyverse")
################################################################################

#' Calculate Fantasy Points
#'
#' @description
#' Calculate fantasy points using play-by-play and data and user-defined
#' scoring settings (e.g., 6PT PASS TD, -2 PASS INT, Full PPR)
#'
#'
#' @param pbp Play-by-play Dataframe
#' @param pass_td_pts Passing Touchdown Points
#' @param pass_int_pts Passing Interception Points
#' @param rec_pts Reception Points
#'
#' @return
#' Calculate fantasy points using play-by-play and data and user-defined
#' Dataframe with total fantasy points using play-by-play data and user-defined
#' scoring settings (e.g., 6PT PASS TD, -2 PASS INT, Full PPR)
#'
#' @author Nolan MacDonald
Expand Down Expand Up @@ -38,11 +52,69 @@ calc_fpts <- function(pbp = pbp,

#' Calculate Fantasy Points for Common Scoring Formats
#'
#' @param pbp Play-by-play Dataframe
#' @description
#' Calculate fantasy points using play-by-play data and common
#' scoring settings (i.e., 4/6PT PASS TD, -2 PASS INT, STD/Half PPR/Full PPR)
#'
#' @param pbp Play-by-play Data frame
#'
#' @return
#' Calculate fantasy points using play-by-play and data and common
#' Data frame with total fantasy points for common
#' scoring settings (i.e., 4/6PT PASS TD, -2 PASS INT, STD/Half PPR/Full PPR)
#'
#' @seealso \code{\link[nuclearff]{calc_fpts}}
#' Calculate total fantasy points
#'
#' @author Nolan MacDonald
#'
#' @format A data frame with 79 variables that are described below.
#' \describe{
#' \item{\code{fpts_std_4pt_td}}{
#' Total fantasy points for standard scoring with 4 point touchdowns
#' }
#' \item{\code{ppg_std_4pt_td}}{
#' Points per game (PPG) for standard scoring with 4 point touchdowns
#' }
#' \item{\code{fpts_half_ppr_4pt_td}}{
#' Total fantasy points for half point per reception (Half PPR) scoring
#' with 4 point touchdowns
#' }
#' \item{\code{ppg_half_ppr_4pt_td}}{
#' Points per game (PPG) for half point per reception (Half PPR) scoring
#' with 4 point touchdowns
#' }
#' \item{\code{fpts_ppr_4pt_td}}{
#' Total fantasy points for point per reception (full PPR) scoring with
#' 4 point touchdowns
#' }
#' \item{\code{ppg_ppr_4pt_td}}{
#' Points per game (PPG) for point per reception (Full PPR) scoring
#' with 4 point touchdowns
#' }
#' \item{\code{fpts_std_6pt_td}}{
#' Total fantasy points for standard scoring with 6 point touchdowns
#' }
#' \item{\code{ppg_std_6pt_td}}{
#' Points per game (PPG) for standard scoring with 6 point touchdowns
#' }
#' \item{\code{fpts_half_ppr_6pt_td}}{
#' Total fantasy points for half point per reception (Half PPR) scoring
#' with 6 point touchdowns
#' }
#' \item{\code{ppg_half_ppr_6pt_td}}{
#' Points per game (PPG) for half point per reception (Half PPR) scoring
#' with 6 point touchdowns
#' }
#' \item{\code{fpts_ppr_6pt_td}}{
#' Total fantasy points for point per reception (full PPR) scoring with
#' 6 point touchdowns
#' }
#' \item{\code{ppg_ppr_6pt_td}}{
#' Points per game (PPG) for point per reception (Full PPR) scoring
#' with 6 point touchdowns
#' }
#' }
#'
#' @export
calc_fpts_common_formats <- function(pbp = pbp)
{
Expand Down Expand Up @@ -105,11 +177,19 @@ calc_fpts_common_formats <- function(pbp = pbp)

#' Calculate Fantasy Points Per Game for Common Scoring Formats
#'
#' @description
#' Calculate fantasy points per game using play-by-play and data and common
#' scoring settings (i.e., 4/6PT PASS TD, -2 PASS INT, STD/Half PPR/Full PPR)
#'
#'
#' @param pbp Play-by-play Dataframe
#'
#' @return
#' Calculate fantasy points per game using play-by-play and data and common
#' Dataframe with fantasy points per game (PPG) using common
#' scoring settings (i.e., 4/6PT PASS TD, -2 PASS INT, STD/Half PPR/Full PPR)
#'
#' @author Nolan MacDonald
#'
#' @export
calc_fpts_ppg_common_formats <- function(pbp = pbp)
{
Expand Down
Loading

0 comments on commit efd74fd

Please sign in to comment.