Commit 4f82b1a0 authored by Takumi Amano's avatar Takumi Amano 💬
Browse files

[add]xg用のデータ生成

parent 9b7e41c4
...@@ -214,12 +214,70 @@ get_shoot <- function(kick) { ...@@ -214,12 +214,70 @@ get_shoot <- function(kick) {
output <- kick %>% output <- kick %>%
dplyr::filter(shoot == TRUE) %>% dplyr::filter(shoot == TRUE) %>%
distinct(step, .keep_all = 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::select(step,team,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_dist = sqrt((54-abs(ball_x))^2+abs((ball_y))^2)) %>%
dplyr::mutate(ball_goal_angle = atan2((54-abs(ball_x)),ball_y)) dplyr::mutate(ball_goal_angle = atan2((54-abs(ball_x)),ball_y))
return(output) return(output)
} }
get_xg <- function(kick){
output <- kick |>
dplyr::filter(shoot == TRUE) %>%
distinct(step, .keep_all = TRUE) %>%
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)) %>%
dplyr::select(step,team,px,py,ball_x,ball_y,ball_goal_dist,ball_goal_angle)
return(output)
}
get_xg_label <- function(kick){
output <- kick |>
dplyr::filter(shoot == TRUE) %>%
distinct(step, .keep_all = TRUE) %>%
dplyr::select(step,team,shoot_scc)
return(output)
}
get_xg_l <- function(kick){
output <- kick |>
dplyr::filter(shoot == TRUE) %>%
dplyr::filter(side == "l") %>%
distinct(step, .keep_all = TRUE) %>%
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)) %>%
dplyr::select(px,py,ball_x,ball_y,ball_goal_dist,ball_goal_angle)
return(output)
}
get_xg_l_label <- function(kick){
output <- kick |>
dplyr::filter(shoot == TRUE) %>%
dplyr::filter(side == "l") %>%
distinct(step, .keep_all = TRUE) %>%
dplyr::select(shoot_scc)
return(output)
}
get_xg_r <- function(kick){
output <- kick |>
dplyr::filter(shoot == TRUE) %>%
dplyr::filter(side == "r") %>%
distinct(step, .keep_all = TRUE) %>%
dplyr::mutate(px = px * -1,py = py *-1,ball_x = -1 * ball_x,ball_y = ball_y * -1) %>%
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)) %>%
dplyr::select(px,py,ball_x,ball_y,ball_goal_dist,ball_goal_angle)
return(output)
}
get_xg_r_label <- function(kick){
output <- kick |>
dplyr::filter(shoot == TRUE) %>%
dplyr::filter(side == "r") %>%
distinct(step, .keep_all = TRUE) %>%
dplyr::select(shoot_scc)
return(output)
}
get_dp <- function(dribbleAll){ get_dp <- function(dribbleAll){
output <- dribbleAll |> output <- dribbleAll |>
dplyr::mutate(p_speed = sqrt(pvx^2 + pvy^2)) %>% dplyr::mutate(p_speed = sqrt(pvx^2 + pvy^2)) %>%
...@@ -248,7 +306,7 @@ get_shoot_epv <- function(players,shoot){ ...@@ -248,7 +306,7 @@ get_shoot_epv <- function(players,shoot){
shootAll <- get_shoot_Allplayer(players,shoot) shootAll <- get_shoot_Allplayer(players,shoot)
goalkeeper <- get_goalkeeper_action(shootAll) |> goalkeeper <- get_goalkeeper_action(shootAll) |>
dplyr::filter(team != shoot_team) |> dplyr::filter(team != shoot_team) |>
dplyr::select(step,ball_keeper_dist_x,keeper_goal_dist=player_goal_dist,ball_closer_goal_goalkeeper) dplyr::select(step,side,ball_keeper_dist_x,keeper_goal_dist=player_goal_dist,ball_closer_goal_goalkeeper)
opponent_team <- shootAll |> opponent_team <- shootAll |>
dplyr::filter(team != shoot_team) %>% dplyr::filter(team != shoot_team) %>%
dplyr::mutate(r_post_x = (ball_x + (py - ball_y)*(7-ball_x)/(-54-ball_y))) %>% dplyr::mutate(r_post_x = (ball_x + (py - ball_y)*(7-ball_x)/(-54-ball_y))) %>%
...@@ -266,8 +324,8 @@ get_shoot_epv <- function(players,shoot){ ...@@ -266,8 +324,8 @@ get_shoot_epv <- function(players,shoot){
output <- shoot |> output <- shoot |>
dplyr::left_join(goalkeeper,by = "step") %>% dplyr::left_join(goalkeeper,by = "step") %>%
dplyr::left_join(opp_dist_ball_in_3m_num,by="step") %>% dplyr::left_join(opp_dist_ball_in_3m_num,by="step") %>%
dplyr::left_join(opp_triangle_in_player_num,by = "step") dplyr::left_join(opp_triangle_in_player_num,by = "step") %>%
replace_na(list(triangle_in_player_num = 0, dist_ball_in_3m_num = 0))
return(output) return(output)
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment