-
Notifications
You must be signed in to change notification settings - Fork 1
/
winrate.py
executable file
·67 lines (50 loc) · 1.89 KB
/
winrate.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
#!/usr/bin/env python3
# Copyright 2023 Nobleo Technology B.V.
#
# SPDX-License-Identifier: Apache-2.0
from argparse import ArgumentParser, FileType
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from snakes.elo import read_csv
def print_winrate(df):
reserved_names = ['turns', 'seed']
names = [name for name in df.columns if name not in reserved_names and not name.startswith('cpu_')]
cpu_names = ['cpu_' + name for name in names]
ranking = df[names] # contains only the individual match rankings
data = {
'Wins': (ranking == 1).sum(),
'Matches': ranking.notna().sum(),
}
data = pd.DataFrame(data)
data['Rate'] = data['Wins'] / data['Matches']
data.sort_values('Rate', inplace=True, ascending=False)
winrate = pd.DataFrame(np.full((len(names), len(names)), np.nan), index=data.index, columns=data.index)
for a in data.index:
for b in data.index:
if a == b:
continue
matches_participated = ranking[ranking[a].notna() & ranking[b].notna()]
won = (matches_participated[a] < matches_participated[b]).sum()
winrate[a][b] = won / len(matches_participated)
print(winrate.T.to_string(max_rows=np.inf, max_cols=np.inf))
fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.matshow(winrate.T, interpolation='nearest')
fig.colorbar(cax)
ax.set_xticks(range(len(data.index)))
ax.set_xticklabels(data.index, rotation=90)
ax.set_yticks(range(len(data.index)))
ax.set_yticklabels(data.index)
plt.show()
def main(infile):
df = read_csv(infile)
print_winrate(df)
if __name__ == '__main__':
parser = ArgumentParser(description='Elo estimation')
parser.add_argument('infile', type=FileType(), help="Input csv")
args = parser.parse_args()
try:
main(**vars(args))
except KeyboardInterrupt:
pass