diff --git a/DESCRIPTION b/DESCRIPTION index d6397cc..ce862c8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: cbbdata Type: Package Title: API for College Basketball Data -Version: 0.2.0 +Version: 0.3.0 Authors@R: person("Andrew", "Weatherman", email = "andrew@aweatherman.com", role = c("aut", "cre")) Description: Provides direct access to clean and tidy college basketball data using the diff --git a/NAMESPACE b/NAMESPACE index ef64240..8b1ae27 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,11 +2,14 @@ export("%>%") export(cbd_add_net_quad) +export(cbd_all_metrics) +export(cbd_bpi_ratings) export(cbd_create_account) export(cbd_kenpom_authorization) export(cbd_kenpom_ratings) export(cbd_kenpom_ratings_archive) export(cbd_login) +export(cbd_match_teams) export(cbd_teams) export(cbd_torvik_conf_factors) export(cbd_torvik_current_resume) diff --git a/NEWS.md b/NEWS.md index 0fc0d2c..0a11a5f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# cbbdata 0.3.0 +- Added [`cbd_bpi_ratings`](https://cbbdata.aweatherman.com/reference/cbd_bpi_ratings.html) to pull current ESPN BPI ratings + rankings, SOR/SOS, and tournament projections. +- Added [`cbd_all_metrics`](https://cbbdata.aweatherman.com/reference/cbd_all_metrics.html) to source Torvik, KenPom, BPI, SOR/SOS, and NET in one unified tibble. +- Added [`cbd_match_teams`](https://cbbdata.aweatherman.com/reference/cbd_match_teams.html) to build a team-matching named vector. +- KenPom authorization is no longer needed for [`cbd_kenpom_ratings`] (these ratings are public). + # cbbdata 0.2.0 - Removed `gt` table functions and moved to [`cbbplotR`](https://cbbplotr.aweatherman.com/articles/getting_started.html). diff --git a/R/cbd_all_metrics.R b/R/cbd_all_metrics.R new file mode 100644 index 0000000..c9cf660 --- /dev/null +++ b/R/cbd_all_metrics.R @@ -0,0 +1,35 @@ +#' Get T-Rank, WAB, KP, BPI, SOR/SOS, and NET in one tibble +#' +#' @examples +#' \donttest{try(cbd_all_metrics())} +#' @export +cbd_all_metrics <- function(...) { + + # get trank and net // this takes a few seconds as it hits Barttorvik and not the API + torvik_net <- cbbdata::cbd_torvik_current_resume() %>% + dplyr::select(team, conf, trank_rating = barthag, trank_rank = t_rank, trank_off = adj_o, + trank_off_rank = adj_o_rk, trank_def = adj_d, trank_def_rank = adj_d_rk, trank_tempo = adj_t, + trank_tempo_rank = adj_t_rk, net_rank = net, wab, wab_rank = wab_rk) + + # get kenpom + kp <- cbbdata::cbd_kenpom_ratings(year = 2024) %>% + dplyr::select(team, kp_rating = adj_em, kp_rank = rk, kp_off = adj_o, kp_off_rank = adj_o_rk, kp_def = adj_d, + kp_def_rank = adj_d_rk, kp_tempo = adj_t, kp_tempo_rk = adj_t_rk, kp_luck = luck, kp_luck_rk = luck_rk, + w_l) %>% + tidyr::separate(w_l, into = c('wins', 'losses'), sep = '-', convert = TRUE) + + # get bpi + bpi <- cbd_bpi_ratings() %>% + dplyr::select(team, bpi_rating = bpi_value, bpi_rank = bpi_rank, bpi_off = bpi_offense, bpi_off_rank = bpi_offense_rank, + bpi_def = bpi_defense, bpi_def_rank = bpi_defense_rank, bpi_sor_rank = sor_rank, bpi_sos_rank = sos_rank, + bpi_qual_wins = quality_wins, bpi_qual_losses = quality_losses) + + # join together and move wins after conf. name + data <- list(torvik_net, kp, bpi) %>% + purrr::reduce(left_join, by = "team") %>% + dplyr::relocate(c(wins, losses), .after = c(conf, conf)) + + + return(data) + +} diff --git a/R/cbd_bpi_ratings.R b/R/cbd_bpi_ratings.R new file mode 100644 index 0000000..5fe5433 --- /dev/null +++ b/R/cbd_bpi_ratings.R @@ -0,0 +1,19 @@ +#' BPI Ratings and ESPN Projections +#' +#' Pulls current BPI ratings and ESPN season and tournament projections. +#' +#' @param ... OPTIONAL. To load the complete data set, pass no arguments through +#' to the function. Else, you can filter on `team` or `conf`. +#' | +#' @examples +#' \donttest{try(cbd_bpi_ratings(conf = 'ACC'))} +#' @export +cbd_bpi_ratings <- function(...) { + + base_url <- 'https://www.cbbdata.com/api/espn/bpi?' + + data <- cbbdata:::get_cbd_file(base_url, ...) + + return(data) + +} diff --git a/R/cbd_kenpom_ratings.R b/R/cbd_kenpom_ratings.R index aba2c19..6e66857 100644 --- a/R/cbd_kenpom_ratings.R +++ b/R/cbd_kenpom_ratings.R @@ -2,8 +2,6 @@ #' #' Pulls year-end KenPom ratings and adjusted efficiencies from 2001-Present. #' -#' Requires KenPom authorization. You can authorize with -#' `cbd_kenpom_authorization`. #' #' @param ... OPTIONAL. To load the complete data set, pass no arguments through #' to the function. Else, you can filter on `team`, `conf`, `year`, or any diff --git a/R/cbd_match_teams.R b/R/cbd_match_teams.R new file mode 100644 index 0000000..2c4163a --- /dev/null +++ b/R/cbd_match_teams.R @@ -0,0 +1,21 @@ +#' Generate a team matching dictionary +#' +#' A utility function that returns a named vector to be used as a matching +#' dictionary. +#' +#' @examples +#' \donttest{try(cbd_match_teams()['Duke Blue Devils'])} +#' @export + +cbd_match_teams <- function() { + + teams <- cbbdata::cbd_teams() %>% + dplyr::select(-c(long, lat, espn_logo, espn_dark_logo, logo, wordmark, color, alt_color)) %>% + tidyr::pivot_longer(-common_team) + + team_matching <- teams %>% dplyr::pull('common_team') %>% + rlang::set_names(teams$value) + + return(team_matching) + +} diff --git a/_pkgdown.yml b/_pkgdown.yml index 0c234fa..f6fd47e 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -32,13 +32,15 @@ home: target: _blank reference: - title: Metric Ratings - desc: Functions for grabbing metric ratings from T-Rank + desc: Functions for grabbing metric ratings from various sources contents: - cbd_torvik_ratings - cbd_torvik_ratings_archive - cbd_torvik_team_factors - cbd_kenpom_ratings - cbd_kenpom_ratings_archive + - cbd_bpi_ratings + - cbd_all_metrics - title: Player Data desc: Functions for grabbing player-level data contents: @@ -75,6 +77,7 @@ reference: - cbd_torvik_similar_resumes - title: Other contents: + - cbd_match_teams - cbd_create_account - cbd_login - cbd_kenpom_authorization diff --git a/man/cbd_all_metrics.Rd b/man/cbd_all_metrics.Rd new file mode 100644 index 0000000..ac36226 --- /dev/null +++ b/man/cbd_all_metrics.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cbd_all_metrics.R +\name{cbd_all_metrics} +\alias{cbd_all_metrics} +\title{Get T-Rank, WAB, KP, BPI, SOR/SOS, and NET in one tibble} +\usage{ +cbd_all_metrics(...) +} +\description{ +Get T-Rank, WAB, KP, BPI, SOR/SOS, and NET in one tibble +} +\examples{ +\donttest{try(cbd_all_metrics())} +} diff --git a/man/cbd_bpi_ratings.Rd b/man/cbd_bpi_ratings.Rd new file mode 100644 index 0000000..da92b40 --- /dev/null +++ b/man/cbd_bpi_ratings.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cbd_bpi_ratings.R +\name{cbd_bpi_ratings} +\alias{cbd_bpi_ratings} +\title{BPI Ratings and ESPN Projections} +\usage{ +cbd_bpi_ratings(...) +} +\arguments{ +\item{...}{OPTIONAL. To load the complete data set, pass no arguments through +to the function. Else, you can filter on \code{team} or \code{conf}. +|} +} +\description{ +Pulls current BPI ratings and ESPN season and tournament projections. +} +\examples{ +\donttest{try(cbd_bpi_ratings(conf = 'ACC'))} +} diff --git a/man/cbd_kenpom_ratings.Rd b/man/cbd_kenpom_ratings.Rd index 41a5291..174dc56 100644 --- a/man/cbd_kenpom_ratings.Rd +++ b/man/cbd_kenpom_ratings.Rd @@ -15,10 +15,6 @@ other data column. \description{ Pulls year-end KenPom ratings and adjusted efficiencies from 2001-Present. } -\details{ -Requires KenPom authorization. You can authorize with -\code{cbd_kenpom_authorization}. -} \examples{ \donttest{try(cbd_kenpom_ratings(year = 2023))} } diff --git a/man/cbd_match_teams.Rd b/man/cbd_match_teams.Rd new file mode 100644 index 0000000..5c94b37 --- /dev/null +++ b/man/cbd_match_teams.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cbd_match_teams.R +\name{cbd_match_teams} +\alias{cbd_match_teams} +\title{Generate a team matching dictionary} +\usage{ +cbd_match_teams() +} +\description{ +A utility function that returns a named vector to be used as a matching +dictionary. +} +\examples{ +\donttest{try(cbd_match_teams()['Duke Blue Devils'])} +}