-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
114 lines (89 loc) · 2.95 KB
/
Copy pathanalysis.py
File metadata and controls
114 lines (89 loc) · 2.95 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
import sc2reader
import plotly.express as px
import pandas
import sys
print(sc2reader.__version__)
# Also loads game events:
#sc2reader.load_replay('MyReplay.SC2Replay', load_level=4)
replays = sc2reader.load_replays('replays')
#print(type(replays))
def sectomin(seconds):
return (seconds // 60.0)
for r in replays:
r: sc2reader.resources.Replay
born_units = []
ko2: sc2reader.utils.Length = r.game_length * 1.012
total_baneling_count : int = 0
times = []
counts = []
for event in r.events:
#print(event)
#print(vars(event), " of type: ", type(vars(event)))
something_changed : bool = False
baneling_count_before_event = total_baneling_count
if (event.name == "UnitBornEvent"):
if (event.unit.name == "Queen"):
total_baneling_count += 1
something_changed = True
if (event.name == "UnitDiedEvent" or event.name == "UnitTypeChangeEvent"):
if (event.unit.name == "Queen"):
total_baneling_count -= 1
something_changed = True
if (baneling_count_before_event != total_baneling_count):
times.append(event.second // 60)
counts.append(total_baneling_count)
#exit
# uoc = event.tracker.UnitOwnerChangeEvent
#for t, c in zip(times, counts):
#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")
print("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))
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")