-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Weatherman
authored and
Andrew Weatherman
committed
Jan 14, 2024
1 parent
0942172
commit e92683c
Showing
12 changed files
with
137 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.