Skip to content

Commit

Permalink
Merge pull request #111 from American-Soccer-Analysis/develop
Browse files Browse the repository at this point in the history
Add USL Championship, USL League One, and NASL data
  • Loading branch information
tyler-richardett authored Mar 16, 2021
2 parents 7719616 + 6d3ace2 commit 9a351e7
Show file tree
Hide file tree
Showing 24 changed files with 749 additions and 439 deletions.
142 changes: 140 additions & 2 deletions config/leagues.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ league_config <- list(
ui = "tables_ui",
server = NA
)
)
)#,
# Profiles = list(
# players = list(
# display_name = "Players",
# route_link = "players",
# icon = "user",
# ui = "players_ui",
# server = NA
# )
# )
)
),
nwsl = list(
Expand Down Expand Up @@ -66,7 +75,136 @@ league_config <- list(
ui = "tables_ui",
server = NA
)
)
)#,
# Profiles = list(
# players = list(
# display_name = "Players",
# route_link = "players",
# icon = "user",
# ui = "players_ui",
# server = NA
# )
# )
)
),
uslc = list(
name = "USL Championship",
tabs = list(
Tables = list(
xgoals = list(
display_name = "xGoals",
route_link = "xgoals",
icon = "futbol-o",
subheaders = c("Players", "Teams", "Games", "Goalkeepers"),
ui = "tables_ui",
server = NA
),
xpass = list(
display_name = "xPass",
route_link = "xpass",
icon = "bullseye",
subheaders = c("Players", "Teams"),
ui = "tables_ui",
server = NA
),
`goals-added` = list(
display_name = "Goals Added (g+)",
route_link = "goals-added",
icon = "google-plus-g",
subheaders = c("Players", "Teams"),
ui = "tables_ui",
server = NA
)
)#,
# Profiles = list(
# players = list(
# display_name = "Players",
# route_link = "players",
# icon = "user",
# ui = "players_ui",
# server = NA
# )
# )
)
),
usl1 = list(
name = "USL League One",
tabs = list(
Tables = list(
xgoals = list(
display_name = "xGoals",
route_link = "xgoals",
icon = "futbol-o",
subheaders = c("Players", "Teams", "Games", "Goalkeepers"),
ui = "tables_ui",
server = NA
),
xpass = list(
display_name = "xPass",
route_link = "xpass",
icon = "bullseye",
subheaders = c("Players", "Teams"),
ui = "tables_ui",
server = NA
),
`goals-added` = list(
display_name = "Goals Added (g+)",
route_link = "goals-added",
icon = "google-plus-g",
subheaders = c("Players", "Teams"),
ui = "tables_ui",
server = NA
)
)#,
# Profiles = list(
# players = list(
# display_name = "Players",
# route_link = "players",
# icon = "user",
# ui = "players_ui",
# server = NA
# )
# )
)
),
nasl = list(
name = "North American Soccer League",
tabs = list(
Tables = list(
xgoals = list(
display_name = "xGoals",
route_link = "xgoals",
icon = "futbol-o",
subheaders = c("Players", "Teams", "Games", "Goalkeepers"),
ui = "tables_ui",
server = NA
),
xpass = list(
display_name = "xPass",
route_link = "xpass",
icon = "bullseye",
subheaders = c("Players", "Teams"),
ui = "tables_ui",
server = NA
),
`goals-added` = list(
display_name = "Goals Added (g+)",
route_link = "goals-added",
icon = "google-plus-g",
subheaders = c("Players", "Teams"),
ui = "tables_ui",
server = NA
)
)#,
# Profiles = list(
# players = list(
# display_name = "Players",
# route_link = "players",
# icon = "user",
# ui = "players_ui",
# server = NA
# )
# )
)
)
)
8 changes: 5 additions & 3 deletions config/tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,22 @@ tables_config <- list(
),
share_headed_shots = list(
app_name = "Header %",
tooltip_text = "Share of shots faced that were headed.",
tooltip_text = "Share of shots on target faced that were headed.",
percentage = TRUE
),
xgoals_gk_faced = list(
app_name = "xG",
tooltip_text = "xGoals",
tooltip_text = "xGoals (post-shot)",
normalize = TRUE
),
goals_minus_xgoals_gk = list(
app_name = "G-xG",
tooltip_text = "Negative values are better.",
normalize = TRUE
),
goals_divided_by_xgoals_gk = list(
app_name = "G/xG"
app_name = "G/xG",
tooltip_text = "Values closer to zero are better."
),
count_games = list(
app_name = "Games"
Expand Down
40 changes: 34 additions & 6 deletions global.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ library(tidyverse)
STAGE <- ifelse(grepl("stage", getwd()), "stage/", "")
API_PATH <- paste0("https://app.americansocceranalysis.com/", STAGE, "api/v1")

# VIOLIN_HEIGHT <- "450px"
# VIOLIN_WIDTH <- "96%"
VIOLIN_HEIGHT <- "400px"
VIOLIN_WIDTH <- "96%"
VIOLIN_MINIMUM_MINUTES <- 500

FIELD_WIDTH <- 80
FIELD_LENGTH <- 115

DATABASE_TIMEZONE <- "America/New_York"
DATABASE_TIMEZONE <- "UTC"

PATTERNS_OF_PLAY <- c("Corner", "Fastbreak", "Free kick", "Penalty", "Regular", "Set piece")
THIRDS_OF_FIELD <- c("Attacking", "Middle", "Defensive")
Expand Down Expand Up @@ -94,6 +95,29 @@ router_list_to_parse <- gsub(",\\s+$", ")", router_list_to_parse)
eval(parse(text = router_list_to_parse))


# Create lookup for controlbar panel ------------
controlbar_lookup <- list()

headers <- names(league_config[[league]][["tabs"]])
for (league in league_schemas) {
for (h in headers) {
tab_header <- league_config[[league]][["tabs"]][[h]]
menu_items <- names(tab_header)
for (m in menu_items) {
tab_name_prefix <- tab_header[[m]][["route_link"]]
subheaders <- tab_header[[m]][["subheaders"]]
if (!is.null(subheaders)) {
for (s in subheaders) {
controlbar_lookup[[paste0(league, "/", tab_name_prefix, "/", tolower(s))]] <- h
}
} else {
controlbar_lookup[[paste0(league, "/", tab_name_prefix)]] <- h
}
}
}
}


# Utility functions -----------------------------
api_request <- function(path = API_PATH, endpoint, parameters = NULL) {
parameters_array <- c()
Expand All @@ -119,7 +143,7 @@ api_request <- function(path = API_PATH, endpoint, parameters = NULL) {
paste0("?", paste0(parameters_array, collapse = "&")),
"")

return(fromJSON(content(GET(paste0(API_PATH, endpoint, parameters_array)),
return(fromJSON(content(GET(paste0(path, endpoint, parameters_array)),
as = "text", encoding = "UTF-8")))
}

Expand All @@ -128,9 +152,10 @@ get_config_element <- function(league, sidebar_header, route_prefix, league_conf
}

get_values_from_page <- function(page) {
page <- gsub("\\?.*$", "", page)
league <- gsub("/.*$", "", page)
subheader <- gsub(league, "", gsub("^.*/", "", page))
route_prefix <- gsub("/", "", gsub(league, "", gsub(subheader, "", page)))
route_prefix <- gsub("/.*$", "", gsub("^/", "", gsub(league, "", page)))
subheader <- gsub("/", "", gsub(route_prefix, "", gsub(league, "", page)))

return(list(
league = league,
Expand All @@ -140,6 +165,9 @@ get_values_from_page <- function(page) {
}

assemble_key <- function(league, route_prefix = NA, subheader = NA) {
route_prefix <- if (is.null(route_prefix)) NA else route_prefix
subheader <- if (is.null(subheader)) NA else subheader

if (!is.na(subheader) > 0) {
keys <- c()
for (s in subheader) {
Expand Down
18 changes: 9 additions & 9 deletions renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
},
"DT": {
"Package": "DT",
"Version": "0.17.1",
"Version": "0.17.2",
"Source": "GitHub",
"RemoteType": "github",
"RemoteHost": "api.github.com",
"RemoteRepo": "DT",
"RemoteUsername": "rstudio",
"RemoteRef": "HEAD",
"RemoteSha": "607e0d7bb9c717eb7bad378ef577430a697e0ba0",
"Hash": "ae7d6963a1a91ff5feb0237a2ab892ca"
"RemoteSha": "f0d511da3d32683342e9876c2b7da9ff1cd2f112",
"Hash": "9eab18168bad8b8034141dd33efc4f66"
},
"MASS": {
"Package": "MASS",
Expand Down Expand Up @@ -65,10 +65,10 @@
},
"Rcpp": {
"Package": "Rcpp",
"Version": "1.0.5",
"Version": "1.0.6",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "125dc7a0ed375eb68c0ce533b48d291f"
"Hash": "dbb5e436998a7eba5a9d682060533338"
},
"RcppEigen": {
"Package": "RcppEigen",
Expand Down Expand Up @@ -352,10 +352,10 @@
},
"htmltools": {
"Package": "htmltools",
"Version": "0.5.1",
"Version": "0.5.1.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "4d5452ff42a254e861282931190d052a"
"Hash": "af2c2531e55df5cf230c4b5444fc973c"
},
"htmlwidgets": {
"Package": "htmlwidgets",
Expand Down Expand Up @@ -576,10 +576,10 @@
},
"promises": {
"Package": "promises",
"Version": "1.1.1",
"Version": "1.2.0.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "a8730dcbdd19f9047774909f0ec214a4"
"Hash": "4ab2c43adb4d4699cf3690acd378d75d"
},
"ps": {
"Package": "ps",
Expand Down
Loading

0 comments on commit 9a351e7

Please sign in to comment.