Skip to content

Commit

Permalink
catch videos that have no video_times (not synced) v0.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondben committed Oct 25, 2023
1 parent d16e7d3 commit fac4b2c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ovva
Title: A Shiny App for Volleyball Video Analysis
Version: 0.12.0
Version: 0.12.1
Authors@R: c(person(given = "Adrien", family = "Ickowicz", role = c("aut", "cre"), email = "[email protected]"),
person(given = "Ben", family = "Raymond", role = "aut"),
person("openvolley.org", role = "org"))
Expand Down
59 changes: 38 additions & 21 deletions R/shiny_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ovva_shiny_server <- function(app_data) {
meta_unfiltered <- reactiveVal(NULL)
pbp <- reactiveVal(NULL)
pbp_augment <- reactiveVal(NULL)
got_no_video <- reactiveVal(FALSE) ## only used to show message about no matches with video
got_no_video <- reactiveVal(0L) ## only used to show message about no matches with video: 0 = ok, 1 = all files missing video, 2 = all files missing video times and/or videos
season_data_type <- reactiveVal("indoor")
empty_video_list <- dplyr::tibble(match_id = character(), filename = character(), video_source = character())
video_list <- reactiveVal(empty_video_list)
Expand Down Expand Up @@ -112,7 +112,7 @@ ovva_shiny_server <- function(app_data) {
## prune out any that don't have video
if (!is.null(out)) out <- Filter(function(z) !is.null(z$video) && nrow(z$video) > 0, out)
if (length(out) < 1) {
got_no_video(TRUE)
got_no_video(1L)
video_list(empty_video_list)
pbp(NULL)
pbp_augment(NULL)
Expand Down Expand Up @@ -146,14 +146,12 @@ ovva_shiny_server <- function(app_data) {
out <- Filter(Negate(is.null), lapply(out, function(z) if (nrow(z$video) == 1 && !is.na(z$video$file) && nzchar(z$video$file)) z))
if (length(out) < 1) {
## no files with video
got_no_video(TRUE)
got_no_video(1L)
pbp(NULL)
pbp_augment(NULL)
out <- NULL
} else {
got_no_video(FALSE)
## now process pbp()
my_match_ids <- as.character(lapply(out, function(z) z$match_id))
## will also need to check actual plays data to remove any files with all-missing video times
showModal(modalDialog(title = "Processing match data ...", footer = NULL, "Please wait"))
if (file.exists(file.path(get_data_paths()[[input$season]], "alldata.rds"))) {
## use alldata.rds if available
Expand All @@ -169,25 +167,41 @@ ovva_shiny_server <- function(app_data) {
do.call(dv_read, dvargs)$plays
}))
}
## augment the match_id values with input$season, in case there are the same matches in different data sets (seasons)
## augment the match_id values with input$season to match what we did to the match_ids in the metadata above
mydat$match_id <- paste0(sdigest, "|", mydat$match_id)

mydat <- mydat[mydat$match_id %in% my_match_ids, ]
mydat <- ungroup(mutate(group_by(mydat, .data$match_id), game_date = min(as.Date(.data$time), na.rm = TRUE)))
## replace missing game dates with those from meta, if we can
mydat <- left_join(mydat, game_dates_meta %>% dplyr::rename(game_date2 = "game_date"), by = "match_id") %>%
mutate(game_date = if_else(is.na(.data$game_date) | is.infinite(.data$game_date), .data$game_date2, .data$game_date)) %>%
dplyr::select(-"game_date2")
## check for all-missing video times now
no_video_times_mids <- mydat %>% group_by(.data$match_id) %>% dplyr::summarize(nv = all(is.na(.data$video_time))) %>% dplyr::filter(.data$nv) %>% pull(.data$match_id)
cat("nvt:\n"); print(no_video_times_mids)
## remove those from out
out <- Filter(Negate(is.null), lapply(out, function(z) if (z$match_id %in% no_video_times_mids) NULL else z))
if (length(out) < 1) {
## no files with video/video times
got_no_video(2L)
pbp(NULL)
pbp_augment(NULL)
out <- NULL
} else {
my_match_ids <- as.character(lapply(out, function(z) z$match_id))
mydat <- dplyr::filter(mydat, .data$match_id %in% my_match_ids)
got_no_video(0L)
## now process pbp()
mydat <- mydat[mydat$match_id %in% my_match_ids, ]
mydat <- ungroup(mutate(group_by(mydat, .data$match_id), game_date = min(as.Date(.data$time), na.rm = TRUE)))
## replace missing game dates with those from meta, if we can
mydat <- left_join(mydat, game_dates_meta %>% dplyr::rename(game_date2 = "game_date"), by = "match_id") %>%
mutate(game_date = if_else(is.na(.data$game_date) | is.infinite(.data$game_date), .data$game_date2, .data$game_date)) %>%
dplyr::select(-"game_date2")
## mydat <- mutate(mydat, game_id = paste0(gsub('\\b(\\pL)\\pL{1,}|.','\\U\\1', .data$home_team, perl = TRUE),
## "_", gsub('\\b(\\pL)\\pL{1,}|.','\\U\\1',.data$visiting_team, perl = TRUE)))
## mydat <- mutate(mydat, game_id = case_when(!is.na(.data$game_date) & !is.infinite(.data$game_date) ~ paste0(.data$game_date, "_", .data$game_id),
## TRUE ~ .data$game_id))
## ## de-duplicate game_ids
## dedup <- mutate(distinct(dplyr::select(mydat, .data$match_id, .data$game_id)), game_id = make.unique(.data$game_id, sep = "_"))
## mydat <- left_join(dplyr::select(mydat, -"game_id"), dedup, by = "match_id")
pbp(mydat)
## Augment pbp with additional covariates
pbp_augment(preprocess_data(mydat, data_type = season_data_type()))
pbp(mydat)
## Augment pbp with additional covariates
pbp_augment(preprocess_data(mydat, data_type = season_data_type()))
}
}
}
removeModal()
Expand All @@ -196,7 +210,7 @@ ovva_shiny_server <- function(app_data) {
out
} else {
isolate({
got_no_video(FALSE)
got_no_video(0L)
meta_unfiltered(NULL)
video_list(empty_video_list)
pbp(NULL)
Expand All @@ -219,11 +233,14 @@ ovva_shiny_server <- function(app_data) {
if (is.null(input$season)) {
tags$div(class = "alert alert-info", "No competition data sets. Log in?")
} else if (!is.null(meta()) && is.null(pbp())) {
tags$div(class = "alert alert-danger", "No matches with video could be found.")
tags$div(class = "alert alert-danger", "All matches are missing their video files.")
} else if (is.null(meta()) && have_done_startup()) {
if (isTRUE(isolate(got_no_video()))) {
tags$div(class = "alert alert-danger", "No matches with video could be found.")
if (isolate(got_no_video()) > 1L) {
tags$div(class = "alert alert-danger", "All matches are missing their video files and/or have not been synchronized with video.")
} else if (isolate(got_no_video()) > 0L) {
tags$div(class = "alert alert-danger", "All matches are missing their video files.")
} else {
## some other failure
tags$div(class = "alert alert-danger", "Sorry, something went wrong processing this data set.")
}
} else {
Expand Down

0 comments on commit fac4b2c

Please sign in to comment.