Skip to content

Instantly share code, notes, and snippets.

View JoGall's full-sized avatar

Joe Gallagher JoGall

View GitHub Profile
@JoGall
JoGall / fpl_xpts_draft_h2h.R
Created August 20, 2024 14:08
Expected Points (xPts) for FantasyPL draft head-to-head league
# Calculate expected points for a FantasyPL draft, head-to-head league.
#
# Calculate expected points (xPts) and expected rank (xRank) for each
# team in a head-to-head draft league as the average points (i.e. 0, 1, 3)
# expected against all teams in that league each gameweek, not just the actual
# opponent.
#
# @param leagueid: integer
library(dplyr)
@JoGall
JoGall / so_openai_legal_query.md
Last active May 9, 2024 16:33
Query of legislation being used to prevent users transforming, redacting, or dissociating from StackOverflow submissions and OpenAI applications
@JoGall
JoGall / twitter_otd.py
Last active December 11, 2022 12:08
Generates a search URL for twitter.com to retrieve tweets on this day by a given user and opens results in system default browser
"""
Generates a search URL for twitter.com to retrieve tweets on this day (#OTD)
by a given user and opens results in system default browser
Usage:
python ./twitter_otd.py
Author:
Joe Gallagher (@joedgallagher)
"""
player_id age elo prop_mins_played
1 18 60 0.330277778
1 19 60 0.620325203
1 20 60 0.791725768
1 21 60 0.791472868
1 22 60 0.868888889
1 23 70 0.631860776
1 24 70 0.850793651
1 25 70 0.5
1 25 80 0.627664399
@JoGall
JoGall / possessionAdjust.R
Last active March 13, 2019 09:57
Possession adjust metrics for StatsBomb data
# Compute total minutes played per player -------------------------------
statsbombMinsPlayed <- function(dat) {
dat <- dat %>%
group_by(match_id) %>%
mutate(end = max(ElapsedTime))
# starting XI
minutes <- dat %>%
#devtools::install_github("statsbomb/StatsBombR") #install package
#devtools::install_github("jogall/StatsBombR") #or fork for R v<5.0 if necessary
library(StatsBombR)
# see all free competitions
FreeCompetitions()
# e.g. get all fixtures from FIFA World Cup
fixtures <- FreeMatches(43)
library(tidyverse)
library(soccermatics)
library(StatsBombR)
# get data from StatsBomb
fixture <- FreeMatches(37) %>%
filter(home_team.home_team_name == "Reading WFC" & away_team.away_team_name == "Yeovil Town LFC")
# helper function from my fork of statsbombr package: https://github.com/JoGall/StatsBombR
# or code here: https://github.com/JoGall/StatsBombR/blob/master/R/allinfo.R
# Computes number of neighbours in common between first degree neighbourhood of each vertex in an igraph network
# Not sure if this is meaningful metric yet but seems like it could be interesting!
# FUNCTION --------------------------------------------------------------------
common.neighbours <- function(graph) {
lapply(unique(V(graph)), function(v) {
# get vertices of 1st-order neighbourhood for focal vertex (and omit self)
@JoGall
JoGall / drawNetballCourt.R
Last active January 29, 2018 13:29
Draw a netball court using ggplot
library(ggplot2)
library(ggforce) # gives us `geom_circle` and `geom_arc` functions
# pitch dimensions
courtLength <- 30.5
courtWidth <- 15.25
courtRunoff <- 3.05
# aesthetic parameters
pitch_col <- "grey90"
@JoGall
JoGall / gglexis.R
Last active November 13, 2017 00:39
Lexis lifeline ggplot
library(ggplot2)
library(dplyr)
library(scales)
# SAMPLE DATA
set.seed(123)
# get all dates in a range
start_date <- as.Date("2017-01-01")
end_date <- as.Date("2017-06-01")
dates <- seq(start_date, end_date, 1)