-
Notifications
You must be signed in to change notification settings - Fork 11
/
parse_log.py
executable file
·69 lines (57 loc) · 1.57 KB
/
parse_log.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
#!/usr/bin/env python
from pylab import *
import scipy as ss
from sys import argv
import re
configre = re.compile(r'''^p1time=(\d+\.\d+) p2time=(\d+\.\d+)$''')
winningre = re.compile(r'''^winner: bot (\d) .+$''')
fh = open(argv[1],"r")
results = {}
current_key = None
for line in fh:
match = configre.match(line)
if match:
key = tuple(map(lambda x: int(10.*float(x)),match.groups()))
assert(key not in results)
results[key] = []
current_key = key
match = winningre.match(line)
if match:
assert(current_key is not None)
results[current_key].append(int(match.groups()[0])-1)
fh.close()
for key,value in results.items():
print key, float(sum(value))/len(value), len(value)
aa = ss.arange(1,10,2,dtype=ss.integer)
def proba(p1time=None,p2time=None):
bb = ss.zeros(aa.shape)
cc = ss.zeros(aa.shape)
for k,time in enumerate(aa):
if p1time is not None:
key = (p1time,time)
if p2time is not None:
key = (time,p2time)
try:
res = results[key]
bb[k] = float(sum(res))/len(res)
cc[k] = len(res)
except KeyError:
print "can't find key %s" % repr(key)
return bb,cc
figure(1)
ylabel("p2 win probability [%]")
xlabel("p2 time [ms]")
figure(2)
ylabel("realisation count")
xlabel("p2 time [ms]")
for time in aa:
bb,cc = proba(p1time=time)
figure(1)
plot(aa*100,bb,label="p1 time %dms" % (100*time))
figure(2)
plot(aa*100,cc,label="p1 time %dms" % (100*time))
figure(1)
legend()
figure(2)
legend()
show()