data-raw/gen_afl_data.R

################################################################################
# Generate clean AFL DATA
################################################################################

library(fitzRoy)
library(dplyr)


# Prepare the data
afl_df_raw <- fitzRoy:::get_match_results()

match_outcome <- function(margin){
    (margin + 0.5) %>%
        pmin(1) %>%
        pmax(0)
}

afl_df <- afl_df_raw %>%
    filter(Date > as.Date("20000101", format="%Y%m%d")) %>%
    arrange(Date) %>%
    mutate(
        match_index = 1:n(),
        #time_index = as.numeric(Date - min(Date)),
        outcome = match_outcome(Margin)
    ) %>%
    select(
        match_index,
        home_team = Home.Team,
        away_team = Away.Team,
        outcome,
        date = Date,
        home_score = Home.Points,
        away_score = Away.Points
    ) %>%
    as_tibble()


usethis::use_data(afl_df, overwrite = TRUE)
dclaz/mELO documentation built on May 17, 2021, 2:27 a.m.