New fitzRoy functions

The new AFL season, with it’s condensed fixture, is proving challenging for the old little R package fitzRoy. Luckily I’ve added a couple new functions to help!

You’ll need the development version of the package.

devtools::install_github("jimmyday12/fitzRoy")
library(fitzRoy)
library(dplyr)

Fixture

I recently noticed that the get_fixture function was broken. There is unfortunately not a lot I can do with that one. The Footywire website doesn’t provide round in it’s outputs and so I’ve always just calculated this assuming that rounds begin on Thursday/Friday and finish on Sunday/Monday. That obviously doesn’t work this year!

For example, see below. The games on the 2nd August are Round 9, the games on the 3rd of Augst should be Round 10. The games on the 8th of August should be Round 11!

fixture <- get_fixture(season = 2020)
fixture %>% filter(Date >= lubridate::dmy("02/08/2020") & Date <= lubridate::dmy("08/08/2020"))
## # A tibble: 9 x 7
##   Date                Season Season.Game Round Home.Team   Away.Team    Venue   
##   <dttm>               <dbl>       <int> <dbl> <chr>       <chr>        <chr>   
## 1 2020-08-02 15:35:00   2020           1     9 Gold Coast  GWS          Carrara 
## 2 2020-08-02 16:10:00   2020           1     9 Fremantle   Collingwood  Perth S…
## 3 2020-08-03 18:40:00   2020           1    10 Port Adela… Footscray    Adelaid…
## 4 2020-08-04 19:10:00   2020           1    10 Richmond    Brisbane Li… Carrara 
## 5 2020-08-05 17:40:00   2020           1    10 Geelong     North Melbo… Gabba   
## 6 2020-08-05 19:40:00   2020           1    10 Adelaide    Melbourne    Adelaid…
## 7 2020-08-06 17:40:00   2020           1    10 Collingwood Sydney       Gabba   
## 8 2020-08-06 20:10:00   2020           1    10 Gold Coast  St Kilda     Carrara 
## 9 2020-08-07 19:50:00   2020           1    10 Essendon    GWS          Carrara

I’m going to try and get it working but in the meantime, I’ve added a new function to return the fixture from the AFL.com.au website. OBviously this is not going to be the same as the normal get_fixture function and might need some tidying of names etc, but at least it works!

The function ask you to provide a season and an optional round as arguements.

fixture <- get_afl_fixture(season = 2020)
fixture %>% filter(date >= lubridate::dmy("02/08/2020") & date <= lubridate::dmy("08/08/2020")) %>%
  select(date, round_name, home_name, away_name, venue_name)
## # A tibble: 11 x 5
##    date       round_name home_name       away_name        venue_name      
##    <date>     <chr>      <chr>           <chr>            <chr>           
##  1 2020-08-02 Round 9    Gold Coast Suns GWS Giants       Metricon Stadium
##  2 2020-08-02 Round 9    Fremantle       Collingwood      Optus Stadium   
##  3 2020-08-03 Round 10   Port Adelaide   Western Bulldogs Adelaide Oval   
##  4 2020-08-04 Round 10   Richmond        Brisbane Lions   Metricon Stadium
##  5 2020-08-05 Round 10   Geelong Cats    North Melbourne  Gabba           
##  6 2020-08-05 Round 10   Adelaide Crows  Melbourne        Adelaide Oval   
##  7 2020-08-06 Round 10   Collingwood     Sydney Swans     Gabba           
##  8 2020-08-06 Round 10   Gold Coast Suns St Kilda         Metricon Stadium
##  9 2020-08-07 Round 10   Essendon        GWS Giants       Metricon Stadium
## 10 2020-08-08 Round 11   Port Adelaide   Richmond         Adelaide Oval   
## 11 2020-08-08 Round 11   Brisbane Lions  Western Bulldogs Gabba

Looks a lot better!

Results

The other issue I’ve found is that the AFL Tables website can sometimes take time to update after a around is over. Generally - all results come through 1-2 days after a round finishes.

get_match_results() %>%
  tail()
## # A tibble: 6 x 16
##    Game Date       Round Home.Team Home.Goals Home.Behinds Home.Points Away.Team
##   <dbl> <date>     <chr> <chr>          <int>        <int>       <int> <chr>    
## 1 15689 2020-07-31 R9    Essendon           3           10          28 Brisbane…
## 2 15690 2020-08-01 R9    North Me…         19            5         119 Adelaide 
## 3 15691 2020-08-01 R9    St Kilda          15           11         101 Sydney   
## 4 15692 2020-08-01 R9    West Coa…         11            7          73 Geelong  
## 5 15693 2020-08-02 R9    Gold Coa…          4           11          35 GWS      
## 6 15694 2020-08-02 R9    Fremantle         10            1          61 Collingw…
## # … with 8 more variables: Away.Goals <int>, Away.Behinds <int>,
## #   Away.Points <int>, Venue <chr>, Margin <int>, Season <dbl>,
## #   Round.Type <chr>, Round.Number <int>

This might be an issue moving forward if there are any delays in match results. To help here, I’ve added a new function to return results from footywire.com.

Again - you can provide a season input. Optionally - you can specify the last_n_games. This is a bit clunky but again, without having round as part of the website, it’s a tricky one to scrape. For now - returning the most recent n number of matches is the easiest approach.

get_footywire_match_results(2020, last_n_matches = 10)
## # A tibble: 10 x 8
##    Date       Time  Round  Venue   Home.Team  Away.Team  Home.Points Away.Points
##    <date>     <chr> <chr>  <chr>   <chr>      <chr>            <int>       <int>
##  1 2020-07-29 19:10 Round… " Metr… Western B… Richmond            49          90
##  2 2020-07-30 19:50 Round… " Gabb… Melbourne  Port Adel…          32          83
##  3 2020-07-31 15:40 Round… " Optu… Carlton    Hawthorn            58          89
##  4 2020-07-31 20:10 Round… " Metr… Essendon   Brisbane            28          91
##  5 2020-08-01 14:35 Round… " Metr… North Mel… Adelaide           119          50
##  6 2020-08-01 17:10 Round… " Gabb… St Kilda   Sydney             101          48
##  7 2020-08-01 18:10 Round… " Optu… West Coast Geelong             73          64
##  8 2020-08-02 15:35 Round… " Metr… Gold Coast GWS                 35          61
##  9 2020-08-02 16:10 Round… " Optu… Fremantle  Collingwo…          61          49
## 10 2020-08-03 18:40 Round… " Adel… Port Adel… Western B…          55          42

That’s about it - let me know how you go!

comments powered by Disqus