Commit 49e8ea6f authored by Keisuke ANDO's avatar Keisuke ANDO 😌
Browse files

[add] plotlyを使ったビジュアライゼーションのサンプルを追加(analyzerの互換機能)

parent 59f1eb7a
...@@ -5,6 +5,8 @@ output: github_document ...@@ -5,6 +5,8 @@ output: github_document
RoboCup Soccer 2Dの試合分析のためのツール群 RoboCup Soccer 2Dの試合分析のためのツール群
## 機能
### `read_rcl` ### `read_rcl`
指定されたrclファイルを解析し、tibbleにして返します。 指定されたrclファイルを解析し、tibbleにして返します。
...@@ -12,7 +14,9 @@ RoboCup Soccer 2Dの試合分析のためのツール群 ...@@ -12,7 +14,9 @@ RoboCup Soccer 2Dの試合分析のためのツール群
```{r, message=FALSE, collapse = TRUE} ```{r, message=FALSE, collapse = TRUE}
library(tidyverse) library(tidyverse)
source("R/read_rcl.R") source("R/read_rcl.R")
read_rcl("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcl") rcl <- read_rcl("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcl")
head(rcl)
``` ```
### `read_rcg` ### `read_rcg`
...@@ -22,5 +26,59 @@ read_rcl("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcl") ...@@ -22,5 +26,59 @@ read_rcl("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcl")
```{r, message=FALSE, collapse = TRUE} ```{r, message=FALSE, collapse = TRUE}
library(tidyverse) library(tidyverse)
source("R/read_rcg.R") source("R/read_rcg.R")
read_rcg("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcg") 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))
)
)
``` ```
![plotly-visualization-sample](image/plotly-visualization-sample.png)
...@@ -3,6 +3,8 @@ socceR ...@@ -3,6 +3,8 @@ socceR
RoboCup Soccer 2Dの試合分析のためのツール群 RoboCup Soccer 2Dの試合分析のためのツール群
## 機能
### `read_rcl` ### `read_rcl`
指定されたrclファイルを解析し、tibbleにして返します。 指定されたrclファイルを解析し、tibbleにして返します。
...@@ -10,21 +12,18 @@ RoboCup Soccer 2Dの試合分析のためのツール群 ...@@ -10,21 +12,18 @@ RoboCup Soccer 2Dの試合分析のためのツール群
``` r ``` r
library(tidyverse) library(tidyverse)
source("R/read_rcl.R") source("R/read_rcl.R")
read_rcl("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcl") rcl <- read_rcl("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcl")
## # A tibble: 867,098 x 6
## step team unum command args line head(rcl)
## <chr> <chr> <chr> <chr> <list> <chr> ## # A tibble: 6 x 6
## 1 0 HELIOS_base 1 init <chr [1]> "0,114\tRecv HELIOS_base_1: (i~ ## step team unum command args line
## 2 0 HELIOS_base 1 version <chr [1]> "0,114\tRecv HELIOS_base_1: (i~ ## <chr> <chr> <chr> <chr> <list> <chr>
## 3 0 HELIOS_base 1 goalie <chr [0]> "0,114\tRecv HELIOS_base_1: (i~ ## 1 0 HELIOS_base 1 init <chr [1]> "0,114\tRecv HELIOS_base_1: (init~
## 4 0 HELIOS_base 1 synch_see <chr [0]> "0,115\tRecv HELIOS_base_1: (s~ ## 2 0 HELIOS_base 1 version <chr [1]> "0,114\tRecv HELIOS_base_1: (init~
## 5 0 HELIOS_base 1 ear <chr [0]> "0,115\tRecv HELIOS_base_1: (s~ ## 3 0 HELIOS_base 1 goalie <chr [0]> "0,114\tRecv HELIOS_base_1: (init~
## 6 0 HELIOS_base 1 off <chr [1]> "0,115\tRecv HELIOS_base_1: (s~ ## 4 0 HELIOS_base 1 synch_see <chr [0]> "0,115\tRecv HELIOS_base_1: (sync~
## 7 0 HELIOS_base 1 clang <chr [0]> "0,115\tRecv HELIOS_base_1: (s~ ## 5 0 HELIOS_base 1 ear <chr [0]> "0,115\tRecv HELIOS_base_1: (sync~
## 8 0 HELIOS_base 1 ver <chr [1]> "0,115\tRecv HELIOS_base_1: (s~ ## 6 0 HELIOS_base 1 off <chr [1]> "0,115\tRecv HELIOS_base_1: (sync~
## 9 0 HELIOS_base 1 change_view <chr [1]> "0,115\tRecv HELIOS_base_1: (c~
## 10 0 HELIOS_base 1 turn <chr [1]> "0,115\tRecv HELIOS_base_1: (t~
## # ... with 867,088 more rows
``` ```
### `read_rcg` ### `read_rcg`
...@@ -34,21 +33,69 @@ read_rcl("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcl") ...@@ -34,21 +33,69 @@ read_rcl("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcl")
``` r ``` r
library(tidyverse) library(tidyverse)
source("R/read_rcg.R") source("R/read_rcg.R")
read_rcg("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcg") rcg <- read_rcg("data/20220405162804-HELIOS_base_3-vs-enemy_2.rcg")
## # A tibble: 143,418 x 21
## step side unum type state x y vx vy body neck vq head(rcg)
## <int> <chr> <int> <int> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <chr> ## # A tibble: 6 x 21
## 1 1 l 1 0 9 -49 0 0 0 54.7 0 h ## step side unum type state x y vx vy body neck vq vw
## 2 1 l 2 17 1 -25 -5 0 0 -118. 0 h ## <int> <chr> <int> <int> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <chr> <int>
## 3 1 l 3 8 1 -25 5 0 0 108. 0 h ## 1 1 l 1 0 9 -49 0 0 0 54.7 0 h 180
## 4 1 l 4 13 1 -25 -10 0 0 -117. 0 h ## 2 1 l 2 17 1 -25 -5 0 0 -118. 0 h 180
## 5 1 l 5 6 1 -25 10 0 0 -174. 0 h ## 3 1 l 3 8 1 -25 5 0 0 108. 0 h 180
## 6 1 l 6 11 1 -25 0 0 0 114. 0 h ## 4 1 l 4 13 1 -25 -10 0 0 -117. 0 h 180
## 7 1 l 7 10 1 -15 -5 0 0 162. 0 h ## 5 1 l 5 6 1 -25 10 0 0 -174. 0 h 180
## 8 1 l 8 5 1 -15 5 0 0 -170. 0 h ## 6 1 l 6 11 1 -25 0 0 0 114. 0 h 180
## 9 1 l 9 4 1 -15 -10 0 0 175. 0 h ## # ... with 8 more variables: stamina <dbl>, effort <dbl>, recovery <dbl>,
## 10 1 l 10 16 1 -15 10 0 0 -122. 0 h ## # capacity <dbl>, ball_x <dbl>, ball_y <dbl>, ball_vx <dbl>, ball_vy <dbl>
## # ... with 143,408 more rows, and 9 more variables: vw <int>, stamina <dbl>, ```
## # effort <dbl>, recovery <dbl>, capacity <dbl>, ball_x <dbl>, ball_y <dbl>,
## # ball_vx <dbl>, ball_vy <dbl> ## plotlyを使ったビジュアライゼーションのサンプル
``` r
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))
)
)
``` ```
![plotly-visualization-sample](image/plotly-visualization-sample.png)
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