bit in that
  • Home
  • Fantasy
    • AFL
    • Top Coaches
    • Player Selections
    • AFLW
    • Top Coaches
    • Player Selections
  • Players
    • AFL
    • Draft Prospects
    • AFLW
    • Player Data
    • Draft Prospects

AFLW Player Data

library(reactable)
library(htmltools)
library(tippy)
library(bslib)
library(arrow)
library(stringr)
library(data.table)
library(dplyr)
library(purrr)

source("../../parameters.R")

source("https://github.com/bit-in-that/data-automation/raw/main/aflw_fantasy/modules/get_player_data_afw.R")
player_data <- get_player_data()
player_data_round <- get_player_data(by_round = TRUE)

player_details_all <- read_parquet("https://github.com/bit-in-that/data-automation/raw/main/players/data/raw/player_details_all.parquet")

player_data_columns <- as_tibble(fread("../player_data_column_info.csv"))


aflw_player_details <- player_details_all |> 
  filter(
    competition_name_lookup == "AFLW", year ==2023
  ) |>
  select(
    id = playerId,
    playerDetails.heightCm,
    playerDetails.age,
    date_of_birth = playerDetails.dateOfBirth,
    playerDetails.stateOfOrigin,
    # recruited_from = playerDetails.recruitedFrom,
    starts_with("averages")
  ) |> 
  select(-averages.ranking, -averages.ratingPoints, -averages.superGoals, -averages.fantasy_points, 
         -averages.turnovers, -averages.matchesPlayed, -averages.dreamTeamPoints) |>
  mutate(
    date_of_birth = as.Date(date_of_birth, format = "%e/%m/%Y")
  )  |> 
  rename_with(~ {
    .x |>
      str_remove("^averages\\.") #|>
  }, .cols = starts_with("averages")) |> 
  relocate(goals, .before = behinds) |> 
  relocate(kicks, .before = handballs)

season_stat_names <- aflw_player_details |> 
  select(behinds:tacklesInside50) |> 
  names()

player_data_restricted <- player_data |> 
  mutate(
      id = paste0("CD_I", id),
      gamesPlayed  = if_else(is.na(gamesPlayed), 0L, gamesPlayed)
    ) |> 
  select(id, full_name, squad_name, gamesPlayed, position, cost, avgPoints, avgPointsLast3, avgPointsLast5, seasonPriceChange, lastRoundPriceChange) |> 
  left_join(aflw_player_details, by = "id") |> 
  arrange(desc(cost)) |> 
  relocate(id, .before = playerDetails.heightCm)
format_price <- function(cell_value) {
  if(is.na(cell_value)) {
    ""
  } else {
    sign_prefix <- if(cell_value > 0) "" else "-"
    paste0(sign_prefix, "$", format(round(abs(cell_value/1000), digits = 0), big.mark = ","), "K")
    
  }
}

format_date <- function(cell_value) {
  if(is.na(cell_value)) {
    ""
  } else {
    format(cell_value, format = "%e %b %Y")
  }
}
# player_data_restricted

# TODO: for individual players create this and save as a RDS (generate in separate script), then whenever the full colDef is needed, it can be read in

verbose_name_map <- player_data_columns$verbose_name |> 
  `names<-`(player_data_columns$column_name)

hover_over_verbose_name <- function(header_value, column_name){
  tippy(header_value, verbose_name_map[column_name])
  }


reactable_specification <- player_data_columns |>
  filter(
   column_name %in% names(player_data_restricted)
  ) |> 
  mutate(
    colDefs_base = abbreviated_name |> 
      map2(width, ~ colDef(name = .x, header = hover_over_verbose_name, minWidth = .y)) |> 
      `names<-`(column_name),
     colDefs_base = case_when(
       is_price ~ map(colDefs_base, ~ structure(c(.x, list(cell = format_price)),  class = "colDef")),
       is_date ~ map(colDefs_base, ~ structure(c(.x, list(cell = format_date)),  class = "colDef")),
       TRUE ~ colDefs_base
      ),
    colDefs_default = colDefs_base |> 
      map2(default_stats, ~ structure(c(.x, list(show = .y)),  class = "colDef")),
    colDefs_basic = colDefs_base |> 
      map2(basic_stats, ~ structure(c(.x, list(show = .y)),  class = "colDef"))
  )

colGroups_default <- reactable_specification |> 
  group_by(grouping) |> 
  summarise(
    columns = list(column_name)
  ) |> 
  mutate(
    colGroups_default = map2(grouping, columns, ~ colGroup(name = .x, columns = .y, headerStyle = list("white-space" = "nowrap")))
  ) |> 
  pull()

additional_columns <- list(
  full_name = colDef(
    name = "Player",
    sticky = "left",
    cell = function(cell_value, row_index, column_name) {
      id <- player_data_restricted[["id"]][[row_index]]
      img_url <- paste0("https://aflwfantasy.afl/media/players/", str_remove(id, "CD_I"), "_500.webp")
      player_url <- paste0("https://dfsaustralia.com/aflw-fantasy-player-summary/?playerId=", id)
      tags$a(
        tags$img(src = img_url, style = "height: 24px;width: 24px;"),
        " ",
        cell_value,
        href = player_url,
        target = "_blank"
        )
      },
    width = 200)
  )


player_data_basic <- player_data_restricted |> 
  reactable(
    columns = c(reactable_specification$colDefs_basic, additional_columns),
    columnGroups = colGroups_default,
    elementId = "player-data",
    filterable = TRUE
    )

player_data_default <- player_data_restricted |> 
  reactable(
    columns = c(reactable_specification$colDefs_default, additional_columns),
    columnGroups = colGroups_default,
    elementId = "player-data-default",
    filterable = TRUE
    )
  • Basic
  • Main
tagList(
  tags$button("Download as CSV", onclick = "download_table()"),
  tags$button("Show All", onclick = "Reactable.setHiddenColumns('player-data', [''])"),
  player_data_basic
)
​
General
AFLW Fantasy
Player Info
Scoring
Disposals
Marks
Free Kicks
Ruck
Defence
Player
Gm
Pos
Ave
Team
G
B
D
K
H
M
FA
FF
HO
T
Ebony Marinoff
10
MID
128.5
Adelaide Crows
0.4
0.1
28.5
21.9
6.6
4.3
2.1
1.5
0
10.5
Ash Riddell
10
MID
116.1
North Melbourne
0.3
0.3
31.6
16.8
14.9
3.1
0.6
1.3
0
5.6
Jasmine Garner
10
MID
127
North Melbourne
0.8
0.9
30.3
19.9
10.4
3.5
0.4
1.6
0
6.6
Laura Gardiner
10
FWD
115.6
Sydney Swans
0.3
0
29
14.9
14.1
2.6
1.4
1.5
0
9.3
Monique Conti
10
MID
106.5
Richmond
0.4
0.4
27.5
15.5
12
3.3
1
2.4
0
5.5
Ellie Blackburn
10
MID
100
Western Bulldogs
0
0.4
25.8
14.4
11.4
3.8
0.5
1.5
0
4.9
Zarlie Goldsworthy
10
FWD
90.7
GWS Giants
1.4
0.8
18
9.3
8.8
3.8
0.8
1.4
0
6.1
Charlie Rowbottom
9
MID
113
Gold Coast Suns
0.1
0.3
27
13.9
13.1
3
1.8
2.6
0
10.4
Bonnie Toogood
10
FWD
102.2
Essendon
1.6
0.9
19.4
13.9
5.5
6.4
0.8
2.1
0.4
4.8
Madison Prespakis
10
MID
96.3
Essendon
0.4
0.3
27.5
13.1
14.4
3.1
1.8
3.5
0
5.8
1–10 of 576 rows
...
tagList(
  tags$button("Download as CSV", onclick = "download_table()"),
  tags$button("Show All", onclick = "Reactable.setHiddenColumns('player-data-default', [''])"),
  player_data_default
)
​
General
AFLW Fantasy
Player Info
Scoring
Clearances
Disposals
Marks
Free Kicks
Ruck
Defence
Player
Gm
Pos
Price
Ave
Team
Age
G
B
GA
CBA
D
K
H
I50
R50
DE%
KI
KI:PO
MG
CM
M
MI50
FA
FF
HO
HO:A
HO:W%
RC
T
PA
S
Ebony Marinoff
10
MID
$1,607K
128.5
Adelaide Crows
25
0.4
0.1
0.4
118
28.5
21.9
6.6
6
1.3
61.8
0
0
494.2
0.1
4.3
0.1
2.1
1.5
0
0
0
0
10.5
23.3
0.3
Ash Riddell
10
MID
$1,397K
116.1
North Melbourne
27
0.3
0.3
0.5
79
31.6
16.8
14.9
4.3
1.8
64
0
0
404.2
0
3.1
0.1
0.6
1.3
0
0
0
0
5.6
18.9
0
Jasmine Garner
10
MID
$1,396K
127
North Melbourne
29
0.8
0.9
0.9
90
30.3
19.9
10.4
7.8
1.6
65.3
0
0
566
0.1
3.5
0.4
0.4
1.6
0
0
0
0
6.6
18.5
0.3
Laura Gardiner
10
FWD
$1,371K
115.6
Sydney Swans
20
0.3
0
0.3
110
29
14.9
14.1
4.1
2.3
63.4
0
0
332.8
0
2.6
0
1.4
1.5
0
0
0
0
9.3
26.3
0.1
Monique Conti
10
MID
$1,366K
106.5
Richmond
23
0.4
0.4
0.3
105
27.5
15.5
12
5
1.9
63.2
0
0
405.4
0.1
3.3
0.1
1
2.4
0
0
0
0
5.5
21.3
0
Ellie Blackburn
10
MID
$1,350K
100
Western Bulldogs
28
0
0.4
0.1
109
25.8
14.4
11.4
3.8
2.1
58.7
0
0
353.7
0
3.8
0
0.5
1.5
0
0
0
0
4.9
19.8
0.4
Zarlie Goldsworthy
10
FWD
$1,345K
90.7
GWS Giants
18
1.4
0.8
0
58
18
9.3
8.8
1.9
1.3
55.6
0
0
237.1
0.6
3.8
1.1
0.8
1.4
0
0
0
0
6.1
18.6
0.6
Charlie Rowbottom
9
MID
$1,292K
113
Gold Coast Suns
20
0.1
0.3
0.6
104
27
13.9
13.1
3.6
0.8
62.5
0
0
293.5
0.8
3
0.3
1.8
2.6
0
0
0
0
10.4
17.4
0.3
Bonnie Toogood
10
FWD
$1,228K
102.2
Essendon
25
1.6
0.9
0.3
4
19.4
13.9
5.5
3.6
0.8
66.5
0
0
308.9
1.9
6.4
1.9
0.8
2.1
0.4
0
10.7
3.5
4.8
11.5
1
Madison Prespakis
10
MID
$1,222K
96.3
Essendon
22
0.4
0.3
0.3
96
27.5
13.1
14.4
2.3
2.4
60.9
1
1
290.5
0
3.1
0.5
1.8
3.5
0
0
0
0.1
5.8
12.1
0.3
1–10 of 576 rows
...
Back to top

2023 bit in that Source Code

 

Designed with using and Quarto