Skip to content

Commit

Permalink
bump to v0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Weatherman authored and Andrew Weatherman committed Jan 14, 2024
1 parent 0942172 commit e92683c
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
role = c("aut", "cre"))
Description: Provides direct access to clean and tidy college basketball data using the
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
35 changes: 35 additions & 0 deletions R/cbd_all_metrics.R
Original file line number Diff line number Diff line change
@@ -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)

}
19 changes: 19 additions & 0 deletions R/cbd_bpi_ratings.R
Original file line number Diff line number Diff line change
@@ -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)

}
2 changes: 0 additions & 2 deletions R/cbd_kenpom_ratings.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions R/cbd_match_teams.R
Original file line number Diff line number Diff line change
@@ -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)

}
5 changes: 4 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -75,6 +77,7 @@ reference:
- cbd_torvik_similar_resumes
- title: Other
contents:
- cbd_match_teams
- cbd_create_account
- cbd_login
- cbd_kenpom_authorization
Expand Down
14 changes: 14 additions & 0 deletions man/cbd_all_metrics.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/cbd_bpi_ratings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions man/cbd_kenpom_ratings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions man/cbd_match_teams.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e92683c

Please sign in to comment.