Commit de8a994f authored by Takumi Amano's avatar Takumi Amano 💬
Browse files

[fix]stimeが読み込まれていないため、正確な選手の位置が取得できなかったので修正

parent f2661fc0
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)
}
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
}
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
......@@ -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) |>
......
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