jimmyday12 / fitzRoy

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

Inconsistent home and away teams in drawn finals using get_afltables_stats() #116

Closed insightlane closed 4 years ago

insightlane commented 4 years ago

In get_afltables_stats() for drawn finals, there are inconsistent Home.team and Away.team fields which seem to relate to the player-level Playing.for field (as per every other match). This is inconsistent with all other games where the Home.team and Away.team are static for each match. Seems to be okay for all other spot-checked drawn matches.


Brief description of the problem


afltables_data <- get_afltables_stats(start_date = "1897-05-07", end_date = Sys.Date())

afltables_data %>%
  filter(Season == 2010 & Round == "GF" & Home.score == Away.score) %>%
  distinct(Season, Round, Date, Venue, Home.team, Home.score, Away.team, Away.score, Playing.for) 

# A tibble: 2 x 9
  Season Round Date       Venue  Home.team   Home.score Away.team   Away.score Playing.for
   <dbl> <chr> <date>     <chr>  <chr>            <int> <chr>            <int> <chr>      
1   2010 GF    2010-09-25 M.C.G. Collingwood         68 St Kilda            68 Collingwood
2   2010 GF    2010-09-25 M.C.G. St Kilda            68 Collingwood         68 St Kilda   

afltables_data %>%
  distinct(Season, Round, Date, Venue, Home.team, Home.score, Away.team, Away.score) %>%
  filter(Home.score == Away.score) %>%
  group_by(Season, Round, Date, Venue) %>%
  mutate(count = n()) %>%
  filter(count > 1) %>%
  arrange(Date)

# A tibble: 16 x 9
# Groups:   Season, Round, Date, Venue [8]
   Season Round Date       Venue         Home.team       Home.score Away.team       Away.score count
    <dbl> <chr> <date>     <chr>         <chr>                <int> <chr>                <int> <int>
 1   1928 SF    1928-09-15 M.C.G.        Collingwood             62 Melbourne               62     2
 2   1928 SF    1928-09-15 M.C.G.        Melbourne               62 Collingwood             62     2
 3   1946 SF    1946-09-14 M.C.G.        Collingwood            100 Essendon               100     2
 4   1946 SF    1946-09-14 M.C.G.        Essendon               100 Collingwood            100     2
 5   1948 GF    1948-10-02 M.C.G.        Essendon                69 Melbourne               69     2
 6   1948 GF    1948-10-02 M.C.G.        Melbourne               69 Essendon                69     2
 7   1962 PF    1962-09-15 M.C.G.        Carlton                 85 Geelong                 85     2
 8   1962 PF    1962-09-15 M.C.G.        Geelong                 85 Carlton                 85     2
 9   1972 SF    1972-09-16 Waverley Park Carlton                 61 Richmond                61     2
10   1972 SF    1972-09-16 Waverley Park Richmond                61 Carlton                 61     2
11   1977 GF    1977-09-24 M.C.G.        Collingwood             76 North Melbourne         76     2
12   1977 GF    1977-09-24 M.C.G.        North Melbourne         76 Collingwood             76     2
13   1990 QF    1990-09-08 Waverley Park Collingwood             90 West Coast              90     2
14   1990 QF    1990-09-08 Waverley Park West Coast              90 Collingwood             90     2
15   2010 GF    2010-09-25 M.C.G.        Collingwood             68 St Kilda                68     2
16   2010 GF    2010-09-25 M.C.G.        St Kilda                68 Collingwood             68     2
jimmyday12 commented 4 years ago

I think this should be fixed on the development version on github @insightlane. Would love any feedback to confirm but at least the above test case should be fixed