README.Rmd 2.3 KB
Newer Older
Keisuke ANDO's avatar
Keisuke ANDO committed
1
2
3
4
5
---
title: "socceR"
output: github_document
---

6
7
RoboCup Soccer 2Dの試合分析のためのツール群

8
9
## 機能

10
11
12
### `read_rcl`

指定されたrclファイルを解析し、tibbleにして返します。
Keisuke ANDO's avatar
Keisuke ANDO committed
13
14
15
16

```{r, message=FALSE, collapse = TRUE}
library(tidyverse)
source("R/read_rcl.R")
17
18
19
rcl <- read_rcl("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcl")

head(rcl)
20
21
22
23
24
25
26
27
28
```

### `read_rcg`

指定されたrcgファイルを解析し、tibbleにして返します。

```{r, message=FALSE, collapse = TRUE}
library(tidyverse)
source("R/read_rcg.R")
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
rcg <- read_rcg("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcg")

head(rcg)
```


## plotlyを使ったビジュアライゼーションのサンプル

```{r, message=FALSE, eval=FALSE}
library(plotly)

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::filter(move_dist != 0 & move_dist < 40)

ball_path |>
  plotly::plot_ly(showlegend = FALSE) |>
  plotly::add_markers(
    data       = ball_path,
    x          = ~ball_x,
    y          = ~ball_y,
    z          = ~move_dist,
    marker     = list(color        = ~move_dist,
                      size         = 3,
                      colorscale   = "Viridis",
                      opacity      = 0.8,
                      showscale  = FALSE)
  ) |>
  plotly::add_paths(
    data       = ball_path |>
                 dplyr::select(step, ball_x, ball_y, move_dist) |>
                 dplyr::mutate(base = 0) |>
                 tidyr::pivot_longer(c(move_dist, base)) |>
                 dplyr::group_by(step),
    x          = ~ball_x,
    y          = ~ball_y,
    z          = ~value,
    color      = ~value
  ) |>
  plotly::hide_colorbar() |>
  plotly::layout(
    scene = list(
      xaxis  = list(title = "ボールのX座標"),
      yaxis  = list(title = "ボールのY座標"),
      zaxis  = list(title = "ボールの飛距離"),
      camera = list(eye    = list(x = 0.8, y = -1.8, z =  0.8),
                    center = list(x = 0.0, y =  0.0, z = -0.2))
    )
  )

83
```
84
![plotly-visualization-sample](image/plotly-visualization-sample.png)