Skip to content

Instantly share code, notes, and snippets.

@gallochris
gallochris / minutes-continuity-ncaat.R
Created March 21, 2024 14:40
Minutes + continuity of NCAA Tourney Field
# First, use hoopR to grab the kenpom data for continuity and experience
meta_metrics <- hoopR::kp_height(min_year = 2024, max_year = 2024)
# now load the seed data and filter out teams that already lost
seeds <-
readr::read_csv(
"https://gist.githubusercontent.com/gallochris/86fc2a21dd4b30e3dd9ea79516594f05/raw/1e2dfa7eae2d196f5dee9ecf5fe95e5f76ba827d/ncaat_seeds.csv"
) |>
dplyr::select(seed = Seed,
team = Team,
@gallochris
gallochris / unc_miami_poss_plot.R
Created February 27, 2024 17:00
Possession plot for basketball
# use bigballR to fetch schedule
schedule <-
bigballR::get_team_schedule(season = "2023-24", team.name = "North Carolina")
# grab miami home game pbp
unc_miami_pbp <- bigballR::get_play_by_play(schedule$Game_ID[28])
# add index to determine first half and second half
um_index <- which(unc_miami_pbp$Half_Status == 2)[1]
@gallochris
gallochris / def_ppp_plot.R
Last active January 22, 2024 15:16
Defensive efficiency plot
# Attempt to recreate or riff on the plot from the Tufte book
# https://opticalacumen.blogspot.com/2014/07/data-visualization-in-1919.html
# Fetch the player minutes data by game over past three seasons
hubert <-
cbbdata::cbd_torvik_game_factors(team = "North Carolina") |>
dplyr::filter(year > 2021) |>
dplyr::arrange(date) |>
dplyr::mutate(off_ppp = format(round(off_ppp / 100, 2), nsmall = 2),
def_ppp = format(round(def_ppp / 100, 2), nsmall = 2)) |>
@gallochris
gallochris / acc_last_five_seasons_results.csv
Created February 17, 2023 21:05
ACC home games by results
game_date game_id team opponent location result points_scored points_allowed diff year
1 20190112 2826 North Carolina Louisville Home L 83 62 21 2019
2 20190115 3021 North Carolina Notre Dame Home W 75 69 6 2019
3 20190121 3312 North Carolina Virginia Tech Home W 103 82 21 2019
4 20190205 3986 North Carolina N.C. State Home W 113 96 17 2019
5 20190209 4125 North Carolina Miami FL Home W 88 85 3 2019
6 20190211 4288 North Carolina Virginia Home L 69 61 8 2019
7 20190223 4795 North Carolina Florida St. Home W 77 59 18 2019
8 20190226 4958 North Carolina Syracuse Home W 93 85 8 2019
9 20190309 5420 North Carolina Duke Home W 79 70 9 2019
library(rvest)
library(dplyr)
library(janitor)
library(stringr)
# load data
url <-
'https://www.sports-reference.com/cfb/play-index/sgl_finder.cgi?request=1&match=game&year_min=2019&year_max=2021&school_id=north-carolina&c1stat=points&c1comp=gt&c1val=1&c2stat=opp_points&c2comp=gt&c2val=1&c3comp=gt&c4comp=gt&order_by=date_game#results'
mack_raw <- url %>%
@gallochris
gallochris / win_totals_odds_2021-22.R
Created September 29, 2021 15:39
WynnBet win totals, title odds, and final four odds
library(tidyverse)
library(gt)
# make the data - https://www.wynnbet.com/theplaybook/posts/wynnbet-releases-odds-for-upcoming-men-s-college-basketball-season-01ffk34jmvek
odds <- tibble::tribble(
~team, ~win, ~nt, ~ff,
"Gonzaga", 33.5, 11.1, 33.3,
"UCLA", 31, 7.7, 25.0,
"Michigan", 27, 7.7, 25.0,
"Memphis", 32, 6.3, 20.0,
@gallochris
gallochris / minutes_2019_2020.r
Created October 20, 2020 15:38
2019-20 Minutes played UNC
library(tidyverse)
library(gt)
# make the data
injury <- tibble::tribble(
~Opp,~Anthony,~Keeling,~Robinson,~Black,~Brooks,~Bacot,~Pierce,~Platek,~Francis,~Harris,~Manley,
"Notre Dame",37,21,0,33,39,23,20,26,0,0,0,
"at UNC-Wilmington",34,23,0,32,33,3,32,27,0,0,0,
"Gardner-Webb",33,30,0,34,30,23,21,23,0,0,0,
"Elon",36,25,0,27,33,26,23,18,0,0,0,
@gallochris
gallochris / duke-unc-point-spreads.md
Last active February 5, 2020 19:38
duke-unc-point-spreads
Season Result UNC Score Opp Score Ref 1 Ref 2 Ref 3 Spread Location
2019 L 73 74 Roger Ayers Jamie Luckie Clarence Armstrong 3.5 neutral
2019 W 79 70 Roger Ayers Ted Valentine Bill Covington Jr. -4.5 home
2019 W 88 72 Mike Eades Brian Dorsey Ron Groover 9.5 away
2018 W 74 69 Mike Eades Ted Valentine Bert Smith 4 neutral
2018 L 64 74 Roger Ayers Mike Eades Raymond Styons 7.5 away
2018 W 82 78 Jeff Clark Jamie Luckie Ron Groover -1.5 home
2017 L 83 93 Bria
@gallochris
gallochris / win_total_roy_era.csv
Last active January 30, 2020 22:16
win totals first 20 games roy era
G W Product
1 1 2004
2 2 2004
3 3 2004
4 4 2004
5 5 2004
6 6 2004
7 6 2004
8 7 2004
9 8 2004
@gallochris
gallochris / spread_losses.csv
Created August 16, 2019 19:58
point spreads and double-digit losses in RW ERa
Season Opponent Result UNC Score Opp Score Favored by? Lost by? Swing?
2011-12 Florida State L 57 90 -6 -33 -39
2018-19 Louisville L 62 83 -11 -21 -32
2016-17 Georgia Tech L 63 75 -17 -12 -29
2017-18 Texas A&M L 65 85 -7 -20 -27
2010-11 Georgia Tech L 58 78 -6 -20 -26
2004-05 Santa Clara L 66 77 -13 -11 -24
2009-10 UVA L 60 75 -8 -15 -23
2012-13 Texas L 67 85 -4.5 -18 -22.5
2005-06 Miami L 70 81 -10.5 -11 -21.5