The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Analysis of Spanish play-by-play data

Guillermo Vinue

2024-01-09

This document contains all the needed R code to reproduce the results described in the paper A Basketball Big Data Platform for Box Score and Play-by-Play Data, that has been submitted for publication. It presents the dashboard available at https://www.uv.es/vivigui/AppPBP.html. This dashboard belongs to the platform available at https://www.uv.es/vivigui/basketball_platform.html.

# Firstly, load BAwiR and other packages that will be used in the paper:
library(BAwiR) # 1.3
library(tidyverse) # 1.3.2

The following data file is an illustration of the type of play-by-play data available from the Spanish ACB league.

df0 <- acb_vbc_cz_pbp_2223

day_num <- unique(acb_vbc_cz_pbp_2223$day)
game_code <- unique(acb_vbc_cz_pbp_2223$game_code)

Do some first data processing:

acb_games_2223_sl <- acb_vbc_cz_sl_2223 %>%
  filter(period == "1C")

df1 <- do_prepare_data(df0, day_num, 
                      acb_games_2223_sl, acb_games_2223_info,
                      game_code)
# Lineups and sub-lineups:
data_li <- do_lineup(df1, day_num, game_code, "Valencia Basket", FALSE) 
data_subli <- do_sub_lineup(data_li, 4)
# Possessions:
data_poss <- do_possession(df1, "1C")  
# Timeouts:
df1_to <- do_prepare_data_to(df0, TRUE, acb_games_2223_info, acb_games_2223_coach)
data_to <- do_time_out_success(df1_to, day_num, game_code, 
                               "Casademont Zaragoza_Porfirio Fisac", FALSE)
# Periods:
df0_per <- df0

rm_overtime <- TRUE # Decide if remove overtimes.
if (rm_overtime) {
  df0 <- df0 %>%
    filter(!grepl("PR", period)) %>%
    mutate(period = as.character(period))
}
  
team_sel <- "Valencia Basket" # "Casademont Zaragoza"
period_sel <- "1C"            # "4C"
player_sel <- "Webb"          # "Mara"
  
df1 <- df0 %>%
  filter(team == team_sel) %>%
  filter(!action %in% c("D - Descalificante - No TL", "Altercado no TL")) 
    
df2 <- df1 %>%
  filter(period == period_sel)
    
df0_inli_team <- acb_vbc_cz_sl_2223 %>% 
  filter(team == team_sel, period == period_sel)
  
df3 <- do_prepare_data(df2, day_num, 
                       df0_inli_team, acb_games_2223_info,
                       game_code)
                         
data_per <- do_stats_per_period(df3, day_num, game_code, team_sel, period_sel, player_sel)

# Clutch time:
data_clutch <- do_clutch_time(acb_vbc_cz_pbp_2223)
# Free throw fouls:
data_ft_comm <- do_ft_fouls(df0, "comm")
data_ft_rec <- do_ft_fouls(df0, "rec")

# Offensive fouls:
data_off_comm <- do_offensive_fouls(df0, "comm")
data_off_rec <- do_offensive_fouls(df0, "rec")
# Offensive rebounds:
df1_or <- do_prepare_data_or(df0, TRUE, acb_games_2223_info)
data_or <- do_reb_off_success(df1_or, day_num, game_code, "Valencia Basket", FALSE)
sessionInfo()
## R version 3.6.3 (2020-02-29)
## Platform: x86_64-redhat-linux-gnu (64-bit)
## Running under: Fedora 30 (Workstation Edition)
## 
## Matrix products: default
## BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
## 
## locale:
##  [1] LC_CTYPE=es_ES.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=es_ES.UTF-8        LC_COLLATE=C              
##  [5] LC_MONETARY=es_ES.UTF-8    LC_MESSAGES=es_ES.UTF-8   
##  [7] LC_PAPER=es_ES.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## loaded via a namespace (and not attached):
##  [1] digest_0.6.33   R6_2.5.1        jsonlite_1.8.7  evaluate_0.21  
##  [5] rlang_1.1.1     cachem_1.0.8    cli_3.6.1       jquerylib_0.1.4
##  [9] bslib_0.5.1     rmarkdown_2.24  tools_3.6.3     xfun_0.40      
## [13] yaml_2.3.7      fastmap_1.1.1   compiler_3.6.3  htmltools_0.5.6
## [17] knitr_1.43      sass_0.4.7

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.