Skip to content

Commit

Permalink
REMOVE gt functions; ADD cbd_add_net_quad
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Weatherman authored and Andrew Weatherman committed Jan 5, 2024
1 parent a1a1af8 commit 8390708
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 226 deletions.
6 changes: 1 addition & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(cbd_add_net_quad)
export(cbd_create_account)
export(cbd_gt_logos)
export(cbd_kenpom_authorization)
export(cbd_kenpom_ratings)
export(cbd_kenpom_ratings_archive)
Expand All @@ -29,9 +29,7 @@ export(cbd_torvik_similar_resumes)
export(cbd_torvik_team_factors)
export(cbd_torvik_team_history)
export(cbd_torvik_team_split)
export(gt_theme_athletic)
import(dplyr)
import(gt)
import(httr)
import(httr2)
importFrom(arrow,read_parquet)
Expand Down Expand Up @@ -65,9 +63,7 @@ importFrom(purrr,pmap)
importFrom(purrr,reduce)
importFrom(readr,parse_number)
importFrom(readr,read_csv)
importFrom(rlang,as_string)
importFrom(rlang,check_installed)
importFrom(rlang,ensym)
importFrom(rlang,expr)
importFrom(rlang,inform)
importFrom(rlang,list2)
Expand Down
49 changes: 49 additions & 0 deletions R/cbd_add_net_quad.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#' Add Net Rankings and Quadrants to Data
#'
#' A utility function for adding current NET rankings and quadrant boundaries to
#' data.
#'
#' @param df Data frame to alter
#' @param net_team_col A column of team names which should be used to match
#' against current NET rankings
#' @param net_col The name of your NET column (or the name to call the new NET
#' column)
#' @param location_col The name of your game location column
#' @param add_net Should NET rankings first be added to your data? Set to FALSE
#' if you already have NET rankings and reference that column name in
#' `net_col.` Defaults to TRUE.
#'
#' @export

cbd_add_net_quad <- function(df, net_team_col = opp, net_col = net, location_col = location,
add_net = TRUE) {

# convert string inputs to symbols
location_col <- ensym(location_col)
net_col <- ensym(net_col)
net_team_col <- ensym(net_team_col)

# if add_net is true, grab net rankings and join to data on net_team_col var.
if(add_net) {
net_data <- cbd_torvik_current_resume() %>%
select(!! net_team_col := team, !! net_col := net)

# join over the data on the `net_team_col` variable
df <- df %>%
left_join(net_data, by = as.character(net_team_col))
}

# define quadrants
df <- df %>%
mutate(quad = case_when(
.data[[net_col]] <= ifelse(.data[[location_col]] == "H", 30, ifelse(.data[[location_col]] == "N", 50, 75)) ~ "Quadrant 1",
.data[[net_col]] > ifelse(.data[[location_col]] == "H", 30, ifelse(.data[[location_col]] == "N", 50, 75)) &
.data[[net_col]] <= ifelse(.data[[location_col]] == "H", 75, ifelse(.data[[location_col]] == "N", 100, 135)) ~ "Quadrant 2",
.data[[net_col]] > ifelse(.data[[location_col]] == "H", 75, ifelse(.data[[location_col]] == "N", 100, 135)) &
.data[[net_col]] <= ifelse(.data[[location_col]] == "H", 160, ifelse(.data[[location_col]] == "N", 200, 240)) ~ "Quadrant 3",
.data[[net_col]] > ifelse(.data[[location_col]] == "H", 160, ifelse(.data[[location_col]] == "N", 200, 240)) ~ "Quadrant 4"
))

return(df)
}

48 changes: 0 additions & 48 deletions R/cbd_gt_logos.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/cbd_torvik_team_factors.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ cbd_torvik_team_factors <- function(year = NULL, venue = "all", game_type = "all
}

else {
cbbdata::cbd_torvik_ratings(year = year) %>% distinct(team, conf)
conf_info <- cbbdata::cbd_torvik_ratings(year = year) %>% distinct(team, conf)
}

cbbdata:::validate_input(venue, c('all', 'home', 'away', 'neutral', 'road'), "Please input correct venue value (see details)")
Expand Down
98 changes: 0 additions & 98 deletions R/gt_theme_athletic.R

This file was deleted.

6 changes: 1 addition & 5 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ reference:
- cbd_torvik_game_factors
- cbd_torvik_game_stats
- cbd_torvik_season_schedule
- cbd_add_net_quad
- title: Predictions
desc: Functions for running T-Rank predictions and Monte Carlo simulations
contents:
Expand All @@ -72,11 +73,6 @@ reference:
- cbd_torvik_ncaa_sheets
- cbd_torvik_resume_database
- cbd_torvik_similar_resumes
- title: gt Utilities
desc: Utility functions for gt tables
contents:
- gt_theme_athletic
- cbd_gt_logos
- title: Other
contents:
- cbd_create_account
Expand Down
33 changes: 33 additions & 0 deletions man/cbd_add_net_quad.Rd

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

46 changes: 0 additions & 46 deletions man/cbd_gt_logos.Rd

This file was deleted.

23 changes: 0 additions & 23 deletions man/gt_theme_athletic.Rd

This file was deleted.

0 comments on commit 8390708

Please sign in to comment.