jimmyday12 / fitzRoy

A set of functions to easily access AFL data
https://jimmyday12.github.io/fitzRoy
Other
125 stars 27 forks source link

Default number of season IDs returned on AFL API is 10, which excludes 2012:2014 #225

Closed jaidenpopowski closed 1 week ago

jaidenpopowski commented 1 week ago

When using {fitzRoy} functions to return data from the AFL API, there is an issue with finding season IDs. In find_season_id(), it requests for the AFL ids for compseasons, which has a default page length of 10. This means only the 10 most recent season ids can be returned from this function. As such, no functions work if you input seasons 2012, 2013 or 2014.

Adding ?pageSize=20 to the end of the API call (as done on the AFL site) will include all seasons.

afl_data <- fitzRoy::fetch_player_stats_afl(season = 2012)
#> ℹ Fetching match ids
#> Warning: Could not find a matching ID to the AFLM for 2012
#> Warning: No fixture data found for season 2012 on AFL.com.au for AFLM
#> Warning: No player stats data found for season 2012 on AFL.com.au for AFLM
#> ✔ Fetching match ids ... done

season <- 2012
comp <- "AFLM"

# From fitzRoy:::find_season_id()
season <- fitzRoy:::check_season(season)
comp <- fitzRoy:::check_comp(comp)
comp_id <- fitzRoy:::find_comp_id(comp)
api <- httr::modify_url("https://aflapi.afl.com.au", path = paste0("/afl/v2/competitions/", 
                                                                   comp_id, "/compseasons"))
resp <- httr::GET(api)
cont <- fitzRoy:::parse_resp_afl(resp)
cont$compSeasons
#>    id  providerId                        name   shortName currentRoundNumber
#> 1  62 CD_S2024014 2024 Toyota AFL Premiership Premiership                 16
#> 2  52 CD_S2023014 2023 Toyota AFL Premiership Premiership                 28
#> 3  43 CD_S2022014 2022 Toyota AFL Premiership Premiership                 27
#> 4  34 CD_S2021014 2021 Toyota AFL Premiership Premiership                 27
#> 5  20 CD_S2020014 2020 Toyota AFL Premiership Premiership                 22
#> 6  18 CD_S2019014 2019 Toyota AFL Premiership Premiership                 27
#> 7  14 CD_S2018014 2018 Toyota AFL Premiership Premiership                 27
#> 8  11 CD_S2017014 2017 Toyota AFL Premiership Premiership                 27
#> 9   9 CD_S2016014 2016 Toyota AFL Premiership Premiership                 27
#> 10  7 CD_S2015014 2015 Toyota AFL Premiership Premiership                 27

Created on 2024-07-01 with reprex v2.1.0