get_kick_point.R 2.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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,
    )
18
19
20
  
  return(output)
}
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

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)
}