From 45d1390d55fd4fe236e4b607145c3a3725c60c31 Mon Sep 17 00:00:00 2001 From: takumiamano Date: Wed, 13 Apr 2022 19:58:21 +0900 Subject: [PATCH 01/14] =?UTF-8?q?[add]rcg=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=81=AE=E8=AA=AD=E3=81=BF=E5=8F=96=E3=82=8A=E3=81=A8?= =?UTF-8?q?=E3=82=B0=E3=83=A9=E3=83=95=E4=BD=9C=E6=88=90=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/make_graphics.R | 17 +++++++++ R/read_rcg.R | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 R/make_graphics.R create mode 100644 R/read_rcg.R diff --git a/R/make_graphics.R b/R/make_graphics.R new file mode 100644 index 0000000..36d7aee --- /dev/null +++ b/R/make_graphics.R @@ -0,0 +1,17 @@ +make_graph <- function(p_data,teamname,num){ + p <- ggplot(data = p_data %>% filter(team==teamname,unum==num), aes(x = as.numeric(x), y = as.numeric(y))) + + ggplot2::coord_fixed(xlim=c(-55,55),ylim =c(-35,35))+ + geom_hline(yintercept = -34.1, linetype = "solid")+ + geom_hline(yintercept = 34.1, linetype = "solid")+ + geom_hline(yintercept = 0, linetype = "solid")+ + geom_vline(xintercept = 52.6, linetype = "solid")+ + geom_vline(xintercept = -52.6, linetype = "solid")+ + geom_vline(xintercept = 0, linetype = "solid")+ + geom_point(size=0.1) + + geom_density_2d_filled(alpha = 0.7) + return(p) +} + +#ggplot2::geom_path(size=1.2,aes(color = as.numeric(step))) + +# + +# ggplot2::geom_density2d(size = 0.25, colour = "black") \ No newline at end of file diff --git a/R/read_rcg.R b/R/read_rcg.R new file mode 100644 index 0000000..cc08da8 --- /dev/null +++ b/R/read_rcg.R @@ -0,0 +1,94 @@ +# remove(list = ls());gc() +# path = "~/socceR/R/test.rcg" +tag <- c("x","y","vx","vy") + +read_rcg_ball <- function(path){ + ball_log <- path |> + readr::read_lines() |> + tibble::as_tibble() |> + dplyr::mutate( + step = value |> stringr::str_extract("\\(show ([0-9]*)*") + |> stringr::str_remove("\\(show "), + ball = value |> stringr::str_extract("\\(\\(b\\)( [0-9\\-\\.]*)*\\)") + |> stringr::str_remove("\\(\\(b\\) ") + |> stringr::str_remove("\\)"), + x = ball |> stringr::str_extract("[0-9\\-\\.]+"), + y = ball |> stringr::str_remove(x) + |> stringr::str_extract("[0-9\\-\\.]+"), + vx = ball |> stringr::str_remove(x) + |> stringr::str_remove(y) + |> stringr::str_extract("[0-9\\-\\.]+"), + vy = ball |> stringr::str_remove(x) + |> stringr::str_remove(y) + |> stringr::str_remove(vx) + |> stringr::str_extract("[0-9\\-\\.]+"), + )|> + dplyr::select( + step, + # ball, + x, + y, + vx, + vy, + ) %>% tidyr::drop_na() + return(ball_log) +} + +read_rcg_player <- function(path){ + player_log <- path |> + readr::read_lines() |> + tibble::as_tibble() |> + dplyr::mutate( + step = value |> stringr::str_extract("\\(show ([0-9]*)*") + |> stringr::str_remove("\\(show "), + players = value |> stringr::str_extract_all("\\(\\([lr] [0-9]*\\) [0-9]* [0-9x]* ([0-9\\-\\.]* )*\\(v h [0-9\\-\\.]*\\) \\(s( [0-9\\-\\.]*)*\\)( \\(f [rl] [0-9\\-\\.]*\\))* \\(c( [0-9\\-\\.]*)*\\)\\)") + ) |> + tidyr::unnest(players) |> + dplyr::mutate( + player = players |> stringr::str_extract("\\([rl] [0-9]+\\)"), + team = player |> stringr::str_extract("[rl]"), + unum = player |> stringr::str_extract("[0-9]+"), + params = players |> stringr::str_remove("\\([rl] [0-9]+\\)"), + + type = params|> stringr::str_extract("[0-9\\-\\.x]+"), + l1 = params |> stringr::str_remove(type), + + state = l1 |> stringr::str_extract("[0-9\\-\\.x]+"), + l2 = l1 |> stringr::str_remove(state), + + x = l2 |> stringr::str_extract("[0-9\\-\\.]+"), + l3 = l2 |> stringr::str_remove(x), + + y = l3 |> stringr::str_extract("[0-9\\-\\.]+"), + l4 = l3 |> stringr::str_remove(y), + + vx = l4 |> stringr::str_extract("[0-9\\-\\.]+"), + l5 = l4 |> stringr::str_remove(vx), + + vy = l5 |> stringr::str_extract("[0-9\\-\\.]+"), + l6 = l5 |> stringr::str_remove(vy), + + body = l6 |> stringr::str_extract("[0-9\\-\\.]+"), + l7 = l6 |> stringr::str_remove(body), + + neck = l7 |> stringr::str_extract("[0-9\\-\\.]+"), + l8 = l7 |> stringr::str_remove(neck), + ) |> + dplyr::select( + step, + # players, + # player, + team, + unum, + # params, + # type, + # state, + x, + y, + vx, + vy, + body, + neck, + ) %>% tidyr::drop_na() + return(player_log) +} -- GitLab From 52b0312f50b68d8911eb4346950a2f7fba553cc6 Mon Sep 17 00:00:00 2001 From: takumiamano Date: Fri, 15 Apr 2022 20:19:06 +0900 Subject: [PATCH 02/14] =?UTF-8?q?[add]=20=E3=83=92=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=83=9E=E3=83=83=E3=83=97=E3=81=A8=E3=82=B5=E3=83=83=E3=82=AB?= =?UTF-8?q?=E3=83=BC=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=81=AE?= =?UTF-8?q?=E6=8F=8F=E5=86=99=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/get_kick_point.R | 20 +++++++++++++ R/make_graphics.R | 75 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 R/get_kick_point.R diff --git a/R/get_kick_point.R b/R/get_kick_point.R new file mode 100644 index 0000000..7eb0283 --- /dev/null +++ b/R/get_kick_point.R @@ -0,0 +1,20 @@ +get_kick_point <- function(log_data) { + output <- log_data |> + dplyr::filter(command=="kick") |> + dplyr::mutate( + x = args |> stringr::str_extract("[0-9\\-\\.]+"), + l1 = args |> stringr::str_remove(x), + y = l1 |> stringr::str_extract("[0-9\\-\\.]+"), + + ) |> + dplyr::select( + step, + team, + unum, + command, + x, + y, + ) + + return(output) +} diff --git a/R/make_graphics.R b/R/make_graphics.R index 36d7aee..7aa0277 100644 --- a/R/make_graphics.R +++ b/R/make_graphics.R @@ -1,17 +1,70 @@ -make_graph <- function(p_data,teamname,num){ - p <- ggplot(data = p_data %>% filter(team==teamname,unum==num), aes(x = as.numeric(x), y = as.numeric(y))) + - ggplot2::coord_fixed(xlim=c(-55,55),ylim =c(-35,35))+ - geom_hline(yintercept = -34.1, linetype = "solid")+ - geom_hline(yintercept = 34.1, linetype = "solid")+ +DEFAULT_MAX_PLAYER <- 11 +DEFAULT_PITCH_LENGTH <- 105.0 +DEFAULT_PITCH_WIDTH <- 70.0 +DEFAULT_PITCH_MARGIN <- 5.0 +DEFAULT_CENTER_CIRCLE_R <- 9.15 +DEFAULT_PENALTY_AREA_LENGTH <- 16.5 +DEFAULT_PENALTY_AREA_WIDTH <- 40.32 +DEFAULT_PENALTY_CIRCLE_R <- 9.15 +DEFAULT_PENALTY_SPOT_DIST <- 11.0 +DEFAULT_GOAL_AREA_LENGTH <- 5.5 +DEFAULT_GOAL_AREA_WIDTH <- 18.32 +DEFAULT_GOAL_DEPTH <- 2.44 +# DEFAULT_CORNER_ARC_R <- 1.0 +half_p_l <- DEFAULT_PITCH_LENGTH/2 +half_p_w <- DEFAULT_PITCH_WIDTH/2 +penalty_x <- half_p_l - DEFAULT_PENALTY_AREA_LENGTH +penalty_y <- DEFAULT_PENALTY_AREA_WIDTH/2 +goal_x <- half_p_l - DEFAULT_GOAL_AREA_LENGTH +goal_y <- DEFAULT_GOAL_AREA_WIDTH/2 + + + +make_field <- function(input_graph){ + p <- input_graph + + geom_hline(yintercept = 0, linetype = "solid")+ - geom_vline(xintercept = 52.6, linetype = "solid")+ - geom_vline(xintercept = -52.6, linetype = "solid")+ geom_vline(xintercept = 0, linetype = "solid")+ + geom_linerange(aes(x=half_p_l, y=NULL, ymin=-half_p_w, ymax=half_p_w))+ + geom_linerange(aes(x=-half_p_l, y=NULL, ymin=-half_p_w, ymax=half_p_w))+ + geom_linerange(aes(x=NULL, y=half_p_w, xmin=-half_p_l, xmax=half_p_l))+ + geom_linerange(aes(x=NULL, y=-half_p_w, xmin=-half_p_l, xmax=half_p_l))+ + geom_point(size=0.1) + - geom_density_2d_filled(alpha = 0.7) + geom_linerange(aes(x=penalty_x, y=NULL, ymin=-penalty_y, ymax=penalty_y))+ + geom_linerange(aes(x=-penalty_x, y=NULL, ymin=-penalty_y, ymax=penalty_y))+ + geom_linerange(aes(x=NULL, y=penalty_y, xmin=penalty_x, xmax=half_p_l))+ + geom_linerange(aes(x=NULL, y=-penalty_y, xmin=penalty_x, xmax=half_p_l))+ + geom_linerange(aes(x=NULL, y=penalty_y, xmax=-penalty_x, xmin=-half_p_l))+ + geom_linerange(aes(x=NULL, y=-penalty_y, xmax=-penalty_x, xmin=-half_p_l))+ + + geom_linerange(aes(x=goal_x, y=NULL, ymin=-goal_y, ymax=goal_y))+ + geom_linerange(aes(x=-goal_x, y=NULL, ymin=-goal_y, ymax=goal_y))+ + geom_linerange(aes(x=NULL, y=goal_y, xmax=goal_x, xmin=half_p_l))+ + geom_linerange(aes(x=NULL, y=-goal_y, xmax=goal_x, xmin=half_p_l))+ + geom_linerange(aes(x=NULL, y=goal_y, xmin=-goal_x, xmax=-half_p_l))+ + geom_linerange(aes(x=NULL, y=-goal_y, xmin=-goal_x, xmax=-half_p_l))+ + + ggforce::geom_circle(aes(x0 = 0, y0 = 0, r = DEFAULT_CENTER_CIRCLE_R),inherit.aes = FALSE) + return(p) +} + +make_heatmap <- function(p_data){ + p <- ggplot(data = p_data, aes(x = as.numeric(x), y = as.numeric(y))) + + ggplot2::coord_fixed(xlim=c(-half_p_l,half_p_l),ylim =c(-half_p_w,half_p_w))+ + geom_density_2d_filled(alpha = 0.5) + + p <- p |> make_field() return(p) } -#ggplot2::geom_path(size=1.2,aes(color = as.numeric(step))) + -# + -# ggplot2::geom_density2d(size = 0.25, colour = "black") \ No newline at end of file +# make_kick_point <- function(p_data,input_graph){ +# log_data <- p_data + +# p <- input_graph + +# geom_point(data = p_data,aes(x = as.numeric(x), y = as.numeric(y))) + + +# return(p) +# } + -- GitLab From de8a994fc61266584513de73ae22e570c2547d17 Mon Sep 17 00:00:00 2001 From: takumiamano Date: Fri, 23 Sep 2022 22:46:07 +0900 Subject: [PATCH 03/14] =?UTF-8?q?[fix]stime=E3=81=8C=E8=AA=AD=E3=81=BF?= =?UTF-8?q?=E8=BE=BC=E3=81=BE=E3=82=8C=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=80=81=E6=AD=A3=E7=A2=BA=E3=81=AA=E9=81=B8?= =?UTF-8?q?=E6=89=8B=E3=81=AE=E4=BD=8D=E7=BD=AE=E3=81=8C=E5=8F=96=E5=BE=97?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=AE?= =?UTF-8?q?=E3=81=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/get_kick_point.R | 109 ---------------- R/make_data.R | 293 ++++++++++++++++++++++++++++++++++---------- R/make_soccer_map.R | 104 ++++++++++++++++ R/read_rcg.R | 2 +- 4 files changed, 333 insertions(+), 175 deletions(-) delete mode 100644 R/get_kick_point.R create mode 100644 R/make_soccer_map.R diff --git a/R/get_kick_point.R b/R/get_kick_point.R deleted file mode 100644 index afd8d67..0000000 --- a/R/get_kick_point.R +++ /dev/null @@ -1,109 +0,0 @@ -get_kick_point <- function(rcl) { - output <- rcl |> - dplyr::filter(command=="kick") |> - dplyr::mutate( - x = args |> stringr::str_extract("[0-9\\-\\.]+"), - l1 = args |> stringr::str_remove(x), - y = l1 |> stringr::str_extract("[0-9\\-\\.]+"), - unum = as.numeric(unum) - ) |> - dplyr::select( - step, - team, - unum, - command, - x, - y, - ) - - return(output) -} - -read_referee <- function(path_rcl) { - referee <- path_rcl |> - readr::read_lines() |> - tibble::as_tibble() |> - dplyr::mutate( - step = value |> stringr::str_extract("\\d+"), - command = value |> - stringr::str_extract("referee [a-zA-Z0-9_]*")|> - stringr::str_remove("referee "), - step = as.numeric(step), - ) |> - dplyr::select( - step, - command, - ) %>% tidyr::drop_na() - - - return(referee) -} - -read_goal <- function(referee,name){ - goal <- referee |> - dplyr::filter(stringr::str_detect(command, "goal_[rl]_[0-9]+")) |> - dplyr::mutate( - side = command |> - stringr::str_remove("goal_") |> - stringr::str_extract("[rl]"), - score = command |> - stringr::str_remove("goal_[rl]_") |> - stringr::str_extract("[0-9]+") , - ) |> - dplyr::inner_join(name,by="side") |> - dplyr::select( - step, - name, - score, - ) %>% tidyr::drop_na() - - return(goal) -} - -before_goal <- function(kick_log,goal_step,goal_team){ - - playlist <- kick_log %>% - dplyr::arrange(desc(step)) %>% - dplyr::filter( - step > goal_step -100, - step < goal_step, - team == goal_team, - ) -} - -get_goal_playlist <- function(kick_log,goal){ - if(length(goal$step)<1){ - return(NA) - } - i <- 1 - output <- before_goal(kick_log,goal$step[i],goal$name[i]) - i<- i+1 - while(i <= length(goal$step)){ - # print(i) - i_list <- before_goal(kick_log,goal$step[i],goal$name[i]) - output <- output |> bind_rows(i_list) - i<- i+1 - } - # for(i in goal$step){ - # i_list <- before_goal(kick_log,goal$step[i],goal$name[i]) - # output <- output |> bind_rows(i_list) - # print(i) - # } - return(output) -} - -convert_ball_acg_and_rcl <- function(rcg,rcl){ - output <- dplyr::inner_join(rcg,rcl,by="step") - return(output) -} - -get_dribble_point <- function(log_data){ - output <- log_data %>% filter(dribble==TRUE,pass==FALSE) - return(output) -} - -get_pass_point <- function(log_data){ - output <- log_data %>% filter(pass==TRUE) - return(output) -} - diff --git a/R/make_data.R b/R/make_data.R index a676f12..5d580c2 100644 --- a/R/make_data.R +++ b/R/make_data.R @@ -1,17 +1,225 @@ -source("~/soccer2D/socceR/R/read_old_rcg.R") -source("~/soccer2D/socceR/R/read_rcl.R") -source("~/soccer2D/socceR/R/read_rcg.R") +get_player <- function(rcg, name) { + output <- rcg |> + dplyr::inner_join(name, by = "side") |> + dplyr::filter(is.na(stime)) |> + dplyr::select( + step, + team = name, + unum, + px = x, + py = y, + pvx = vx, + pvy = vy, + body, + neck, + ) + + return(output) +} + +get_action <- function(rcl, ball, players) { + output <- rcl |> + dplyr::filter(command == "kick" | command == "tackle") |> + dplyr::mutate( + x = args |> stringr::str_extract("[0-9\\-\\.]+"), + l1 = args |> stringr::str_remove(x), + y = l1 |> stringr::str_extract("[0-9\\-\\.]+"), + unum = as.numeric(unum) + ) |> + dplyr::select( + step, + team, + unum, + command, + ax = x, + ay = y, + ) |> + dplyr::inner_join(ball, by = "step") %>% + dplyr::inner_join(players, by = c("step", "team", "unum")) %>% + dplyr::mutate(after_team = lead(team)) %>% + dplyr::mutate(a_sameteam = (after_team == team)) %>% + dplyr::mutate(tackle_scc = (command == "tackle" & a_sameteam)) %>% + dplyr::mutate(a_tackle_scc = lead(tackle_scc)) %>% + dplyr::select(-c(after_team, a_sameteam)) + + return(output) +} + +get_tackle <- function(action) { + output <- action %>% + dplyr::filter(command == "tackle") %>% + dplyr::select(-c(a_tackle_scc, ax, ay)) + return(output) +} + +# get_kick <- function(action) { +# output <- action %>% +# dplyr::filter(command == "kick") %>% +# dplyr::mutate(before_team = lag(team)) %>% +# dplyr::mutate(before_unum = lag(unum)) %>% +# dplyr::mutate(after_team = lead(team)) %>% +# dplyr::mutate(after_unum = lead(unum)) %>% +# dplyr::mutate(b_sameteam = (before_team == team)) %>% +# dplyr::mutate(b_sameunum = (before_unum == unum)) %>% +# dplyr::mutate(a_sameteam = (after_team == team)) %>% +# dplyr::mutate(a_sameunum = (after_unum == unum)) + + +# output$b_sameteam[1] <- TRUE +# output$b_sameunum[1] <- FALSE + +# output <- output %>% +# dplyr::mutate(dribble = (a_sameteam & a_sameunum)) %>% +# dplyr::mutate(pass = (a_sameteam & !a_sameunum)) %>% +# group_by(grc = cumsum(!dribble)) %>% +# mutate(touch = row_number()) %>% +# ungroup() %>% +# select(-c(tackle_scc, grc, before_team, before_unum, b_sameteam, b_sameunum, after_team, after_unum, a_sameteam, a_sameunum)) +# return(output) +# } + +get_kick <- function(action) { + output <- action %>% + dplyr::filter(command == "kick") %>% + dplyr::mutate(after_team = lead(team)) %>% + dplyr::mutate(after_unum = lead(unum)) %>% + dplyr::mutate(a_sameteam = (after_team == team)) %>% + dplyr::mutate(a_sameunum = (after_unum == unum)) %>% + select(-c(command, ax, ay, ball_vx, ball_vy, pvx, pvy, body, neck)) + + + return(output) +} + +get_pass <- function(kick) { + output <- kick %>% + dplyr::mutate(pass_scc = (a_sameteam & !a_sameunum)) %>% + dplyr::mutate(pass = ((a_sameteam & !a_sameunum) | (!a_tackle_scc & !a_sameteam))) %>% + dplyr::filter(pass) %>% + select(-c(a_tackle_scc,tackle_scc, pass, a_sameteam, a_sameunum, after_team, after_unum)) + + + return(output) +} + +get_dribble <- function(kick) { + output <- kick %>% + dplyr::mutate(dribble = ((!a_sameteam & a_tackle_scc) | (a_sameteam & a_sameunum))) %>% + dplyr::mutate(dribble_scc = (a_sameteam & a_sameunum)) %>% + group_by(grc = cumsum(!dribble)) %>% + mutate(touch = row_number()) %>% + ungroup() %>% + dplyr::filter(dribble) %>% + select(-c(a_tackle_scc,tackle_scc, dribble, a_sameteam, a_sameunum, after_team, after_unum, dribble, grc)) + + return(output) +} + +read_referee <- function(path_rcl) { + referee <- path_rcl |> + readr::read_lines() |> + tibble::as_tibble() |> + dplyr::mutate( + step = value |> stringr::str_extract("\\d+"), + command = value |> + stringr::str_extract("referee [a-zA-Z0-9_]*") |> + stringr::str_remove("referee "), + step = as.numeric(step), + ) |> + dplyr::select( + step, + command, + ) %>% + tidyr::drop_na() + + + return(referee) +} + +read_goal <- function(referee, name) { + goal <- referee |> + dplyr::filter(stringr::str_detect(command, "goal_[rl]_[0-9]+")) |> + dplyr::mutate( + side = command |> + stringr::str_remove("goal_") |> + stringr::str_extract("[rl]"), + score = command |> + stringr::str_remove("goal_[rl]_") |> + stringr::str_extract("[0-9]+"), + ) |> + dplyr::inner_join(name, by = "side") |> + dplyr::select( + step, + side, + name, + score, + ) %>% + tidyr::drop_na() + + return(goal) +} + +before_goal <- function(kick_log, goal_step, goal_team) { + playlist <- kick_log %>% + dplyr::arrange(desc(step)) %>% + dplyr::filter( + step > goal_step - 100, + step < goal_step, + team == goal_team, + ) +} + +get_goal_playlist <- function(kick_log, goal) { + if (length(goal$step) < 1) { + return(NA) + } + i <- 1 + output <- before_goal(kick_log, goal$step[i], goal$name[i]) + i <- i + 1 + while (i <= length(goal$step)) { + # print(i) + i_list <- before_goal(kick_log, goal$step[i], goal$name[i]) + output <- output |> bind_rows(i_list) + i <- i + 1 + } + # for(i in goal$step){ + # i_list <- before_goal(kick_log,goal$step[i],goal$name[i]) + # output <- output |> bind_rows(i_list) + # print(i) + # } + return(output) +} + +convert_by_step <- function(rcg, rcl) { + output <- dplyr::inner_join(rcg, rcl, by = "step") + return(output) +} + +get_dribble_point <- function(log_data) { + output <- log_data %>% filter(dribble == TRUE, pass == FALSE) + return(output) +} -get_rcl <- function(path_rcl){ +get_pass_point <- function(log_data) { + output <- log_data %>% filter(pass == TRUE) + return(output) +} + +get_tackle_point <- function(log_data) { + output <- log_data %>% filter(tackle == TRUE) + return(output) +} + +get_rcl <- function(path_rcl) { output <- path_rcl |> read_rcl() return(output) } -get_name <- function(path_rcg){ +get_name <- function(path_rcg) { team_name <- path_rcg |> - stringr::str_extract("[a-zA-Z0-9_-]*.rcg") |> + stringr::str_extract("[a-zA-Z0-9_-]*.rcg") |> stringr::str_remove("[0-9]*-") |> - stringr::str_remove(".rcl") + stringr::str_remove(".rcl") l_team <- team_name |> stringr::str_extract("[a-zA-Z0-9_]*-vs-") |> stringr::str_remove("_[0-9]*-vs-") @@ -21,73 +229,28 @@ get_name <- function(path_rcg){ name_table <- tibble::tribble( ~side, ~name, "l", l_team, - "r",r_team, + "r", r_team, ) return(name_table) } -replase_rcg_to_rcl <- function(path_rcg){ - output <- path_rcg |> stringr::str_replace(pattern=".rcg", replacement=".rcl") -} -replase_rcl_to_rcg <- function(path_rcl){ - output <- path_rcl |> stringr::str_replace(pattern=".rcl", replacement=".rcg") +replase_rcg_to_rcl <- function(path_rcg) { + output <- path_rcg |> stringr::str_replace(pattern = ".rcg", replacement = ".rcl") } - -get_player <- function(rcg,name){ - output <- rcg |> - dplyr::inner_join(name,by="side") |> - dplyr::select( - step, - team = name, - unum, - x, - y, - vx, - vy, - body, - neck, - ) - return(output) +replase_rcl_to_rcg <- function(path_rcl) { + output <- path_rcl |> stringr::str_replace(pattern = ".rcl", replacement = ".rcg") } -get_kick <- function(rcl,ball){ - output <- rcl |> - get_kick_point() |> - convert_ball_rcg_and_rcl(ball) - - output <- output %>% - dplyr::mutate(before_team=lag(team)) %>% - dplyr::mutate(before_unum=lag(unum)) %>% - dplyr::mutate(after_team=lead(team)) %>% - dplyr::mutate(after_unum=lead(unum)) %>% - dplyr::mutate(b_sameteam=(before_team==team)) %>% - dplyr::mutate(b_sameunum=(before_unum==unum)) %>% - dplyr::mutate(a_sameteam=(after_team==team)) %>% - dplyr::mutate(a_sameunum=(after_unum==unum)) - - - output$b_sameteam[1] <- TRUE - output$b_sameunum[1] <- FALSE - - output <- output %>% - dplyr::mutate(dribble=(b_sameteam & b_sameunum)) %>% - dplyr::mutate(pass=(a_sameteam & !a_sameunum)) %>% - dplyr::mutate(tackle=(!b_sameteam))%>% - group_by(grc = cumsum(!dribble)) %>% - mutate(touch = row_number()) %>% - ungroup() %>% - select(-c(grc,before_team,before_unum,b_sameteam,b_sameunum,after_team,after_unum,a_sameteam,a_sameunum)) - return(output) -} -kick_dist <- function(rcg){ +kick_dist <- function(rcg) { ball_path <- rcg |> dplyr::group_nest(step, ball_x, ball_y) |> - dplyr::mutate(move_dist_x = ball_x - dplyr::lag(ball_x), - move_dist_y = ball_y - dplyr::lag(ball_y), - move_dist = sqrt(move_dist_x^2 + move_dist_y^2), - move_dist = dplyr::if_else(is.na(move_dist), 0, move_dist) - ) |> + dplyr::mutate( + move_dist_x = ball_x - dplyr::lag(ball_x), + move_dist_y = ball_y - dplyr::lag(ball_y), + move_dist = sqrt(move_dist_x^2 + move_dist_y^2), + move_dist = dplyr::if_else(is.na(move_dist), 0, move_dist) + ) |> dplyr::filter(move_dist != 0 & move_dist < 40) -} \ No newline at end of file +} diff --git a/R/make_soccer_map.R b/R/make_soccer_map.R new file mode 100644 index 0000000..eff96c1 --- /dev/null +++ b/R/make_soccer_map.R @@ -0,0 +1,104 @@ +make_soccer_map_pp <- function(rcg) { + soocer_field = c(6000,104,68) + names(soocer_field) = c("time","length","width") + soccer_map <- array(0, dim = c(6000,13,104,68)) + + for(i in seq_along(rcg)){ + # SP - (x,y) location 1 on attacking players’ location (x,y) + px <- round(rcg$x[i])+soocer_field["length"]/2 + py <- round(rcg$y[i])+soocer_field["width"]/2 + bx <- round(rcg$ball_x[i])+soocer_field["length"]/2 + by <- round(rcg$ball_y[i])+soocer_field["width"]/2 + step <- rcg$step[i] + if(rcg$side[i]=="l"){ + soccer_map[step,1,px,py] = rcg$unum[i] + soccer_map[step,3,px,py] = rcg$vx[i] + soccer_map[step,4,px,py] = rcg$vy[i] + }else if (rcg$side[i]=="r"){ + soccer_map[step,2,px,py] = rcg$unum[i] + soccer_map[step,5,px,py] = rcg$vx[i] + soccer_map[step,6,px,py] = rcg$vy[i] + } + soccer_map[step,7,px,py] = atan(py/(soocer_field["length"]/2 - px)) + dist_p_b = sqrt((bx-px)^2+(by-py)^2) + dist_p_g = sqrt(((soocer_field["length"]/2)-px)^2+(py)^2) + + soccer_map[step,8,px,py] = (py-by) / dist_p_b + soccer_map[step,9,px,py] = (px-bx) / dist_p_b + soccer_map[step,10,px,py] = py / dist_p_g + soccer_map[step,11,px,py] = px / dist_p_g + soccer_map[step,12,px,py] = dist_p_b + soccer_map[step,13,px,py] = dist_p_g + } + return(soccer_map) +} + +make_soccer_map_ps <- function(rcg) { + soocer_field = c(6000,104,68) + names(soocer_field) = c("time","length","width") + soccer_map <- array(0, dim = c(6000,13,104,68)) + + for(i in seq_along(rcg)){ + # SP - (x,y) location 1 on attacking players’ location (x,y) + px <- round(rcg$x[i])+soocer_field["length"]/2 + py <- round(rcg$y[i])+soocer_field["width"]/2 + bx <- round(rcg$ball_x[i])+soocer_field["length"]/2 + by <- round(rcg$ball_y[i])+soocer_field["width"]/2 + step <- rcg$step[i] + if(rcg$side[i]=="l"){ + soccer_map[step,1,px,py] = rcg$unum[i] + soccer_map[step,3,px,py] = rcg$vx[i] + soccer_map[step,4,px,py] = rcg$vy[i] + }else if (rcg$side[i]=="r"){ + soccer_map[step,2,px,py] = rcg$unum[i] + soccer_map[step,5,px,py] = rcg$vx[i] + soccer_map[step,6,px,py] = rcg$vy[i] + } + soccer_map[step,7,px,py] = atan(py/(soocer_field["length"]/2 - px)) + dist_p_b = sqrt((bx-px)^2+(by-py)^2) + dist_p_g = sqrt(((soocer_field["length"]/2)-px)^2+(py)^2) + + soccer_map[step,8,px,py] = (py-by) / dist_p_b + soccer_map[step,9,px,py] = (px-bx) / dist_p_b + soccer_map[step,10,px,py] = py / dist_p_g + soccer_map[step,11,px,py] = px / dist_p_g + soccer_map[step,12,px,py] = dist_p_b + soccer_map[step,13,px,py] = dist_p_g + } + return(soccer_map) +} + +make_soccer_map_pe <- function(rcg) { + soocer_field = c(6000,104,68) + names(soocer_field) = c("time","length","width") + soccer_map <- array(0, dim = c(6000,13,104,68)) + + for(i in seq_along(rcg)){ + # SP - (x,y) location 1 on attacking players’ location (x,y) + px <- round(rcg$x[i])+soocer_field["length"]/2 + py <- round(rcg$y[i])+soocer_field["width"]/2 + bx <- round(rcg$ball_x[i])+soocer_field["length"]/2 + by <- round(rcg$ball_y[i])+soocer_field["width"]/2 + step <- rcg$step[i] + if(rcg$side[i]=="l"){ + soccer_map[step,1,px,py] = rcg$unum[i] + soccer_map[step,3,px,py] = rcg$vx[i] + soccer_map[step,4,px,py] = rcg$vy[i] + }else if (rcg$side[i]=="r"){ + soccer_map[step,2,px,py] = rcg$unum[i] + soccer_map[step,5,px,py] = rcg$vx[i] + soccer_map[step,6,px,py] = rcg$vy[i] + } + soccer_map[step,7,px,py] = atan(py/(soocer_field["length"]/2 - px)) + dist_p_b = sqrt((bx-px)^2+(by-py)^2) + dist_p_g = sqrt(((soocer_field["length"]/2)-px)^2+(py)^2) + + soccer_map[step,8,px,py] = (py-by) / dist_p_b + soccer_map[step,9,px,py] = (px-bx) / dist_p_b + soccer_map[step,10,px,py] = py / dist_p_g + soccer_map[step,11,px,py] = px / dist_p_g + soccer_map[step,12,px,py] = dist_p_b + soccer_map[step,13,px,py] = dist_p_g + } + return(soccer_map) +} \ No newline at end of file diff --git a/R/read_rcg.R b/R/read_rcg.R index 983de71..b688498 100644 --- a/R/read_rcg.R +++ b/R/read_rcg.R @@ -10,7 +10,7 @@ read_rcg <- function(path) { jsonlite::parse_json(simplifyVector = TRUE, flatten = TRUE) |> tibble::as_tibble() |> dplyr::filter(type == "show") |> - dplyr::select(time, players, ball.x, ball.y, ball.vx, ball.vy) |> + dplyr::select(time,stime,players, ball.x, ball.y, ball.vx, ball.vy) |> tidyr::unnest(players) |> dplyr::select(time:capacity, ball.x:ball.vy) |> dplyr::rename(step = time) |> -- GitLab From 97256ee1c520271135f2a143c48ff7c5d0e51098 Mon Sep 17 00:00:00 2001 From: takumiamano Date: Fri, 23 Sep 2022 23:35:01 +0900 Subject: [PATCH 04/14] =?UTF-8?q?[fix]get=5Faction=5FAllplayer=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/make_data.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/R/make_data.R b/R/make_data.R index 5d580c2..a51cd9d 100644 --- a/R/make_data.R +++ b/R/make_data.R @@ -91,6 +91,14 @@ get_kick <- function(action) { return(output) } +get_action_Allplayer <- function(players,action){ + players <- players %>% + dplyr::select(-c("px","py")) + output <- players %>% + dplyr::inner_join(action,by = "step") + return(output) +} + get_pass <- function(kick) { output <- kick %>% dplyr::mutate(pass_scc = (a_sameteam & !a_sameunum)) %>% -- GitLab From 98b3253ba7b1966c9035814d3d53d6a58909b00e Mon Sep 17 00:00:00 2001 From: takumiamano Date: Fri, 23 Sep 2022 23:47:57 +0900 Subject: [PATCH 05/14] [fix]get_pass_Allplayer --- R/make_data.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/make_data.R b/R/make_data.R index a51cd9d..d03ba8e 100644 --- a/R/make_data.R +++ b/R/make_data.R @@ -92,8 +92,8 @@ get_kick <- function(action) { } get_action_Allplayer <- function(players,action){ - players <- players %>% - dplyr::select(-c("px","py")) + action <- action %>% + dplyr::select(c("step","ball_x","ball_y","pass_scc")) output <- players %>% dplyr::inner_join(action,by = "step") return(output) -- GitLab From 8979aa480c0a2778d39eb25edc89a8ee24401c4b Mon Sep 17 00:00:00 2001 From: takumiamano Date: Tue, 27 Sep 2022 17:41:21 +0900 Subject: [PATCH 06/14] =?UTF-8?q?[fix]=E3=83=91=E3=82=B9=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=E3=83=81=E3=83=BC=E3=83=A0=E3=80=81=E3=83=89?= =?UTF-8?q?=E3=83=AA=E3=83=96=E3=83=AB=E3=81=97=E3=81=A6=E3=82=8B=E3=83=81?= =?UTF-8?q?=E3=83=BC=E3=83=A0=E3=82=92=E3=82=8F=E3=81=8B=E3=82=8A=E3=82=84?= =?UTF-8?q?=E3=81=99=E3=81=8F=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/make_data.R | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/R/make_data.R b/R/make_data.R index d03ba8e..fcb148b 100644 --- a/R/make_data.R +++ b/R/make_data.R @@ -5,6 +5,7 @@ get_player <- function(rcg, name) { dplyr::select( step, team = name, + side, unum, px = x, py = y, @@ -91,11 +92,19 @@ get_kick <- function(action) { return(output) } -get_action_Allplayer <- function(players,action){ - action <- action %>% - dplyr::select(c("step","ball_x","ball_y","pass_scc")) +get_pass_Allplayer <- function(players,pass){ + pass <- pass %>% + dplyr::select(step,pass_team=team,ball_x,ball_y,pass_scc) + output <- players %>% + dplyr::inner_join(pass,by = "step") + return(output) +} + +get_dribble_Allplayer <- function(players,dribble){ + dribble <- dribble %>% + dplyr::select(step,dribble_team=team,ball_x,ball_y,dribble_scc) output <- players %>% - dplyr::inner_join(action,by = "step") + dplyr::inner_join(dribble,by = "step") return(output) } -- GitLab From 4e3a63e58cd4ea736c3972c1cc824144203c1d67 Mon Sep 17 00:00:00 2001 From: takumiamano Date: Tue, 27 Sep 2022 20:24:35 +0900 Subject: [PATCH 07/14] =?UTF-8?q?[fix]kickall=E4=BD=9C=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/make_data.R | 57 +++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/R/make_data.R b/R/make_data.R index fcb148b..16fd859 100644 --- a/R/make_data.R +++ b/R/make_data.R @@ -53,31 +53,30 @@ get_tackle <- function(action) { return(output) } -# get_kick <- function(action) { -# output <- action %>% -# dplyr::filter(command == "kick") %>% -# dplyr::mutate(before_team = lag(team)) %>% -# dplyr::mutate(before_unum = lag(unum)) %>% -# dplyr::mutate(after_team = lead(team)) %>% -# dplyr::mutate(after_unum = lead(unum)) %>% -# dplyr::mutate(b_sameteam = (before_team == team)) %>% -# dplyr::mutate(b_sameunum = (before_unum == unum)) %>% -# dplyr::mutate(a_sameteam = (after_team == team)) %>% -# dplyr::mutate(a_sameunum = (after_unum == unum)) - - -# output$b_sameteam[1] <- TRUE -# output$b_sameunum[1] <- FALSE - -# output <- output %>% -# dplyr::mutate(dribble = (a_sameteam & a_sameunum)) %>% -# dplyr::mutate(pass = (a_sameteam & !a_sameunum)) %>% -# group_by(grc = cumsum(!dribble)) %>% -# mutate(touch = row_number()) %>% -# ungroup() %>% -# select(-c(tackle_scc, grc, before_team, before_unum, b_sameteam, b_sameunum, after_team, after_unum, a_sameteam, a_sameunum)) -# return(output) -# } +get_kick_log <- function(action) { + output <- action %>% + dplyr::filter(command == "kick") %>% + dplyr::mutate(before_team = lag(team)) %>% + dplyr::mutate(before_unum = lag(unum)) %>% + dplyr::mutate(after_team = lead(team)) %>% + dplyr::mutate(after_unum = lead(unum)) %>% + dplyr::mutate(b_sameteam = (before_team == team)) %>% + dplyr::mutate(b_sameunum = (before_unum == unum)) %>% + dplyr::mutate(a_sameteam = (after_team == team)) %>% + dplyr::mutate(a_sameunum = (after_unum == unum)) + + output$b_sameteam[1] <- TRUE + output$b_sameunum[1] <- FALSE + + output <- output %>% + dplyr::mutate(dribble = (a_sameteam & a_sameunum)) %>% + dplyr::mutate(pass = (a_sameteam & !a_sameunum)) %>% + group_by(grc = cumsum(!dribble)) %>% + mutate(touch = row_number()) %>% + ungroup() %>% + select(-c(tackle_scc, grc, before_team, before_unum, b_sameteam, b_sameunum, after_team, after_unum, a_sameteam, a_sameunum)) + return(output) +} get_kick <- function(action) { output <- action %>% @@ -92,6 +91,14 @@ get_kick <- function(action) { return(output) } +get_action_Allplayer <- function(players,action){ + action <- action %>% + dplyr::select(step,action_team=team,ball_x,ball_y,pass,dribble) + output <- players %>% + dplyr::inner_join(action,by = "step") + return(output) +} + get_pass_Allplayer <- function(players,pass){ pass <- pass %>% dplyr::select(step,pass_team=team,ball_x,ball_y,pass_scc) -- GitLab From 085740a4f2f080cc6ed0589525fc6051e7d966e6 Mon Sep 17 00:00:00 2001 From: takumiamano Date: Wed, 28 Sep 2022 18:54:30 +0900 Subject: [PATCH 08/14] =?UTF-8?q?[fix]=E3=83=91=E3=82=B9=E3=81=AE=E7=9B=AE?= =?UTF-8?q?=E6=A8=99=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/make_data.R | 55 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/R/make_data.R b/R/make_data.R index 16fd859..ec8d9df 100644 --- a/R/make_data.R +++ b/R/make_data.R @@ -53,6 +53,8 @@ get_tackle <- function(action) { return(output) } + + get_kick_log <- function(action) { output <- action %>% dplyr::filter(command == "kick") %>% @@ -85,7 +87,7 @@ get_kick <- function(action) { dplyr::mutate(after_unum = lead(unum)) %>% dplyr::mutate(a_sameteam = (after_team == team)) %>% dplyr::mutate(a_sameunum = (after_unum == unum)) %>% - select(-c(command, ax, ay, ball_vx, ball_vy, pvx, pvy, body, neck)) + select(-c(command, pvx, pvy, body, neck)) return(output) @@ -101,7 +103,7 @@ get_action_Allplayer <- function(players,action){ get_pass_Allplayer <- function(players,pass){ pass <- pass %>% - dplyr::select(step,pass_team=team,ball_x,ball_y,pass_scc) + dplyr::select(step,ax,ay,pass_team=team,ball_x,ball_y,pass_scc) output <- players %>% dplyr::inner_join(pass,by = "step") return(output) @@ -120,12 +122,16 @@ get_pass <- function(kick) { dplyr::mutate(pass_scc = (a_sameteam & !a_sameunum)) %>% dplyr::mutate(pass = ((a_sameteam & !a_sameunum) | (!a_tackle_scc & !a_sameteam))) %>% dplyr::filter(pass) %>% - select(-c(a_tackle_scc,tackle_scc, pass, a_sameteam, a_sameunum, after_team, after_unum)) - + select(-c(a_tackle_scc,tackle_scc, pass, a_sameteam, a_sameunum, after_team, after_unum)) %>% + dplyr::mutate(next_ball_x = lead(ball_x)) %>% + dplyr::mutate(next_ball_y = lead(ball_y)) return(output) } + + + get_dribble <- function(kick) { output <- kick %>% dplyr::mutate(dribble = ((!a_sameteam & a_tackle_scc) | (a_sameteam & a_sameunum))) %>% @@ -278,3 +284,44 @@ kick_dist <- function(rcg) { ) |> dplyr::filter(move_dist != 0 & move_dist < 40) } + +select_name <- function(data,name){ + output <- data %>% + dplyr::filter(team==name) + return(output) +} + +get_AttackLine <- function(data){ + output <- data %>% + dplyr::group_by(step) %>% + filter(px == max(px)) %>% + dplyr::select(step,AL=px) + return(output) +} + +get_DefendLine <- function(data){ + output <- data %>% + dplyr::group_by(step) %>% + filter(px == min(px)) %>% + dplyr::select(step,DL=px) + return(output) +} + +get_MedianLine <- function(data){ + output <- data %>% + dplyr::group_by(step) %>% + dplyr::summarize(ML=median(px)) %>% + dplyr::select(step,ML) + return(output) +} + +get_DynamicPressureLine <- function(data){ + data <- data %>% + filter(unum > 1) + ad <- get_AttackLine(data) + dd <- get_DefendLine(data) + md <- get_MedianLine(data) + output <- dplyr::inner_join(ad,dd,by = "step") + output <- dplyr::inner_join(output,md,by = "step") + return(output) +} \ No newline at end of file -- GitLab From b81373afcda95f14b933361e8365a1ec602aa8d1 Mon Sep 17 00:00:00 2001 From: takumiamano Date: Wed, 28 Sep 2022 19:01:34 +0900 Subject: [PATCH 09/14] =?UTF-8?q?[fix]=E3=82=AD=E3=83=83=E3=82=AF=E5=BE=8C?= =?UTF-8?q?=E3=81=AE=E3=83=9C=E3=83=BC=E3=83=AB=E3=81=AE=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E3=82=92=E5=8F=82=E7=85=A7=E3=81=A7=E3=81=8D=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/make_data.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/make_data.R b/R/make_data.R index ec8d9df..8643aab 100644 --- a/R/make_data.R +++ b/R/make_data.R @@ -87,7 +87,9 @@ get_kick <- function(action) { dplyr::mutate(after_unum = lead(unum)) %>% dplyr::mutate(a_sameteam = (after_team == team)) %>% dplyr::mutate(a_sameunum = (after_unum == unum)) %>% - select(-c(command, pvx, pvy, body, neck)) + select(-c(command, pvx, pvy, body, neck)) %>% + dplyr::mutate(next_ball_x = lead(ball_x)) %>% + dplyr::mutate(next_ball_y = lead(ball_y)) return(output) @@ -122,9 +124,7 @@ get_pass <- function(kick) { dplyr::mutate(pass_scc = (a_sameteam & !a_sameunum)) %>% dplyr::mutate(pass = ((a_sameteam & !a_sameunum) | (!a_tackle_scc & !a_sameteam))) %>% dplyr::filter(pass) %>% - select(-c(a_tackle_scc,tackle_scc, pass, a_sameteam, a_sameunum, after_team, after_unum)) %>% - dplyr::mutate(next_ball_x = lead(ball_x)) %>% - dplyr::mutate(next_ball_y = lead(ball_y)) + select(-c(a_tackle_scc,tackle_scc, pass, a_sameteam, a_sameunum, after_team, after_unum)) return(output) } -- GitLab From c4caf1f068a70b8039889c9c39667f748c6b18a1 Mon Sep 17 00:00:00 2001 From: takumiamano Date: Wed, 19 Oct 2022 19:41:30 +0900 Subject: [PATCH 10/14] =?UTF-8?q?[fix]=E3=83=9C=E3=83=BC=E3=83=AB=E3=81=AE?= =?UTF-8?q?=E5=8A=A0=E9=80=9F=E5=BA=A6=E3=81=8C=E5=8F=82=E7=85=A7=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=81=8F=E3=81=AA=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/make_data.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/make_data.R b/R/make_data.R index 8643aab..0c88d6c 100644 --- a/R/make_data.R +++ b/R/make_data.R @@ -105,7 +105,7 @@ get_action_Allplayer <- function(players,action){ get_pass_Allplayer <- function(players,pass){ pass <- pass %>% - dplyr::select(step,ax,ay,pass_team=team,ball_x,ball_y,pass_scc) + dplyr::select(step,ax,ay,pass_team=team,ball_x,ball_y,ball_vx,ball_vy,pass_scc) output <- players %>% dplyr::inner_join(pass,by = "step") return(output) -- GitLab From 32ba2199ed677f52adad9aa19cdf9f54a4d41e58 Mon Sep 17 00:00:00 2001 From: takumiamano Date: Thu, 27 Oct 2022 18:02:26 +0900 Subject: [PATCH 11/14] =?UTF-8?q?[fix]=20dpl=E3=81=A7=E3=83=91=E3=82=B9?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=83=81=E3=83=BC=E3=83=A0=E3=81=A8=E6=88=90?= =?UTF-8?q?=E5=90=A6=E3=81=8C=E5=88=86=E3=81=8B=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/make_data.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) mode change 100644 => 100755 R/make_data.R diff --git a/R/make_data.R b/R/make_data.R old mode 100644 new mode 100755 index 0c88d6c..ce00a66 --- a/R/make_data.R +++ b/R/make_data.R @@ -295,7 +295,12 @@ get_AttackLine <- function(data){ output <- data %>% dplyr::group_by(step) %>% filter(px == max(px)) %>% - dplyr::select(step,AL=px) + dplyr::select( + step, + pass_team, + pass_scc, + AL=px + ) return(output) } -- GitLab From d5600352e30d7b7f246bac0b916eddbd1abd1277 Mon Sep 17 00:00:00 2001 From: takumiamano Date: Thu, 27 Oct 2022 19:35:38 +0900 Subject: [PATCH 12/14] =?UTF-8?q?[fix]pass=E3=81=A7step=E3=81=8C=E9=87=8D?= =?UTF-8?q?=E8=A4=87=E3=81=99=E3=82=8B=E3=82=82=E3=81=AE=E3=81=AF1?= =?UTF-8?q?=E3=81=A4=E3=81=A0=E3=81=91=E6=AE=8B=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/make_data.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/make_data.R b/R/make_data.R index ce00a66..aaba9a0 100755 --- a/R/make_data.R +++ b/R/make_data.R @@ -124,6 +124,7 @@ get_pass <- function(kick) { dplyr::mutate(pass_scc = (a_sameteam & !a_sameunum)) %>% dplyr::mutate(pass = ((a_sameteam & !a_sameunum) | (!a_tackle_scc & !a_sameteam))) %>% dplyr::filter(pass) %>% + distinct(step,.keep_all=TRUE) %>% select(-c(a_tackle_scc,tackle_scc, pass, a_sameteam, a_sameunum, after_team, after_unum)) return(output) @@ -287,7 +288,7 @@ kick_dist <- function(rcg) { select_name <- function(data,name){ output <- data %>% - dplyr::filter(team==name) + dplyr::filter(team %in% name) return(output) } @@ -297,8 +298,6 @@ get_AttackLine <- function(data){ filter(px == max(px)) %>% dplyr::select( step, - pass_team, - pass_scc, AL=px ) return(output) @@ -322,11 +321,12 @@ get_MedianLine <- function(data){ get_DynamicPressureLine <- function(data){ data <- data %>% - filter(unum > 1) + filter(unum != 1) ad <- get_AttackLine(data) dd <- get_DefendLine(data) md <- get_MedianLine(data) - output <- dplyr::inner_join(ad,dd,by = "step") - output <- dplyr::inner_join(output,md,by = "step") + output <- dplyr::inner_join(ad,dd,by = "step") %>% + dplyr::inner_join(md,by = "step") %>% + distinct(step,.keep_all=TRUE) return(output) } \ No newline at end of file -- GitLab From 4452e7e23b43fd0003e746f1d4c235ed4d9a886e Mon Sep 17 00:00:00 2001 From: takumiamano Date: Thu, 27 Oct 2022 19:39:25 +0900 Subject: [PATCH 13/14] a --- R/make_data.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/make_data.R b/R/make_data.R index aaba9a0..f55e28a 100755 --- a/R/make_data.R +++ b/R/make_data.R @@ -298,6 +298,8 @@ get_AttackLine <- function(data){ filter(px == max(px)) %>% dplyr::select( step, + pass_team, + pass_scc, AL=px ) return(output) -- GitLab From 20665a732d31f776337ce145306bbc1bb48e5637 Mon Sep 17 00:00:00 2001 From: Keisuke ANDO Date: Tue, 6 Dec 2022 02:38:32 +0000 Subject: [PATCH 14/14] =?UTF-8?q?=E3=82=A2=E3=83=83=E3=83=97=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=83=88=20README.Rmd,=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.Rmd | 81 ++++++++++++++++++++++++++++++++++---- README.md | 112 +++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 166 insertions(+), 27 deletions(-) diff --git a/README.Rmd b/README.Rmd index 55be9d9..ec35891 100644 --- a/README.Rmd +++ b/README.Rmd @@ -3,15 +3,82 @@ title: "socceR" output: github_document --- -### RCLファイルを読む関数ができました --- 使い方 +RoboCup Soccer 2Dの試合分析のためのツール群 + +## 機能 + +### `read_rcl` + +指定されたrclファイルを解析し、tibbleにして返します。 ```{r, message=FALSE, collapse = TRUE} -# tidyverseをインポートする library(tidyverse) - -# 作った関数を読み込む source("R/read_rcl.R") +rcl <- read_rcl("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcl") + +head(rcl) +``` + +### `read_rcg` + +指定されたrcgファイルを解析し、tibbleにして返します。 + +```{r, message=FALSE, collapse = TRUE} +library(tidyverse) +source("R/read_rcg.R") +rcg <- read_rcg("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcg") + +head(rcg) +``` + + +## plotlyを使ったビジュアライゼーションのサンプル + +```{r, message=FALSE, eval=FALSE} +library(plotly) + +ball_path <- rcg |> + dplyr::group_nest(step, ball_x, ball_y) |> + dplyr::mutate(move_dist_x = ball_x - dplyr::lag(ball_x), + move_dist_y = ball_y - dplyr::lag(ball_y), + move_dist = sqrt(move_dist_x^2 + move_dist_y^2), + move_dist = dplyr::if_else(is.na(move_dist), 0, move_dist)) |> + dplyr::filter(move_dist != 0 & move_dist < 40) + +ball_path |> + plotly::plot_ly(showlegend = FALSE) |> + plotly::add_markers( + data = ball_path, + x = ~ball_x, + y = ~ball_y, + z = ~move_dist, + marker = list(color = ~move_dist, + size = 3, + colorscale = "Viridis", + opacity = 0.8, + showscale = FALSE) + ) |> + plotly::add_paths( + data = ball_path |> + dplyr::select(step, ball_x, ball_y, move_dist) |> + dplyr::mutate(base = 0) |> + tidyr::pivot_longer(c(move_dist, base)) |> + dplyr::group_by(step), + x = ~ball_x, + y = ~ball_y, + z = ~value, + color = ~value + ) |> + plotly::hide_colorbar() |> + plotly::layout( + scene = list( + xaxis = list(title = "ボールのX座標"), + yaxis = list(title = "ボールのY座標"), + zaxis = list(title = "ボールの飛距離"), + camera = list(eye = list(x = 0.8, y = -1.8, z = 0.8), + center = list(x = 0.0, y = 0.0, z = -0.2)) + ) + ) -# ファイルを指定するだけ -read_rcl("data/20220304142841-HELIOS_base_1-vs-ThunderLeague_1.rcl") -``` \ No newline at end of file +``` +![plotly-visualization-sample](image/plotly-visualization-sample.png) diff --git a/README.md b/README.md index 1b3b8ab..c785417 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,101 @@ socceR ================ -### RCLファイルを読む関数ができました — 使い方 +RoboCup Soccer 2Dの試合分析のためのツール群 + +## 機能 + +### `read_rcl` + +指定されたrclファイルを解析し、tibbleにして返します。 ``` r -# tidyverseをインポートする library(tidyverse) - -# 作った関数を読み込む source("R/read_rcl.R") +rcl <- read_rcl("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcl") + +head(rcl) +## # A tibble: 6 x 6 +## step team unum command args line +## +## 1 0 HELIOS_base 1 init "0,114\tRecv HELIOS_base_1: (init~ +## 2 0 HELIOS_base 1 version "0,114\tRecv HELIOS_base_1: (init~ +## 3 0 HELIOS_base 1 goalie "0,114\tRecv HELIOS_base_1: (init~ +## 4 0 HELIOS_base 1 synch_see "0,115\tRecv HELIOS_base_1: (sync~ +## 5 0 HELIOS_base 1 ear "0,115\tRecv HELIOS_base_1: (sync~ +## 6 0 HELIOS_base 1 off "0,115\tRecv HELIOS_base_1: (sync~ +``` + +### `read_rcg` + +指定されたrcgファイルを解析し、tibbleにして返します。 + +``` r +library(tidyverse) +source("R/read_rcg.R") +rcg <- read_rcg("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcg") -# ファイルを指定するだけ -read_rcl("data/20220304142841-HELIOS_base_1-vs-ThunderLeague_1.rcl") -## # A tibble: 485,911 x 6 -## step team unum command args line -## -## 1 0 HELIOS_base 1 init "0,19\tRecv HELIOS_base_1: (init~ -## 2 0 HELIOS_base 1 version "0,19\tRecv HELIOS_base_1: (init~ -## 3 0 HELIOS_base 1 goalie "0,19\tRecv HELIOS_base_1: (init~ -## 4 0 HELIOS_base 1 synch_see "0,19\tRecv HELIOS_base_1: (sync~ -## 5 0 HELIOS_base 1 ear "0,19\tRecv HELIOS_base_1: (sync~ -## 6 0 HELIOS_base 1 off "0,19\tRecv HELIOS_base_1: (sync~ -## 7 0 HELIOS_base 1 clang "0,19\tRecv HELIOS_base_1: (sync~ -## 8 0 HELIOS_base 1 ver "0,19\tRecv HELIOS_base_1: (sync~ -## 9 0 HELIOS_base 1 turn "0,20\tRecv HELIOS_base_1: (turn~ -## 10 0 HELIOS_base 1 turn_neck "0,20\tRecv HELIOS_base_1: (turn~ -## # ... with 485,901 more rows +head(rcg) +## # A tibble: 6 x 21 +## step side unum type state x y vx vy body neck vq vw +## +## 1 1 l 1 0 9 -49 0 0 0 54.7 0 h 180 +## 2 1 l 2 17 1 -25 -5 0 0 -118. 0 h 180 +## 3 1 l 3 8 1 -25 5 0 0 108. 0 h 180 +## 4 1 l 4 13 1 -25 -10 0 0 -117. 0 h 180 +## 5 1 l 5 6 1 -25 10 0 0 -174. 0 h 180 +## 6 1 l 6 11 1 -25 0 0 0 114. 0 h 180 +## # ... with 8 more variables: stamina , effort , recovery , +## # capacity , ball_x , ball_y , ball_vx , ball_vy ``` + +## plotlyを使ったビジュアライゼーションのサンプル + +``` r +library(plotly) + +ball_path <- rcg |> + dplyr::group_nest(step, ball_x, ball_y) |> + dplyr::mutate(move_dist_x = ball_x - dplyr::lag(ball_x), + move_dist_y = ball_y - dplyr::lag(ball_y), + move_dist = sqrt(move_dist_x^2 + move_dist_y^2), + move_dist = dplyr::if_else(is.na(move_dist), 0, move_dist)) |> + dplyr::filter(move_dist != 0 & move_dist < 40) + +ball_path |> + plotly::plot_ly(showlegend = FALSE) |> + plotly::add_markers( + data = ball_path, + x = ~ball_x, + y = ~ball_y, + z = ~move_dist, + marker = list(color = ~move_dist, + size = 3, + colorscale = "Viridis", + opacity = 0.8, + showscale = FALSE) + ) |> + plotly::add_paths( + data = ball_path |> + dplyr::select(step, ball_x, ball_y, move_dist) |> + dplyr::mutate(base = 0) |> + tidyr::pivot_longer(c(move_dist, base)) |> + dplyr::group_by(step), + x = ~ball_x, + y = ~ball_y, + z = ~value, + color = ~value + ) |> + plotly::hide_colorbar() |> + plotly::layout( + scene = list( + xaxis = list(title = "ボールのX座標"), + yaxis = list(title = "ボールのY座標"), + zaxis = list(title = "ボールの飛距離"), + camera = list(eye = list(x = 0.8, y = -1.8, z = 0.8), + center = list(x = 0.0, y = 0.0, z = -0.2)) + ) + ) +``` + +![plotly-visualization-sample](image/plotly-visualization-sample.png) -- GitLab