-
Notifications
You must be signed in to change notification settings - Fork 1
/
FormationDetectorDataExtractor.py
168 lines (160 loc) · 4.66 KB
/
FormationDetectorDataExtractor.py
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
from BaseCode.Game import Game
from BaseCode.Cycle import GameMode
import matplotlib.pyplot as plt
from PyrusGeom.vector_2d import Vector2D
import sys
import os
def calculate_average(positions):
x = sum([p.x() for p in positions]) / len(positions)
y = sum([p.y() for p in positions]) / len(positions)
return Vector2D(x, y)
def read_log(path):
g = Game()
g.read_log(path)
defensive_positions = []
offensive_positions = []
for p in range(1, 12):
defensive_positions.append([])
offensive_positions.append([])
for c in g.cycles():
if c.game_mode() != GameMode.play_on:
pass
elif c.next_kicker_team == ['l']:
offensive_positions[-1].append(c.players()[-p].pos_())
elif c.next_kicker_team == ['r']:
defensive_positions[-1].append(c.players()[-p].pos_())
avg_defensive_positions = [calculate_average(p) for p in defensive_positions]
avg_offensive_positions = [calculate_average(p) for p in offensive_positions]
return avg_defensive_positions, avg_offensive_positions
def main(path, csv_out, teams_files, team):
"""
Showing player move point by plot
:param path: path of rcg files
"""
import multiprocessing
process_pool = multiprocessing.Pool(processes=50)
files = []
for f in teams_files:
files.append(os.path.join(path, f))
result_list = process_pool.map(read_log, files)
defensive_positions = [[] for _ in range(11)]
offensive_positions = [[] for _ in range(11)]
for r in result_list:
for i in range(11):
defensive_positions[i].append(r[0][i])
offensive_positions[i].append(r[1][i])
avg_defensive_positions = [calculate_average(p) for p in defensive_positions]
avg_offensive_positions = [calculate_average(p) for p in offensive_positions]
# print(avg_defensive_positions)
# print(avg_offensive_positions)
# for p in avg_defensive_positions:
# plt.scatter(p.x(), p.y())
# plt.xlim([-52, 52])
# plt.ylim([-34, 34])
# plt.show()
# for p in avg_offensive_positions:
# plt.scatter(p.x(), p.y())
# plt.xlim([-52, 52])
# plt.ylim([-34, 34])
# plt.show()
s = f'{team},'
for p in avg_defensive_positions:
s += f'{p.x()},'
s += f'{p.y()},'
for p in avg_offensive_positions:
s += f'{p.x()},'
s += f'{p.y()},'
s += '\n'
f = open(f'{csv_out}', 'w')
f.write(s)
f.close()
if __name__ == "__main__":
teams = [
'2017_alice',
'2018_alice',
'2021_alice',
'2021_aras',
'2021_austras2d',
'2016_csu_yunlu',
'2017_csuyunlu',
'2016_cyrus',
'2017_cyrus',
'2018_cyrus',
'2019_cyrus',
'2021_cyrus',
'2016_fcp_gpr',
'2018_fcpgpr',
'2019_fcpgpr',
'2017_fifty - storms',
'2016_fra',
'2017_fra',
'2021_fra - united',
'2019_fractals',
'2018_fraunited',
'2019_fraunited',
'2016_fury',
'2016_gliders',
'2021_hades2d',
'2016_helios',
'2017_helios',
'2018_helios',
'2019_helios',
'2021_helios',
'2016_hermes',
'2016_hfutengine',
'2017_hfutengine',
'2019_hfutengine',
'2021_hfutengine',
'2016_hillstone',
'2017_hillstone',
'2018_hillstone',
'2019_hillstone',
'2016_itandroids',
'2017_itandroids',
'2018_itandroids',
'2019_itandroids',
'2021_itandroids',
'2021_jyo_sen',
'2016_lefteagle',
'2016_marlik',
'2016_mt',
'2017_mt',
'2018_mt',
'2019_mt',
'2021_mt',
'2018_namira',
'2017_nexus2d',
'2016_oxsy',
'2017_oxsy',
'2018_oxsy',
'2021_oxsy',
'2021_persepolis',
'2017_persiangulf',
'2018_razi',
'2019_razi',
'2019_receptivity',
'2016_ri - one',
'2017_rione',
'2018_rione',
'2019_rione',
'2019_robocin',
'2021_robocin',
'2016_shiraz',
'2019_titans',
'2018_yushan',
'2019_yushan',
'2021_yushan',
'2017_ziziphus',
]
path = './all_games'
files = os.listdir(path)
teams_files = {}
for file in files:
print(file)
left_team = file.split('__')[1]
if left_team not in teams_files.keys():
teams_files[left_team] = []
teams_files[left_team].append(file)
for team in teams_files.keys():
csv_out = f'./csv_form/{team}.csv'
main(path, csv_out, teams_files[team], team)