From 9b7e41c4f8345952ea974ba1bc7be90183ad887a Mon Sep 17 00:00:00 2001 From: takumiamano Date: Mon, 19 Dec 2022 16:11:05 +0900 Subject: [PATCH] =?UTF-8?q?[add]=20=E3=82=B7=E3=83=A5=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=81=AB=E9=96=A2=E3=81=99=E3=82=8B=E3=83=87=E3=83=BC=E3=82=BF?= =?UTF-8?q?=E3=81=AE=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/make_data.R | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/R/make_data.R b/R/make_data.R index eb23c12..139fc83 100755 --- a/R/make_data.R +++ b/R/make_data.R @@ -182,6 +182,16 @@ get_dribble_Allplayer <- function(players, dribble) { return(output) } +get_shoot_Allplayer <- function(players, shoot) { + shoot <- shoot %>% + dplyr::select(step,shoot_team = team,ball_x,ball_y,ball_vx,ball_vy,next_ball_x,next_ball_y,next_ball_vx,next_ball_vy,shoot,shoot_scc,ball_goal_dist,ball_goal_angle) + output <- players %>% + dplyr::inner_join(shoot, by = "step") %>% + dplyr::distinct(step,team,unum, .keep_all = TRUE)%>% + dplyr::mutate(ball_player_dist = sqrt((px-ball_x)^2+(py-ball_y)^2)) + return(output) +} + get_pass <- function(kick) { output <- kick |> dplyr::filter(pass == TRUE) %>% @@ -200,6 +210,16 @@ get_dribble <- function(kick) { return(output) } +get_shoot <- function(kick) { + output <- kick %>% + dplyr::filter(shoot == TRUE) %>% + distinct(step, .keep_all = TRUE) %>% + dplyr::select(step,team,unum,px,py,pvx,pvy,ball_x,ball_y,ball_vx,ball_vy,next_ball_x,next_ball_y,next_ball_vx,next_ball_vy,shoot,shoot_scc) %>% + dplyr::mutate(ball_goal_dist = sqrt((54-abs(ball_x))^2+abs((ball_y))^2)) %>% + dplyr::mutate(ball_goal_angle = atan2((54-abs(ball_x)),ball_y)) + return(output) +} + get_dp <- function(dribbleAll){ output <- dribbleAll |> dplyr::mutate(p_speed = sqrt(pvx^2 + pvy^2)) %>% @@ -208,6 +228,49 @@ get_dp <- function(dribbleAll){ return(output) } +get_as <- function(kick){ + output <- kick |> + dplyr::select(step,action_team=team,shoot,dribble,pass) + return(output) +} + +get_goalkeeper_action<- function(actionAll){ + output <- actionAll |> + dplyr::filter(unum == 1) %>% + dplyr::mutate(ball_keeper_dist_x = sqrt((px-ball_x)^2)) %>% + dplyr::mutate(player_goal_dist = sqrt((54-abs(px))^2+abs((py))^2)) %>% + dplyr::mutate(opp_team =(team != shoot_team)) %>% + dplyr::mutate(ball_closer_goal_goalkeeper = opp_team & (ball_goal_dist < player_goal_dist)) + return(output) +} + +get_shoot_epv <- function(players,shoot){ + shootAll <- get_shoot_Allplayer(players,shoot) + goalkeeper <- get_goalkeeper_action(shootAll) |> + dplyr::filter(team != shoot_team) |> + dplyr::select(step,ball_keeper_dist_x,keeper_goal_dist=player_goal_dist,ball_closer_goal_goalkeeper) + opponent_team <- shootAll |> + dplyr::filter(team != shoot_team) %>% + dplyr::mutate(r_post_x = (ball_x + (py - ball_y)*(7-ball_x)/(-54-ball_y))) %>% + dplyr::mutate(l_post_x = (ball_x + (py - ball_y)*(-7-ball_x)/(-54-ball_y))) %>% + dplyr::mutate(triangle_in_player = (px > l_post_x)&(px < r_post_x)) %>% + dplyr::mutate(dist_ball_in_3m = (ball_player_dist < 3)) + opp_triangle_in_player_num <- opponent_team |> + dplyr::filter(triangle_in_player) %>% + dplyr::group_by(step) %>% + dplyr::summarise(triangle_in_player_num=n()) + opp_dist_ball_in_3m_num <- opponent_team |> + dplyr::filter(dist_ball_in_3m) %>% + dplyr::group_by(step) %>% + dplyr::summarise(dist_ball_in_3m_num=n()) + output <- shoot |> + dplyr::left_join(goalkeeper,by = "step") %>% + dplyr::left_join(opp_dist_ball_in_3m_num,by="step") %>% + dplyr::left_join(opp_triangle_in_player_num,by = "step") + + return(output) +} + before_goal <- function(kick_log, goal_step, goal_team) { playlist <- kick_log %>% dplyr::arrange(desc(step)) %>% @@ -287,6 +350,7 @@ get_name <- function(path_rcg) { 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") } @@ -376,6 +440,7 @@ get_DynamicPressureLine_D <- function(dribble) { dplyr::select(step,AL,ML,DL) return(output) } + add_DynamicPressureLine <- function(action_All,name){ action_l <- select_name(action_All,name[1,2]) action_r <- select_name(action_All,name[2,2]) -- GitLab