## This document was compiled on: 2023-04-18 21:52:22
This version provides a preview of team’s performance in Daly (using TBA data only)
You need to install the following packages
library(DT)
library(rmarkdown)
library(ggplot2)
library(tidyr)
library(GGally)
library(googlesheets4)
library(googledrive)
library(corrplot)
library(tidyverse)
library(dplyr)
library(glue)
library(tibble)
library(purrr)
library(stringr)
library(ggrepel)
library(ggpubr)
library(jsonlite)
## local imports
file_sources <- list.files(c("api"), pattern = "\\.R$",
full.names = TRUE, ignore.case = TRUE)
## sapply(file_sources, source)
file_sources
## [1] "api/driver.R" "api/eventlist.R" "api/eventmatches.R"
## [4] "api/eventmatchesV2.R" "api/eventmean.R" "api/eventmeanV2.R"
## [7] "api/eventmerge.R" "api/eventmerge2.R" "api/getAllianceScore.R"
## [10] "api/getEventDataV2.R" "api/getTeamData.R" "api/teamlist.R"
## [13] "api/teammatches.R" "api/teamopr.R" "api/teamscore.R"
## [16] "api/teamscoreV2.R" "api/teamscoreV3.R"
if (!exists("api_key")) {
readRenviron("example.env")
api_key <- Sys.getenv("API_KEY")
}
Read all TBA regional events; calculate OPR and download all files
source("api/eventlist.R")
##
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
##
## set_names
## The following object is masked from 'package:tidyr':
##
## extract
season2023 = get_event_list(2023, api_key)
season2023 = get_filtered_events(season2023)
dim(season2023)
## [1] 172 11
## download all data and obtain opr
allevents = paste0("2023", season2023$event_code)
# Pull all match statistics except "2023tuis3"
for(event_key in allevents[-149])
{
print(event_key)
oprInfoTBA = get_event_dataV2(event_key, api_key) %>% mutate_if(is.numeric, round, digits=2)
rownames(oprInfoTBA) = oprInfoTBA[,1]
oprInfoTBA[,1] = as.integer(gsub("frc", "", oprInfoTBA[,1]))
## write out all the summary combined
write.csv(oprInfoTBA, glue("output/eventsAll/{event_key}_all.csv"))
}
##
## event_key
## [1] "2023tuis3"
## > event_teams
## [1] "frc7544" "frc7570" "frc7742" "frc8500" "frc8785" "frc8799" "frc8881" "frc9201"
merge2023 = data.frame()
for(event_key in allevents[-149])
{
print(event_key)
df <- read.csv(glue("output/eventsAll/{event_key}_all.csv"))
df2 = data.frame(event_key, df)
merge2023 = rbind(merge2023, df2)
}
## [1] "2023alhu"
## [1] "2023arli"
## [1] "2023ausc"
## [1] "2023azgl"
## [1] "2023azva"
## [1] "2023bcvi"
## [1] "2023brbr"
## [1] "2023caav"
## [1] "2023cada"
## [1] "2023cafr"
## [1] "2023cala"
## [1] "2023camb"
## [1] "2023caoc"
## [1] "2023caph"
## [1] "2023casd"
## [1] "2023casf"
## [1] "2023casj"
## [1] "2023cave"
## [1] "2023chcmp"
## [1] "2023code"
## [1] "2023cthar"
## [1] "2023ctwat"
## [1] "2023flor"
## [1] "2023flta"
## [1] "2023flwp"
## [1] "2023gaalb"
## [1] "2023gacar"
## [1] "2023gacmp"
## [1] "2023gadal"
## [1] "2023gagwi"
## [1] "2023gamac"
## [1] "2023hiho"
## [1] "2023iacf"
## [1] "2023idbo"
## [1] "2023ilch"
## [1] "2023ilpe"
## [1] "2023incmp"
## [1] "2023ingre"
## [1] "2023inmis"
## [1] "2023inpri"
## [1] "2023inwla"
## [1] "2023iscmp"
## [1] "2023isde1"
## [1] "2023isde2"
## [1] "2023isde3"
## [1] "2023isde4"
## [1] "2023ksla"
## [1] "2023lake"
## [1] "2023mabos"
## [1] "2023mabri"
## [1] "2023marea"
## [1] "2023mawne"
## [1] "2023mawor"
## [1] "2023mdbet"
## [1] "2023mdtim"
## [1] "2023mibel"
## [1] "2023micmp1"
## [1] "2023micmp2"
## [1] "2023micmp3"
## [1] "2023micmp4"
## [1] "2023midet"
## [1] "2023midtr"
## [1] "2023miesc"
## [1] "2023mifor"
## [1] "2023mijac"
## [1] "2023mike2"
## [1] "2023miken"
## [1] "2023miket"
## [1] "2023mila2"
## [1] "2023milak"
## [1] "2023milan"
## [1] "2023miliv"
## [1] "2023milsu"
## [1] "2023mimcc"
## [1] "2023mimid"
## [1] "2023mimil"
## [1] "2023mimus"
## [1] "2023misal"
## [1] "2023misjo"
## [1] "2023mista"
## [1] "2023mitr2"
## [1] "2023mitry"
## [1] "2023mitvc"
## [1] "2023miwmi"
## [1] "2023mndu"
## [1] "2023mndu2"
## [1] "2023mnmi"
## [1] "2023mnmi2"
## [1] "2023mokc"
## [1] "2023mose"
## [1] "2023mosl"
## [1] "2023mrcmp"
## [1] "2023mslr"
## [1] "2023mxmo"
## [1] "2023mxpu"
## [1] "2023mxto"
## [1] "2023ncash"
## [1] "2023nccmp"
## [1] "2023ncjoh"
## [1] "2023ncmec"
## [1] "2023ncpem"
## [1] "2023ncwak"
## [1] "2023ndgf"
## [1] "2023necmp1"
## [1] "2023necmp2"
## [1] "2023nhdur"
## [1] "2023nhgrs"
## [1] "2023njfla"
## [1] "2023njrob"
## [1] "2023njski"
## [1] "2023njtab"
## [1] "2023njwas"
## [1] "2023nvlv"
## [1] "2023nyli"
## [1] "2023nyli2"
## [1] "2023nyny"
## [1] "2023nyro"
## [1] "2023nytr"
## [1] "2023ohcl"
## [1] "2023ohmv"
## [1] "2023okok"
## [1] "2023oktu"
## [1] "2023onbar"
## [1] "2023oncmp1"
## [1] "2023oncmp2"
## [1] "2023onham"
## [1] "2023onlon"
## [1] "2023onnew"
## [1] "2023onnob"
## [1] "2023ontor"
## [1] "2023onwat"
## [1] "2023onwin"
## [1] "2023orore"
## [1] "2023orsal"
## [1] "2023orwil"
## [1] "2023paben"
## [1] "2023paca"
## [1] "2023pahat"
## [1] "2023paphi"
## [1] "2023pncmp"
## [1] "2023qcmo"
## [1] "2023rinsc"
## [1] "2023scand"
## [1] "2023schar"
## [1] "2023tnkn"
## [1] "2023tuhc"
## [1] "2023tuis"
## [1] "2023tuis2"
## [1] "2023txama"
## [1] "2023txbel"
## [1] "2023txcha"
## [1] "2023txcle"
## [1] "2023txcmp1"
## [1] "2023txcmp2"
## [1] "2023txdal"
## [1] "2023txfor"
## [1] "2023txhou"
## [1] "2023txsan"
## [1] "2023txwac"
## [1] "2023utwv"
## [1] "2023vaale"
## [1] "2023vabla"
## [1] "2023vagle"
## [1] "2023vapor"
## [1] "2023waahs"
## [1] "2023wabon"
## [1] "2023wasam"
## [1] "2023wasno"
## [1] "2023wayak"
## [1] "2023wila"
## [1] "2023wimi"
dim(merge2023)
## [1] 6595 28
#[1] 6595 28
merge2023_order = merge2023[order(merge2023[,3]),]
##write.csv(merge2023_order , glue("output/events_merge_all.csv"), row.names = FALSE)
Read data from the self-created file “preScout_DalyDivision.csv”. We will focus on dalyTeams only
dalyTeams = read.csv("preScout_DalyDivision.csv", header=TRUE)
dalyTeams = data.frame(dalyTeams[seq(1, 151, 2),], dalyTeams[seq(2, 152, 2), 1])
daly_teams = paste0("frc", dalyTeams[,1])
daly_merge = merge2023_order[merge2023_order[,2] %in% daly_teams,]
write.csv(daly_merge , glue("output/daly_merge_all.csv"), row.names = FALSE)
## Note in the following code, "X" is the team name with "frc coded"
daly_merge = read.csv(glue("output/daly_merge_all.csv"), header=TRUE)
daly_merge_list = split.data.frame(daly_merge, f = daly_merge[,"X"])
## event_keys = unique(daly_merge[,1])
## daly_merge_info = merge_events_2(event_keys)
extractInfo = function(team_rows)
{
max_opr = max(team_rows$opr)
max_score_iqr = max(team_rows$score_iqr)
max_auto_opr = max(team_rows$auto_opr)
max_tele_opr = max(team_rows$teleop_opr)
max_auto_p_iqr = max(team_rows$auto_p_iqr)
max_tele_p_iqr = max(team_rows$tele_p_iqr)
auto_climb = mean(team_rows$count_auto_dock)
tele_climb = mean(team_rows$count_tele_dock)
max_opr_ratio = mean(team_rows$auto_teleop_opr_ratio)
max_ave_Foul = max(team_rows$ave_Foul)
max_total_Foul = max(team_rows$count_totalFoul)
ave_count_auto_mobility = mean(team_rows$count_auto_mobility)
max_miss_auto_balance = max(team_rows$count_miss_auto_balance)
max_miss_tele_balance = max(team_rows$count_miss_tele_balance)
ave_tele_gpc_opr = mean(team_rows$teleop_game_piece_opr)
return(data.frame(
max_opr, max_score_iqr, max_auto_opr,
max_tele_opr,
max_auto_p_iqr,
max_tele_p_iqr,
auto_climb,
tele_climb,
max_opr_ratio,
max_ave_Foul,
max_total_Foul,
ave_count_auto_mobility,
max_miss_auto_balance,
max_miss_tele_balance,
ave_tele_gpc_opr)
)
}
num_events = unlist(lapply(daly_merge_list, nrow))
tmp = as.data.frame(t(simplify2array(lapply(daly_merge_list, extractInfo))[1,,]))
tmp = apply(tmp, 2, unlist)
preDaly2023 = data.frame(team = names(daly_merge_list), num_events, tmp)
Look at the number of statistics we have calculated.
colnames(preDaly2023)
## [1] "team" "num_events"
## [3] "max_opr" "max_score_iqr"
## [5] "max_auto_opr" "max_tele_opr"
## [7] "max_auto_p_iqr" "max_tele_p_iqr"
## [9] "auto_climb" "tele_climb"
## [11] "max_opr_ratio" "max_ave_Foul"
## [13] "max_total_Foul" "ave_count_auto_mobility"
## [15] "max_miss_auto_balance" "max_miss_tele_balance"
## [17] "ave_tele_gpc_opr"
table(preDaly2023$num_events)
##
## 1 2 3 4
## 6 25 37 8
ggplot(daly_merge, aes(x = auto_opr, y = teleop_opr, color = as.factor(team))) +
geom_point() +
labs(x = "Auto OPR", y = "Teleop OPR", color = "Team") +
theme_bw()
ggplot(daly_merge, aes(x = opr, y = auto_opr, color = as.factor(team))) +
geom_point() +
labs(x = "OPR", y = "Auto OPR", color = "Team") +
theme_bw() +
facet_wrap(~ count_auto_balance, ncol = 2)
ggplot(preDaly2023, aes(x = max_opr, y = max_score_iqr, label = team)) +
geom_text() +
ggtitle("opr") +
theme_bw()
ggplot(preDaly2023, aes(x = max_auto_opr, y = max_auto_p_iqr, label = team)) +
geom_text() +
ggtitle("auto_opr") +
theme_bw()
ggplot(preDaly2023, aes(x = max_opr, y = max_total_Foul, label = team)) +
geom_text() + theme_bw()
fvar = c("max_opr", "max_total_Foul", "max_miss_tele_balance", "max_score_iqr")
ggpairs(preDaly2023, columns = fvar) + theme_bw()
datatable(preDaly2023, class = "cell-border stripe",
caption = "Pick List")