Skip to content

Instantly share code, notes, and snippets.

View tonyelhabr's full-sized avatar
🏠
Working from home

Tony ElHabr tonyelhabr

🏠
Working from home
View GitHub Profile
library(tidyverse)
dir_data <- file.path('inst', 'extdata', 'json')
paths <-
fs::dir_ls(dir_data, regexp = 'json$')
paths
n_path <- paths %>% length()
n_path
# paths <- 'inst/extdata/json/8-2020-1485311.json'
# paths <- 'inst/extdata/json/8-2019-1375927.json'
@tonyelhabr
tonyelhabr / Rteta-atomic.R
Last active August 9, 2021 11:53
atomic SPADL functions to use with {Rteta}, use vaep_get_scores_atomic instead of Rteta::vaep_get_scores
#' Calculate the VAEP score for all actions in an atomic spadl df
#' @param spadl A df of spadl events
#' @param scores The name of a col of values calculated for the chance of scoring in next n actions
#' @param concedes The name of a col of values calculated for the chance of conceeding in next n actions
#' @param score_type Whether to score for the attacking contribution or defensive contribution
#' @export vaep_score_actions_atomic
#' @seealso vaep_score_actions
vaep_score_actions_atomic <- function(spadl, scores, concedes, score_type) {
#inverse formulas for attack and defense score
@tonyelhabr
tonyelhabr / night-owlish-2.rstheme
Last active August 26, 2021 12:29
RStudio Theme
/* rs-theme-name: a Night Owl Tony */
/* rs-theme-is-dark: TRUE */
/* THIS THEME WAS AUTOGENERATED BY Theme.tmpl.css (UUID: EB0EC8F4-467B-46D0-8AE9-88B44F4D73B4) */
.ace_gutter {
background: #011627;
color: #6C7A89;
}
.ace_print-margin {
@tonyelhabr
tonyelhabr / 2021_preseason_ffsim.R
Last active September 8, 2021 03:07
2021 ffsimulator predictions
library(ffscrapr)
library(ffsimulator)
library(ggplot2)
library(tonythemes)
conn <- espn_connect(
season = 2021,
league_id = 899513,
espn_s2 = Sys.getenv('FF_ESPN_S2'),
swid = Sys.getenv('FF_SWID')
@tonyelhabr
tonyelhabr / fairyfloss_dark-2.rstheme
Created September 11, 2021 18:08
fairyfloss theme
/* rs-theme-name: a fairyfloss tony */
/* rs-theme-is-dark: TRUE */
/* THIS THEME WAS AUTOGENERATED BY Theme.tmpl.css (UUID: D8D5E82E-3D5B-46B5-B38E-8C841C21347D) */
.ace_gutter {
background: #494266;
color: #A19DAC;
}
.ace_print-margin {
@tonyelhabr
tonyelhabr / sankey-ex.R
Last active October 26, 2021 23:00
example sankey diagram
library(tibble)
library(dplyr)
library(tidyr)
library(ggplot2)
library(ggsankey)
df <-
tibble(
id = c(
@tonyelhabr
tonyelhabr / mls_fotmob.R
Created November 24, 2021 18:39
scrape fotmob data
# Also see:
# - https://github.com/tonyelhabr/sports_viz/blob/master/44-mls_bangers/01-scrape.R
# - https://github.com/tonyelhabr/sports_viz/blob/master/44-mls_bangers/02-visualize.R
library(jsonlite)
library(dplyr)
library(janitor)
library(tibble)
library(lubridate)
@tonyelhabr
tonyelhabr / geom_contour_tanaka.R
Created December 18, 2021 12:38
Heat map thingy by Owen Phillips
# Load packages
library(tidyverse)
library(metR)
library(nbastatR)
library(extrafont)
library(teamcolors)
library(cowplot)
# Custom theme
@tonyelhabr
tonyelhabr / poolside-tony.rstheme
Created February 23, 2022 12:40
Tony's Poolside Theme
/* rs-theme-name: a poolside tony */
/* rs-theme-is-dark: TRUE */
.ace_gutter {
background: #353454;
color: rgba(204, 204, 204, 0.7);
}
.ace_print-margin {
width: 2px;
background: rgba(204, 204, 204, 0.5);
/* rs-theme-name: a semi-cursive poolside tony */
/* rs-theme-is-dark: TRUE */
.ace_gutter {
background: #353454;
color: rgba(204, 204, 204, 0.7);
}
.ace_print-margin {
width: 2px;
background: rgba(204, 204, 204, 0.5);