AFLCA Coaches Votes Functions

not_cran = identical(Sys.getenv("NOT_CRAN"), "true")
online <- !is.null(curl::nslookup("r-project.org", error = FALSE))
eval_param <- not_cran & online

knitr::opts_chunk$set(
    eval = eval_param,
    message = FALSE,
    warning = FALSE,
    collapse = TRUE,
    comment = "#>"
)

library(fitzRoy)
library(dplyr)

Functions have been added to fitzRoy to scrape and analyse AFLCA coaches votes.

Scraping Coaches Votes

The fetch_coaches_votes function accepts 4 arguments. The season, round_number and comp arguments are common to the core fetch_* functions as per the Main Fetch Functions Vignette.

Examples

The following are some examples of ways to scrape the AFLCA coaches votes. Firstly, coaches votes can be retrieved for a season (or an array of seasons).

fetch_coaches_votes(season = 2021, comp = "AFLM") %>% head()
fitzRoy:::aflm_coaches_votes %>% head()

We can also return votes for AFLW.

fetch_coaches_votes(season = 2021, comp = "AFLW") %>% head()
fitzRoy:::aflw_coaches_votes %>% head()

We can return just one round instead of the whole fixture.

fetch_coaches_votes(season = 2021, round_number = 24, comp = "AFLM")
fitzRoy:::aflm_coaches_votes %>%
  dplyr::filter(Round == 24) %>% 
  head()
fetch_coaches_votes(season = 2021, round_number = 9, comp = "AFLW")
fitzRoy:::aflw_coaches_votes %>%
  dplyr::filter(Round == 9) %>% 
  head()

We could also return coaches votes for matches including a particular team.

fetch_coaches_votes(season = 2021, comp = "AFLM", team = "Western Bulldogs")
fitzRoy:::aflm_coaches_votes %>%
  dplyr::filter(Home.Team == "Western Bulldogs" | Away.Team == "Western Bulldogs") %>% 
  head()
fetch_coaches_votes(season = 2021, comp = "AFLW", team = "Western Bulldogs")
fitzRoy:::aflw_coaches_votes %>%
  dplyr::filter(Home.Team=="Western Bulldogs" | Away.Team == "Western Bulldogs") %>% 
  head()

Combining these, we can return coaches votes for a single match.

fetch_coaches_votes(season = 2021, round_number = 24, comp = "AFLM", team = "Western Bulldogs")
fitzRoy:::aflm_coaches_votes %>%
  dplyr::filter(Home.Team=="Western Bulldogs" & Round == 24) %>% 
  head()
fetch_coaches_votes(season = 2021, round_number = 9, comp = "AFLW", team = "Western Bulldogs")
fitzRoy:::aflw_coaches_votes %>%
  dplyr::filter(Home.Team=="Western Bulldogs" & Round == 9) %>% 
  head()

Calculating Coaches Vote Possibilities

The calculate_coaches_vote_possibilities function accepts two arguments.

Examples

The following code will return the coaches votes for a particular match, then find the possible coaches vote breakdowns.

df <- fetch_coaches_votes(season = 2021, round_number = 24, comp = "AFLM", team = "Western Bulldogs")
calculate_coaches_vote_possibilities(df, "Coach View")
fitzRoy:::aflm_coaches_votes %>%
  dplyr::filter(Round == 24 & Home.Team == "Western Bulldogs") %>%
  fitzRoy:::calculate_coaches_vote_possibilities("Coach View")

The following code will create a data frame manually, then find the possible coaches vote breakdowns.

df <- data.frame(
                Player.Name = c("Tom Liberatore","Jack Macrae","Marcus Bontempelli","Cody Weightman","Darcy Parish","Aaron Naughton","Jordan Ridley"),
                Coaches.Votes = c(7, 6, 5, 5, 4, 2, 1)
)
calculate_coaches_vote_possibilities(df, "Player View")


Try the fitzRoy package in your browser

Any scripts or data that you put into this service are public.

fitzRoy documentation built on March 7, 2023, 6:45 p.m.