Skip to content

Commit

Permalink
add pkgdown site and beef up readme
Browse files Browse the repository at this point in the history
  • Loading branch information
andreweatherman committed Dec 19, 2023
1 parent 60776fa commit 19152e0
Show file tree
Hide file tree
Showing 57 changed files with 943 additions and 194 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
^\.Rproj\.user$
^README\.Rmd$
^LICENSE\.md$
^_pkgdown\.yml$
^docs$
^pkgdown$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
.Ruserdata
docs
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cbbdata
Type: Package
Title: Interfaces the CBBData API
Title: API for College Basketball Data
Version: 0.1.0
Authors@R: person("Andrew", "Weatherman", email = "[email protected]",
role = c("aut", "cre"))
Expand All @@ -25,3 +25,4 @@ Imports:
rlang,
stringr,
usethis
Roxygen: list(markdown = TRUE)
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(cbd_create_account)
export(cbd_gt_logos)
export(cbd_kenpom_authorization)
export(cbd_kenpom_ratings)
export(cbd_kenpom_ratings_archive)
export(cbd_kenpom_team_schedules)
export(cbd_login)
export(cbd_players)
export(cbd_teams)
export(cbd_torvik_conf_factors)
export(cbd_torvik_current_resume)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# cbbdata 0.1.0

Beta release; formally "announced" package via Twitter.
4 changes: 2 additions & 2 deletions R/cbd_gt_logos.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#' @importFrom rlang ensym as_string
#' @importFrom magrittr %>%
#' @examples
#' \donttest{try(cbd_torvik_ratings(year=2023) %>% head() %>% select(team, conf) %>%
#' cbd_gt_logos(team) %>% gt() %>% fmt_markdown(team_logo))}
#' \dontrun{try(cbd_torvik_ratings(year=2023) %>% head() %>% select(team, conf) %>%
#' cbbdata::cbd_gt_logos(team, team) %>% gt::gt() %>% gt::fmt_markdown(team))}
#'
#' @export
cbd_gt_logos <- function(data, team_column, logo_column = 'team_logo', logo_type = 'logo', logo_height = 25) {
Expand Down
2 changes: 1 addition & 1 deletion R/cbd_kenpom_ratings.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @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
#' other data column.
#'
#' |
#' @examples
#' \donttest{try(cbd_kenpom_ratings(year = 2023))}
#' @export
Expand Down
22 changes: 0 additions & 22 deletions R/cbd_kenpom_team_schedules.R

This file was deleted.

19 changes: 0 additions & 19 deletions R/cbd_players.R

This file was deleted.

24 changes: 23 additions & 1 deletion R/cbd_torvik_current_resume.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,29 @@
#'
#' Returns a tibble with current NCAA Tournament resume data
#'
#' @returns Returns a tibble with current resume data, including NET
#' @returns Returns a tibble with the following columns:
#' |**Column** |**Description** |
#' |:--------|:---------------------------------------------------------------|
#' |seed |NCAA Seed |
#' |team |Team |
#' |conf |Conference |
#' |barthag |Barthag rating (prob. of beating average team on neutral court) |
#' |t_rank |Barthag rank |
#' |net |NCAA Net rank |
#' |elo |ELO rank (Barttorvik) |
#' |resume |Resume rank (Barttorvik) |
#' |wab_rk |Wins Above Bubble raking |
#' |wab |Wins above/below bubble team expectation |
#' |quad1 |Quad 1 record (current) |
#' |quad2 |Quad 2 record (current) |
#' |quad3 |Quad 3 record (current) |
#' |quad4 |Quad 4 record (current) |
#' |adj_o |Adjusted offense (points per 100 possessions) |
#' |adj_o_rk |Adjusted offense rank |
#' |adj_d |Adjusted defense (points allowed per 100 possessions) |
#' |adj_d_rk |Adjusted defense rank |
#' |adj_t |Adjusted tempo (possessions per game) |
#' |adj_t_rk |Adjusted tempo rank |
#' @import dplyr
#' @import httr
#' @importFrom withr local_options
Expand Down
3 changes: 1 addition & 2 deletions R/cbd_torvik_ratings.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#' Pulls year-end T-Rank ratings and adjusted efficiencies from 2008-Present.
#'
#' @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
#' other data column.
#' to the function. Else, you can filter on `team`, `conf`, or `year`.
#'
#' @examples
#' \donttest{try(cbd_torvik_ratings(year = 2023))}
Expand Down
9 changes: 8 additions & 1 deletion R/cbd_torvik_team_factors.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@
#' games.
#' @param start Game start date (YYYYMMDD format).
#' @param end Game end date (YYYYMMDD format).
#' @param no_bias Logical. `TRUE` will display T-Rank ratings with no preseason
#' bias/weight.
#' @import dplyr
#' @import httr
#' @importFrom withr local_options
#' @importFrom cli cli_abort
#' @importFrom readr read_csv
#' @importFrom magrittr %>%
#' @importFrom glue glue
#' @examples
#' \donttest{try(cbd_torvik_team_factors(2023, start = '20230101'))}
#'
#' @export
cbd_torvik_team_factors <- function(year, venue = "all", game_type = "all", quad = "4", top = 0, start = NULL, end = NULL) {
cbd_torvik_team_factors <- function(year, venue = "all", game_type = "all", quad = "4", top = 0, start = NULL, end = NULL, no_bias = FALSE) {

suppressWarnings({
# default PC user-agent gets blocked on barttorvik.com
Expand All @@ -35,6 +38,10 @@ cbd_torvik_team_factors <- function(year, venue = "all", game_type = "all", quad
cli_abort("Enter a valid year as a number (YYYY). Data only goes back to 2008!")
}

if (no_bias) {
start <- glue('{year-1}-11-01')
}

cbbdata:::validate_input(venue, c('all', 'home', 'away', 'neutral', 'road'), "Please input correct venue value (see details)")
cbbdata:::validate_input(game_type, c('all', 'nc', 'conf', 'reg', 'post', 'ncaa'), "Please input correct type value (see details)")
cbbdata:::validate_input(quad, c('1', '2', '3', '4', 'all'), "Please input correct quad value (see details)")
Expand Down
2 changes: 1 addition & 1 deletion R/cbd_torvik_team_split.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' @param split The data will default to splitting on game result. If you want
#' to split on a different level, you must specify. You can split on
#' `location`, `game_type`, `month`, or `game_result` (default).
#' `location`, `game_type`, `month`, or `game_result`.
#' @param ... OPTIONAL. To load the complete data set, pass no arguments through
#' to the function. Else, you can filter on `year`, `team`, `conf`, or any
#' other data column.
Expand Down
2 changes: 1 addition & 1 deletion R/gt_theme_athletic.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @import gt
#' @importFrom magrittr %>%
#' @examples
#' \donttest{try(mtcars %>% head() %>% gt() %>% gt_theme_athletic())}
#' \dontrun{try(mtcars %>% head() %>% gt::gt() %>% cbbdata::gt_theme_athletic())}
#'
#' @export
gt_theme_athletic <- function(gt_object, ...) {
Expand Down
14 changes: 14 additions & 0 deletions R/utils-pipe.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#' Pipe operator
#'
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
#' @param lhs A value or the magrittr placeholder.
#' @param rhs A function call using the magrittr semantics.
#' @return The result of calling `rhs(lhs)`.
NULL
103 changes: 92 additions & 11 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
out.width = "75%"
)
library(tidyverse)
```

# cbbdata
# Welcome to CBBData: Your Gateway to In-Depth College Basketball Insights

<!-- badges: start -->
<!-- badges: end -->

Welcome to `cbbdata`, an R package designed to grant swift and effortless access to the CBBData API, offering an abundance of college basketball statistics and data! By harnessing the power of back-end SQL queries and direct file transfers, this package equips you with essential college basketball data and statistics.
In the vast arena of college basketball data, finding comprehensive, easily accessible, and up-to-date statistics can be a daunting task. cbbdata emerges as your reliable partner in this quest, offering an unparalleled depth of college basketball insights, just a line of code away.

The benefit of using `cbbdata` is two-fold:
**Unmatched Access, Uncomplicated Process:** `cbbdata` is your key to unlocking a treasure trove of college basketball statistics. Say goodbye to the hurdles of data scraping. Our package is designed for efficiency and simplicity, providing a straightforward pathway to the data you need.

1. It provides batched data; no need to scrape thousands of pages for a complete picture.
**Powered by Precision and Speed:** At the heart of `cbbdata` lies a robust architecture, powered by Flask and Python. Leveraging SQL queries and direct file transfers, we ensure you receive the most accurate and recent data. Our commitment to speed and reliability means you get the data you need, when you need it, without the wait.

2. `cbbdata` uses common naming conventions for players and teams, making it easy to join and compare data from different sources.
**Diverse Data at Your Fingertips:** Whether you're looking for detailed player stats, team analytics, game outcomes, or advanced metrics, `cbbdata` has it all. Our comprehensive database is constantly evolving, bringing you the latest and most detailed insights into the college basketball world.

Getting started with `cbbdata` is a breeze – simply sign up for a free API key and start grabbing data!
**Getting Started is Easy:** Begin your journey with `cbbdata` by signing up for a free API key. With this key, a world of college basketball data awaits you. Experience the ease and power of `cbbdata` and elevate your analysis to the next level.

## Installation

Expand Down Expand Up @@ -83,35 +84,85 @@ Developer [Andrew Weatherman](https://twitter.com/andreweatherman) wrote the pop
#### Metric Ratings:
- Year-end ratings (`cbd_torvik_ratings`)
- Day-by-day ratings (`cbd_torvik_ratings_archive`)
- Team four factor splits (`cbd_torvik_team_factors`)

E.g., if you want to see what the no-bias T-Rank top 10 looks like:
```{r, message=FALSE, warning=FALSE}
cbbdata::cbd_torvik_team_factors(year = 2024, no_bias = TRUE) %>%
dplyr::slice(1:10) %>%
dplyr::select(team, barthag, adj_o, adj_d)
```

#### Player Data:
- Individual game logs (`cbd_torvik_player_game`)
- Season averages (`cbd_torvik_player_season`)
- Season splits (`cbd_torvik_player_split`)

E.g., if you want to see which ACC player averages the most points at home:
```{r, message=FALSE, warning=FALSE}
cbbdata::cbd_torvik_player_split(year = 2024, conf = 'ACC', split = 'location') %>%
dplyr::filter(games >= 3) %>%
dplyr::slice_max(pts, n = 1) %>%
dplyr::select(team, player, pts, games)
```

#### Team + Conference Data:
- Team stats splits (`cbd_torvik_team_split`)
- Team histories (`cbd_torvik_team_history`)
- Team four factor splits (`cbd_torvik_team_factors`)
- Conference four factor splits (`cbd_torvik_conf_factors`)

E.g., if you want to see which conferences shoot the best at home against top 100 teams:
```{r, message=FALSE, warning=FALSE}
cbbdata::cbd_torvik_conf_factors(2024, venue = 'home', top = 100) %>%
dplyr::filter(games >= 5) %>%
dplyr::slice_max(efg, n = 5) %>%
dplyr::select(conf, games, efg)
```

#### Game Data:
- Individual game box (`cbd_torvik_game_box`)
- Individual game four factors (`cbd_torvik_game_factors`)
- Individual game stats (box + factors) (`cbd_torvik_game_stats`)
- Season schedule (`cbd_torvik_season_schedule`)

E.g., if you want to track how Duke's offense has performed this season:
```{r, message=FALSE, warning=FALSE}
cbbdata::cbd_torvik_game_factors(year = 2024, team = 'Duke') %>%
ggplot2::ggplot(aes(date, adj_o)) +
ggplot2::geom_line() +
ggplot2::geom_point(aes(color = result), size = 3) +
ggplot2::scale_color_manual(values = c('darkred', 'darkgreen'), guide = NULL) +
ggplot2::theme_minimal()
```

#### Predictions
- Individual game predictions (`cbd_torvik_game_prediction`)
- Team season predictions (`cbd_torvik_season_prediction`)
- Team season simulations (`cbd_torvik_season_simulation`)

E.g., if you want to run 10,000 simulations of Duke's season with their performance as of today:
```{r, message=FALSE, warning=FALSE}
# no date -> defaults to today
cbbdata::cbd_torvik_season_simulation('Duke', 2024) %>%
ggplot2::ggplot(aes(wins, probability)) +
ggplot2::geom_col() +
ggplot2::scale_y_continuous(labels = scales::label_percent())
```

#### Tournament Results + Resumes
- Daily NET rankings and quadrant records (`cbd_torvik_current_resume`)
- Tournament performance (`cbd_torvik_ncaa_results`)
- Tournament "committee sheets" (`cbd_torvik_ncaa_sheets`)
- "Resume" database (`cbd_torvik_resume_database`)
- Resume database (`cbd_torvik_resume_database`)
- Similar team tournament resumes (`cbd_torvik_similar_resumes`)

E.g., if you want to pull the five teams with the most Q1 NET wins:
```{r, message=FALSE, warning=FALSE}
cbbdata::cbd_torvik_current_resume() %>%
dplyr::mutate(q1_wins = readr::parse_number(quad1)) %>%
dplyr::slice_max(q1_wins, n = 5) %>%
dplyr::select(team, conf, q1_wins, net)
```

### KenPom

Expand All @@ -126,8 +177,38 @@ cbbdata::cbd_kenpom_authorization(password = 'xxx')
- Year-end ratings (`cbd_kenpom_ratings`)
- Day-by-day ratings (`cbd_kenpom_ratings_archive`)

#### Game Data:
- Team schedules (`cbd_kenpom_team_schedules`)
### Other

`cbbdata` ships with the `gt_theme_athletic` theme for `gt` tables. The theme is perfect for stat-focused tables, giving them a classic, monospaced feel.

```{r, message=FALSE, warning=FALSE, eval=FALSE}
cbbdata::cbd_torvik_ratings(year=2024) %>%
dplyr::slice(1:5) %>%
dplyr::select(team, conf, barthag, adj_o, adj_d) %>%
gt::gt() %>%
cbbdata::gt_theme_athletic()
```

```{r, echo=FALSE, warning=FALSE, message=FALSE}
knitr::include_graphics('man/figures/gt_theme.png')
```

Also included in `cbbdata` is a helper function for plotting team logos with `gt`. Simply pass in a dataframe with team names, specify where your 'team' logo resides, and the name of the new column (using the same name as your 'team' column will replace that column -- perfect for `gt`).

```{r, message=FALSE, warning=FALSE, eval=FALSE}
cbbdata::cbd_torvik_ratings(year=2024) %>%
dplyr::slice(1:5) %>%
dplyr::select(team, conf, barthag, adj_o, adj_d) %>%
cbbdata::cbd_gt_logos(team, team) %>%
gt::gt() %>%
cbbdata::gt_theme_athletic() %>%
gt::fmt_markdown(team) %>%
gt::cols_align(columns = team, 'left')
```

```{r, echo=FALSE, warning=FALSE, message=FALSE}
knitr::include_graphics('man/figures/with_logos.png')
```

## Support

Expand Down
Loading

0 comments on commit 19152e0

Please sign in to comment.