From 5c00067cb8af589327a1bd908617f7b48cabc78c Mon Sep 17 00:00:00 2001 From: SuperTikuwa Date: Tue, 29 Nov 2022 01:53:34 +0900 Subject: [PATCH] =?UTF-8?q?add:=20foul=E3=81=AE=E6=A4=9C=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/detect_foul.R | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 R/detect_foul.R diff --git a/R/detect_foul.R b/R/detect_foul.R new file mode 100644 index 0000000..cb53b4b --- /dev/null +++ b/R/detect_foul.R @@ -0,0 +1,47 @@ +detect_foul <- function(path) { + rcl <- path |> readr::read_lines() + + foul_actions <- c() + + count <- 1 + + for (i in rcl) { + str <- stringr::str_extract(i, "foul_\\w+_(l|r)") + if (!is.na(str)) { + foul_actions <- c(foul_actions, rcl[count - 1]) + } + count <- count + 1 + } + + foul_actions <- foul_actions |> + tibble::as_tibble() |> + dplyr::mutate( + step = value |> stringr::str_extract("\\d+") |> as.numeric(), + agent = value |> stringr::str_extract("\\w+_([0-9]{1,2}|Coach)"), + team = agent |> stringr::str_remove("_([0-9]{1,2}|Coach)"), + unum = agent |> stringr::str_extract("([0-9]{1,2}|Coach)$"), + commands = value |> + stringr::str_extract("\\(.+\\)$") |> + purrr::map(~ .x |> + stringr::str_split("\\(|\\)", simplify = TRUE) |> + stringr::str_trim() |> + purrr::discard(~ .x == "")), + ) |> + tidyr::unnest(commands) |> + dplyr::mutate( + commands = commands |> stringr::str_split("\\ ", n = 2), + command = commands |> purrr::map_chr(1), + args = commands |> purrr::map(~ .x[-1]), + ) |> + dplyr::select( + step, + team, + unum, + command, + args, + # line = value, + ) |> + dplyr::filter(command == "tackle") + + return(foul_actions) +} -- GitLab