-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis2.py
More file actions
205 lines (158 loc) · 5.45 KB
/
Copy pathanalysis2.py
File metadata and controls
205 lines (158 loc) · 5.45 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import os
import sys
import sc2reader
import plotly.express as px
import pandas
import shutil
import time
print(sc2reader.__version__)
# Also loads game events:
#sc2reader.load_replay('MyReplay.SC2Replay', load_level=4)
replays = sc2reader.load_replays('hsc28_flatten')
#print(type(replays))
def sectomin(seconds):
return (seconds // 60.0)
t0 = time.perf_counter()
def tic():
global t0
t0 = time.perf_counter()
def tac():
t = time.perf_counter() - t0
#elapsed = "t: ", f"{t:.2f}", "sec"
elapsed = f"t: {t:.2f} sec"
print (elapsed, flush = True)
return elapsed
i = 0
tic()
"""
for r in replays:
i = i + 1
print(i, tac())
"""
tic()
has_both : int = 0
def replay_info():
r: sc2reader.resources.Replay = next(replays)
# --- REPLAY LEVEL DATA ---
print("--- REPLAY PROPERTIES ---")
# See everything attached to the main replay object (length, map name, date, etc.)
print(dir(r))
# --- PLAYER LEVEL DATA ---
print("\n--- PLAYER 1 DATA ---")
player1 = r.players[0]
# vars() will print a beautiful dictionary of player stats (APM, Race, Result, URL, etc.)
print(vars(player1))
# --- EVENT LEVEL DATA (The meat of the game) ---
print("\n--- SAMPLE EVENTS ---")
# Let's just look at the first 10 events to see how they are structured
for event in r.events[:10]:
print(f"Type: {type(event)}")
print(f"Data: {vars(event)}\n")
def full_analysis():
i = 0
for r in replays:
i += 1
print ("replay #", i)
r: sc2reader.resources.Replay
born_units = []
#gl: sc2reader.utils.Length = r.game_length * 1.012
gl = r.game_length
total_mutalisk_count : int = 0
total_phoenix_count : int = 0
phoenix_built : int = 0
mutalisk_built : int = 0
times = []
counts = []
has_mutalisk : bool = False
has_phoenix : bool = False
for event in r.events:
#print(event)
#print(vars(event), " of type: ", type(vars(event)))
something_changed : bool = False
mutalisk_count_before_event = total_mutalisk_count
if (event.name == "UnitBornEvent"):
if (event.unit.name == "Mutalisk"):
total_mutalisk_count += 1
something_changed = True
has_mutalisk = True
mutalisk_built += 1
if (event.unit.name == "Phoenix"):
total_phoenix_count += 1
something_changed = True
has_phoenix = True
phoenix_built += 1
if (event.name == "UnitDiedEvent" or event.name == "UnitTypeChangeEvent"):
if (event.unit.name == "Mutalisk"):
total_mutalisk_count -= 1
something_changed = True
if (event.unit.name == "Phoenix"):
total_phoenix_count -= 1
something_changed = True
if (mutalisk_count_before_event != total_mutalisk_count):
times.append(event.second // 60)
counts.append(total_mutalisk_count)
#exit
# uoc = event.tracker.UnitOwnerChangeEvent
if (has_mutalisk):
print("MUTALISK DETECTED (", mutalisk_built, ")")
if (has_phoenix):
print("PHOENIX DETECTED (", phoenix_built, ")")
if (has_mutalisk and has_phoenix):
has_both += 1
#for t, c in zip(times, counts):
continue
#hist_x = [0] * 60
#for x in range(60):
#hist_x[x] = sum(c for t, c in zip(times, counts) if t < x)
data_x = [0] * 60
for x in range(60):
for t, c in zip(times, counts):
if (t < x):
data_x[x] = c
mean_count = [0] * 60
j = 0
times_counts = tuple(zip(times, counts)) #should be sorted but i'll test it
sorted_times_counts = tuple(sorted(zip(times, counts)))
if (times_counts != sorted_times_counts):
print("wait times counts was not sorted?")
print("times_counts:", times_counts)
print("sorted_times_counts:", sorted_times_counts)
sys.exit()
last_c = 0
for x in range(60):
running_sum = 0
j_len = 0
while j < len(times_counts) and times_counts[j][0] < x:
last_c = times_counts[j][1]
running_sum += last_c
j += 1
j_len += 1
if (j_len > 1):
running_sum = running_sum / j_len
if (j_len == 0 and x > 0):
running_sum = last_c
if (x > r.game_length.mins):
running_sum = -1
mean_count[x] = running_sum
print(r.game_length.mins)
#help(r)
#print(dir(r))
continue
df = pandas.DataFrame({
"time": times,
"banelings": counts
})
fig = px.line(df, x="time", y="banelings", title="Baneling Count Over Time")
fig.show()
xval = [0] * 60
for n in range(60):
xval[n] = n
df2 = pandas.DataFrame({
"time2": xval,
"units": mean_count
})
fig = px.line(df2, x="time2", y="units", title="unit Count Over Time")
fig.show()
fig.write_html("fake_banelings.html")
print("has both #:", has_both)
replay_info()