read_old_rcg.R 3.49 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
110
111
read_old_rcg_ball <- function(path_rcg){
    ball_log <- path_rcg |>
    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("\\)"),
        ball_x = ball |> stringr::str_extract("[0-9\\-\\.]+"),
        ball_y = ball |> stringr::str_remove(ball_x)
            |> stringr::str_extract("[0-9\\-\\.]+"),
        ball_vx = ball  |> stringr::str_remove(ball_x)
            |> stringr::str_remove(ball_y)
            |> stringr::str_extract("[0-9\\-\\.]+"),
        ball_vy = ball  |> stringr::str_remove(ball_x)
            |> stringr::str_remove(ball_y)
            |> stringr::str_remove(ball_vx)
            |> stringr::str_extract("[0-9\\-\\.]+"),
        step = as.numeric(step),
        # ball,
        ball_x = as.numeric(ball_x),
        ball_y = as.numeric(ball_y),
        ball_vx = as.numeric(ball_vx),
        ball_vy = as.numeric(ball_vy),
    )|>
    dplyr::select(
        step,
        # ball,
        ball_x,
        ball_y,
        ball_vx,
        ball_vy,
    ) %>% tidyr::drop_na()
    return(ball_log)
}

read_old_rcg_player <- function(path_rcg){
    player_log <- path_rcg |>
    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]+\\)"),
        side = 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),

        step = as.numeric(step),
        # players,
        # player,
        side,
        unum = unum,
        # params,
        # type,
        # state,
        x = as.numeric(x),
        y = as.numeric(y),
        vx = as.numeric(vx),
        vy = as.numeric(vy),
        body = as.numeric(body),
        neck = as.numeric(neck),
    ) |>
    dplyr::select(
        step,
        # players,
        # player,
        side,
        unum,
        # params,
        # type,
        # state,
        x,
        y,
        vx,
        vy,
        body,
        neck,
    ) %>% tidyr::drop_na()
    return(player_log)
}