Title: | Perana Sports Volleyball Files |
---|---|
Description: | Basic functions for reading and working with Perana Sports volleyball scouting files. |
Authors: | Ben Raymond [aut, cre], Chau Le [ctb], Adrien Ickowicz [ctb] |
Maintainer: | Ben Raymond <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.7.6 |
Built: | 2024-12-26 04:43:19 UTC |
Source: | https://github.com/openvolley/peranavolley |
Extract the plays component from a peranavolley object
plays(x)
plays(x)
x |
peranavolley: a peranavolley object as returned by |
The plays component of x (a data.frame)
## Not run: x <- pv_read(pv_example_file()) inspect(plays(x)) ## End(Not run)
## Not run: x <- pv_read(pv_example_file()) inspect(plays(x)) ## End(Not run)
Example psvt data files provided as part of the peranavolley package
pt_example_file(choice = 1)
pt_example_file(choice = 1)
choice |
numeric: which data file to return?
|
path to the file
myfile <- pt_example_file() x <- pt_read(myfile)
myfile <- pt_example_file() x <- pt_read(myfile)
Read a Perana Sports tagger (psvt) data file
pt_read(filename, raw_only = FALSE)
pt_read(filename, raw_only = FALSE)
filename |
string: path to file |
raw_only |
logical: if |
A list with elements meta
(metadata including the project and template information, and information about the skills and grades used in the tags) and tags
the tag data.
This is somewhat experimental. It may be useful if one wants to read an existing file, modify the content, and re-write it back to a psvt file.
pt_write(x, filename)
pt_write(x, filename)
x |
character: data to write. See e.g the |
filename |
string: path to file |
Define the interpretation of errortypes associated with events.
pv_default_errortypes()
pv_default_errortypes()
a tibble with columns "skill", "errortype", and "evaluation"
pv_default_errortypes()
pv_default_errortypes()
Define the interpretation of eventgrades associated with events.
pv_default_eventgrades()
pv_default_eventgrades()
a tibble with columns "skill", "eventgrade", "evaluation_code" (the equivalent DataVolley code, if there is one), "evaluation", and "win_loss"
pv_default_eventgrades()
pv_default_eventgrades()
Define the interpretation of subevents associated with events.
pv_default_subevents()
pv_default_subevents()
a tibble with columns "skill", "subevent", and "evaluation"
pv_default_subevents()
pv_default_subevents()
These example files were kindly provided by Chau Le from Perana Sports.
pv_example_file(choice = 1)
pv_example_file(choice = 1)
choice |
numeric: which data file to return?
|
path to the file
myfile <- pv_example_file() x <- pv_read(myfile) summary(x)
myfile <- pv_example_file() x <- pv_read(myfile) summary(x)
Read Perana Sports volleyball data file
pv_read( filename, insert_technical_timeouts = FALSE, do_warn = FALSE, extra_validation = 2, raw_only = FALSE, eventgrades = pv_default_eventgrades(), errortypes = pv_default_errortypes(), subevents = pv_default_subevents(), setting_zones, postprocess = NULL )
pv_read( filename, insert_technical_timeouts = FALSE, do_warn = FALSE, extra_validation = 2, raw_only = FALSE, eventgrades = pv_default_eventgrades(), errortypes = pv_default_errortypes(), subevents = pv_default_subevents(), setting_zones, postprocess = NULL )
filename |
string: path to file |
insert_technical_timeouts |
logical: if |
do_warn |
logical: should we issue warnings about the contents of the file as we read it? |
extra_validation |
numeric: should we run some extra validation checks on the file? 0=no extra validation, 1=check only for major errors, 2=somewhat more extensive, 3=the most extra checking |
raw_only |
logical: if |
eventgrades |
tibble: a tibble that defines the interpretations of |
errortypes |
tibble: a tibble that defines the interpretations of |
subevents |
tibble: a tibble that defines the interpretations of |
setting_zones |
named character: if the data file has been scouted using setting zones, then each attack will have its associated setting zone (numbered 1 to 5). The setting zone names are not stored in the file, so they can be provided here as a character vector. This can either be an un-named character vector, in which case it must be of length 5; otherwise if only a subset of the five setting zones are being used then it can be provided as a named character vector(e.g. |
postprocess |
string or function: function, or name of function, to apply to the peranavolley object as the final step in the processing |
A named list with several elements. raw
contains the extracted but unparsed text from the psvb file, meta
provides match metadata, plays
the play-by-play data in the form of a data.frame, and messages
is a data.frame describing any inconsistencies found in the file.
pv_validate
, pv_default_eventgrades
, pv_default_errortypes
filename <- pv_example_file() x <- pv_read(filename) x <- pv_read(filename, setting_zones = c("X1", "X2", "X7", "medium/fast", "high"))
filename <- pv_example_file() x <- pv_read(filename) x <- pv_read(filename, setting_zones = c("X1", "X2", "X7", "medium/fast", "high"))
Notes:
the rules are applied in order, so that a row in x
that matches multiple rows in remap$conditions
will have the first matching row applied to it. Similarly, if remap
is provided as a list of remaps, then these will be applied in order and only the first matching one will be applied to any given row
pv_recode(x, remap, log_changes = FALSE)
pv_recode(x, remap, log_changes = FALSE)
x |
data.frame or tibble: a peranavolley object as returned by |
remap |
list: a remapping is defined by a list with two data.frames. The data.frame named "conditions" defines the conditions to match on, and the one named "values" provides the new values to use. See the example provided and |
log_changes |
logical: if |
A copy of x
with new values applied
## read file x <- pv_read(pv_example_file()) ## construct the remapping my_remap <- list(conditions = data.frame(attack_code = c("1", NA_character_, "4", "5"), start_zone = c(NA, 3, 2, 2), stringsAsFactors = FALSE), values = data.frame(attack_code = c("X1", "Z3", "X6", "V6"), stringsAsFactors = FALSE)) ## meaning that: any attack with attack_code 1 will be recoded as an "X1" attack ## any attack from start_zone 3 will be recoded as an "Z3" attack ## any attack from start_zone 2 with attack_code 4 will be recoded as an "X6" attack ## any attack from start_zone 2 with attack_code 5 will be recoded as an "V6" attack x <- pv_recode(x, remap = my_remap)
## read file x <- pv_read(pv_example_file()) ## construct the remapping my_remap <- list(conditions = data.frame(attack_code = c("1", NA_character_, "4", "5"), start_zone = c(NA, 3, 2, 2), stringsAsFactors = FALSE), values = data.frame(attack_code = c("X1", "Z3", "X6", "V6"), stringsAsFactors = FALSE)) ## meaning that: any attack with attack_code 1 will be recoded as an "X1" attack ## any attack from start_zone 3 will be recoded as an "Z3" attack ## any attack from start_zone 2 with attack_code 4 will be recoded as an "X6" attack ## any attack from start_zone 2 with attack_code 5 will be recoded as an "V6" attack x <- pv_recode(x, remap = my_remap)
Augment partially-scouted data
pv_tas_data_augment(x)
pv_tas_data_augment(x)
x |
peranavolley: a peranavolley object as returned by |
A peranavolley object with additional rows added to its plays
component.
pv_read
, pv_tas_recode
, pv_tas_live_recode
Note that this function is only likely to be useful if you have scouted your VBStats files following the conventions described at https://raymondben.github.io/scouting-notes/
pv_tas_recode(x, remap = pv_tas_remap(), log_changes = FALSE) pv_tas_live_recode( x, remap = pv_tas_remap(), home_team_rotation = NULL, visiting_team_rotation = NULL, log_changes = FALSE ) pv_tas_recode_augment(x, remap = pv_tas_remap(), log_changes = FALSE) pv_tas_live_recode_augment( x, remap = pv_tas_remap(), home_team_rotation = NULL, visiting_team_rotation = NULL, log_changes = FALSE ) pv_tas_remap()
pv_tas_recode(x, remap = pv_tas_remap(), log_changes = FALSE) pv_tas_live_recode( x, remap = pv_tas_remap(), home_team_rotation = NULL, visiting_team_rotation = NULL, log_changes = FALSE ) pv_tas_recode_augment(x, remap = pv_tas_remap(), log_changes = FALSE) pv_tas_live_recode_augment( x, remap = pv_tas_remap(), home_team_rotation = NULL, visiting_team_rotation = NULL, log_changes = FALSE ) pv_tas_remap()
x |
data.frame or tibble: a peranavolley object as returned by |
remap |
list: a list with components "conditions" and "values" that define the remapping. See |
log_changes |
logical: if |
home_team_rotation |
string: fixed rotation of the home team, either "SHM" or "SMH". This will be used to infer missing attack |
visiting_team_rotation |
string: as for |
This function modifies the plays component of a peranavolley object, following the scouting conventions described at https://raymondben.github.io/scouting-notes/. The following changes are made:
attacks marked as "Setter tip" ("Dump" in VBStats) by a setter are mapped to attack_code "PP"
any "Setter tip" by a non-setter are treated as freeballs. Their skill entry is changed to "Freeball", and attack code to NA
attack_code 1 to "X1"
attack_code 2 to "X2"
attack_code 3 to "X7"
attack_code 4 to "CF" (slide)
attack code 5 treated as highball, with new attack code determined by start_zone (V5, V6, etc)
any other attack (with NA attack code) treated as standard tempo with new attack code determined by start_zone (X5, X6, etc)
any dig following a freeball over is changed to skill "Freeball"
pv_tas_recode_augment
and pv_tas_live_recode_augment
are convenience functions that call pv_tas_recode
or pv_tas_live_recode
followed by pv_tas_data_augment
A modified version of x
.
## Note: this is a silly example, because the example VBStats file was NOT ## scouted with the conventions expected by this function x <- pv_read(pv_example_file()) x <- pv_tas_recode(x, remap = pv_tas_remap(), log_changes = TRUE)
## Note: this is a silly example, because the example VBStats file was NOT ## scouted with the conventions expected by this function x <- pv_read(pv_example_file()) x <- pv_tas_recode(x, remap = pv_tas_remap(), log_changes = TRUE)
Validate parsed Perana Volleyball scouting data
pv_validate(x, validation_level = 2)
pv_validate(x, validation_level = 2)
x |
peranavolley: peranavolley object as returned by |
validation_level |
numeric: how strictly to check? If 0, perform no checking; if 1, only identify major errors; if 2, also return any issues that are likely to lead to misinterpretation of data; if 3, return all issues (including minor issues) |
data.frame with columns message (the validation message), file_line_number (the corresponding line number in the file), video_time, and file_line (the actual line from the file).
filename <- pv_example_file() x <- pv_read(filename) pv_validate(x)
filename <- pv_example_file() x <- pv_read(filename) pv_validate(x)
This is somewhat experimental. It may be useful if one wants to read an existing file, modify the content, and re-write it back to a PSVB file.
pv_write(x, filename)
pv_write(x, filename)
x |
character: data to write. See e.g the |
filename |
string: path to file |
## Not run: x <- pv_read(pv_example_file()) new_file_name <- tempfile(fileext = ".psvb") pv_write(x$raw, filename = new_file_name) ## End(Not run)
## Not run: x <- pv_read(pv_example_file()) new_file_name <- tempfile(fileext = ".psvb") pv_write(x$raw, filename = new_file_name) ## End(Not run)