Skip to content

Commit 80f98eb

Browse files
committed
adding back in internal data for abbreviations functions
1 parent b74ce38 commit 80f98eb

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

R/sysdata.rda

4.01 KB
Binary file not shown.

data-raw/vignette_data.R

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,82 @@ tips_round <- get_squiggle_data("tips", round = 1, year = 2018)
2727
cookie <- get_aflw_cookie()
2828

2929

30-
usethis::use_data(results, fixture, stats, stats_gf, ladder, ladder_round, sources, tips, tips_round,
30+
# This is used by other parts so it's important to keep.
31+
# First lets load afldata provided
32+
load(here::here("data-raw", "afl_tables_playerstats", "afltables_playerstats_provided.rda"))
33+
34+
# Select out the columns we want
35+
afldata <- afldata %>%
36+
select(
37+
-X, -year, -month, -day,
38+
-Home.coach, -Home.coach.DOB, -Away.coach, -Away.coach.DOB,
39+
-Height, -Weight, -DOB
40+
)
41+
42+
# Save the names of the columns. Will be used internally by the package
43+
afldata_cols <- names(afldata)
44+
45+
# Function to fix abbreviations
46+
fix_abbreviations <- function(x) {
47+
map_chr(x, ~
48+
case_when(
49+
. == "KI" ~ "Kicks",
50+
. == "MK" ~ "Marks",
51+
. == "HB" ~ "Handballs",
52+
. == "GL" ~ "Goals",
53+
. == "BH" ~ "Behinds",
54+
. == "HO" ~ "Hit.Outs",
55+
. == "TK" ~ "Tackles",
56+
. == "RB" ~ "Rebounds",
57+
. == "IF" ~ "Inside.50s",
58+
. == "CL" ~ "Clearances",
59+
. == "CG" ~ "Clangers",
60+
. == "FF" ~ "Frees.For",
61+
. == "FA" ~ "Frees.Against",
62+
. == "BR" ~ "Brownlow.Votes",
63+
. == "CP" ~ "Contested.Possessions",
64+
. == "UP" ~ "Uncontested.Possessions",
65+
. == "CM" ~ "Contested.Marks",
66+
. == "MI" ~ "Marks.Inside.50",
67+
. == "One.Percenters" ~ "One.Percenters",
68+
. == "BO" ~ "Bounces",
69+
. == "GA" ~ "Goal.Assists",
70+
. == "TOG" ~ "Time.on.Ground..",
71+
. == "Jumper" ~ "Jumper.No",
72+
TRUE ~ ""
73+
))
74+
}
75+
76+
77+
# Let's get the stats
78+
# match_urls <- get_afltables_urls("01/06/2018", "15/06/2018")
79+
# dat <- scrape_afltables_match(match_urls)
80+
load(here::here("data-raw", "afl_tables_playerstats", "afltables_raw.rda"))
81+
82+
abb <- fix_abbreviations(names(afltables_raw))
83+
84+
stat_abbr <- tibble(
85+
stat = abb[abb != ""],
86+
stat.abb = names(afltables_raw)[abb != ""]
87+
)
88+
89+
90+
## Write data for abbreviations Team and Stats to a data frame that can be used
91+
team_abbr <- tibble(
92+
Team = c(
93+
"Adelaide", "Brisbane Lions", "Carlton", "Collingwood", "Essendon",
94+
"Fremantle", "Gold Coast", "Geelong", "Greater Western Sydney", "Hawthorn",
95+
"Melbourne", "North Melbourne", "Port Adelaide", "Richmond", "St Kilda",
96+
"Sydney", "Western Bulldogs", "West Coast"
97+
),
98+
Team.abb = c(
99+
"AD", "BL", "CA", "CW", "ES", "FR",
100+
"GC", "GE", "GW", "HW", "ME", "NM",
101+
"PA", "RI", "SK", "SY", "WB", "WC"
102+
)
103+
)
104+
105+
usethis::use_data(stat_abbr, team_abbr, afldata_cols,
106+
results, fixture, stats, stats_gf,
107+
ladder, ladder_round, sources, tips, tips_round,
31108
internal = TRUE, overwrite = TRUE)

0 commit comments

Comments
 (0)