Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Keisuke ANDO
socceR
Commits
85828ab7
Commit
85828ab7
authored
Apr 13, 2022
by
Takumi Amano
💬
Committed by
Keisuke ANDO
Apr 15, 2022
Browse files
[add]rcgファイルの読み取りとグラフ作成を追加
parent
cb5f6f04
Changes
2
Show whitespace changes
Inline
Side-by-side
R/make_graphics.R
0 → 100644
View file @
85828ab7
make_graph
<-
function
(
p_data
,
teamname
,
num
){
p
<-
ggplot
(
data
=
p_data
%>%
filter
(
team
==
teamname
,
unum
==
num
),
aes
(
x
=
as.numeric
(
x
),
y
=
as.numeric
(
y
)))
+
ggplot2
::
coord_fixed
(
xlim
=
c
(
-55
,
55
),
ylim
=
c
(
-35
,
35
))
+
geom_hline
(
yintercept
=
-34.1
,
linetype
=
"solid"
)
+
geom_hline
(
yintercept
=
34.1
,
linetype
=
"solid"
)
+
geom_hline
(
yintercept
=
0
,
linetype
=
"solid"
)
+
geom_vline
(
xintercept
=
52.6
,
linetype
=
"solid"
)
+
geom_vline
(
xintercept
=
-52.6
,
linetype
=
"solid"
)
+
geom_vline
(
xintercept
=
0
,
linetype
=
"solid"
)
+
geom_point
(
size
=
0.1
)
+
geom_density_2d_filled
(
alpha
=
0.7
)
return
(
p
)
}
#ggplot2::geom_path(size=1.2,aes(color = as.numeric(step))) +
# +
# ggplot2::geom_density2d(size = 0.25, colour = "black")
\ No newline at end of file
R/read_rcg.R
0 → 100644
View file @
85828ab7
# remove(list = ls());gc()
# path = "~/socceR/R/test.rcg"
tag
<-
c
(
"x"
,
"y"
,
"vx"
,
"vy"
)
read_rcg_ball
<-
function
(
path
){
ball_log
<-
path
|>
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
(
"\\)"
),
x
=
ball
|>
stringr
::
str_extract
(
"[0-9\\-\\.]+"
),
y
=
ball
|>
stringr
::
str_remove
(
x
)
|>
stringr
::
str_extract
(
"[0-9\\-\\.]+"
),
vx
=
ball
|>
stringr
::
str_remove
(
x
)
|>
stringr
::
str_remove
(
y
)
|>
stringr
::
str_extract
(
"[0-9\\-\\.]+"
),
vy
=
ball
|>
stringr
::
str_remove
(
x
)
|>
stringr
::
str_remove
(
y
)
|>
stringr
::
str_remove
(
vx
)
|>
stringr
::
str_extract
(
"[0-9\\-\\.]+"
),
)
|>
dplyr
::
select
(
step
,
# ball,
x
,
y
,
vx
,
vy
,
)
%>%
tidyr
::
drop_na
()
return
(
ball_log
)
}
read_rcg_player
<-
function
(
path
){
player_log
<-
path
|>
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]+\\)"
),
team
=
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
),
)
|>
dplyr
::
select
(
step
,
# players,
# player,
team
,
unum
,
# params,
# type,
# state,
x
,
y
,
vx
,
vy
,
body
,
neck
,
)
%>%
tidyr
::
drop_na
()
return
(
player_log
)
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment