-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_pvz.py
More file actions
156 lines (120 loc) · 3.8 KB
/
Copy pathextract_pvz.py
File metadata and controls
156 lines (120 loc) · 3.8 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
import os
import shutil
import sc2reader
import sys
source_folder = r"hsc28_flatten/"
target_folder = r"hsc28_pvz/"
for filename in os.listdir(source_folder):
print("file: ", filename, flush = True)
if not filename.endswith(".SC2Replay"):
print(filename, " does not end in SC2Replay")
continue
replay_path = os.path.join(source_folder, filename)
replay = sc2reader.load_replay(replay_path)
pvz = false
if (pvz):
shutil.copy2(
replay_path,
os.path.join(target_folder, filename)
)
print(f"Copied: {filename}")
# Example condition:
# Copy replay if game lasted more than 20 minutes
sys.exit()
print(sc2reader.__version__)
# Also loads game events:
#sc2reader.load_replay('MyReplay.SC2Replay', load_level=4)
replays = sc2reader.load_replays('hsc28')
#print(type(replays))
def sectomin(seconds):
return (seconds // 60.0)
t0 = time.perf_counter()
def tac():
t = time.perf_counter() - t0
print("t: ", f"{t:.2f}", "sec", flush = True)
i = 0
for r in replays:
i = i + 1
print(i, tac())
help(r)
replay_path = os.path.join()
sys.exit()
for r in replays:
sys.exit()
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")