-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsereportbin.py
55 lines (42 loc) · 1.36 KB
/
parsereportbin.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
import collections
import struct
import sys
header_length = 128
def main():
file_name = "fullreport.bin"
if len(sys.argv) > 1:
file_name = sys.argv[1]
games = collections.Counter()
won = collections.Counter()
lengths = collections.Counter()
headers = {}
win_mask = 1 << 63
len_mask = win_mask - 1
with open(file_name, 'rb') as f:
while True:
blob = f.read(8)
if not blob: break
idx = struct.unpack("<Q", blob)[0]
if idx not in headers:
blob = f.read(header_length - 8)
header = blob[:blob.index(b'\x00')].decode()
headers[idx] = header
else:
blob = f.read(8)
length = struct.unpack("<Q", blob)[0]
result = length & win_mask
length = length & len_mask
result = bool(result)
games[idx] += 1
if result:
won[idx] += 1
lengths[idx] += length
out_name = "parsedreport.csv"
if len(sys.argv) > 2:
out_name = sys.argv[2]
with open(out_name, 'w') as f:
f.write('sim;bs;i;N;p;q;runs;won;sumlengths;\n')
for k in headers:
f.write('{}{};{};{};\n'.format(headers[k],games[k],won[k],lengths[k]))
if __name__ == '__main__':
main()