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
@tonyelhabr
tonyelhabr / scrape-2023-fifa-womens-world-cup.md
Last active July 21, 2023 19:02
Scrape player stats for the 2023 FIFA Women's World Cup
library(httr)
library(tibble)
library(tidyr)
library(dplyr)
library(purrr)
library(janitor)
library(cli)
library(stringr)
@tonyelhabr
tonyelhabr / ff_scores.csv
Last active July 2, 2023 22:34
Scrape ESPN fantasy football league scores (2018/19-2022/23)
season week user_name opponent_user_name user_score opponent_score result
2018 1 Juan Avalos Manuel Espinosa 137.84 86.26 W
2018 1 Manuel Espinosa Juan Avalos 86.26 137.84 L
2018 1 Enrique Rodriguez Tracy Krohn 123.14 121.78 W
2018 1 Steven Valencia Juan Pineda 134.54 86.2 W
2018 1 Andrew ElHabr Andrew Lara 106.26 102.06 W
2018 1 Drake Hernandez Tony ElHabr 131.04 123.42 W
2018 1 Tony ElHabr Drake Hernandez 123.42 131.04 L
2018 1 Andrew Lara Andrew ElHabr 102.06 106.26 L
2018 1 Tracy Krohn Enrique Rodriguez 121.78 123.14 L
@tonyelhabr
tonyelhabr / overperformance.md
Last active May 30, 2023 12:21
Emperical bayes estimation of xG overperformance

This is my attempt to replicate the analysis by Laurie Shaw here.

Creating some fake data.

library(tibble)
library(purrr)
library(tidyr)
library(MASS)
library(ggplot2)
@tonyelhabr
tonyelhabr / latest-opta-club-rankings.md
Created April 30, 2023 17:28
Get latest opta club rankings from release.
library(readr)
library(dplyr)
opta_club_rankings <- read_csv('https://github.com/tonyelhabr/club-rankings/releases/download/club-rankings/opta-club-rankings.csv')
opta_club_rankings |> 
  filter(updated_at == max(updated_at))
#> # A tibble: 3,000 × 7
#>     rank team              rating `ranking change 7 days` date       updated_at          id                       
#>    <dbl> <chr>              <dbl>                   <dbl> <date>     <dttm>              <chr>                    
@tonyelhabr
tonyelhabr / compare.md
Last active February 15, 2023 20:52
Comparing new and old Opta xG data on FBref and Fotmob
library(worldfootballR)
library(dplyr)
library(stringr)
library(readr)
library(purrr)
library(janitor)

# https://fbref.com/en/matches/a6ff9cf9/Chelsea-Norwich-City-October-23-2021-Premier-League
@tonyelhabr
tonyelhabr / precip.md
Created January 8, 2023 14:17
Austin precipitation by day of week between 2022-10-01 and 2022-12-31

Data source

library(httr)
library(tibble)
library(purrr)
library(readr)
library(dplyr)
@tonyelhabr
tonyelhabr / scrape-worldcup-match-player-stats.md
Last active July 23, 2023 15:32
Get stats by player for a 2022 World Cup match.

Scraping a specific stat for this match. Inspiration here. You can get other player stats in a similar fashion.

library(httr)
library(tibble)
library(tidyr)
library(dplyr)
library(purrr)
library(janitor)
@tonyelhabr
tonyelhabr / cdc-scraper.md
Last active November 19, 2022 23:38
cdc get rekt

Heart Disease and Stroke

For example, this.

library(httr)
library(tibble)
library(tidyr)
library(dplyr)
@tonyelhabr
tonyelhabr / fotmob_shots_by_season.md
Created October 17, 2022 16:59
Fotmob shots for top scorers in the 2022/23 EPL season
suppressPackageStartupMessages({
  library(worldfootballR)
  library(dplyr)
  library(lubridate)
})

## Need the very most recent version of the package for `load_fotmob_match_details()` to work.
packageVersion("worldfootballR")
@tonyelhabr
tonyelhabr / corners.md
Created September 20, 2022 14:29
get corners for a match with worldfootballR

hey jon 👋

library(dplyr)
library(worldfootballR)

match_team_stats <- fotmob_get_match_team_stats(3609994)
match_team_stats |> 
  filter(stats_title == 'Corners') |> 
  glimpse()
#> Rows: 1