Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import re
- import pandas as pd
- rex_move = re.compile(r';[BW]\[[a-z]{2}\]')
- rex_res = re.compile(r'RE\[[BW]\+T\]')
- rex_tm = re.compile(r'OT\[([^ ]{0,100}) ?([^]]{2,100})\]')
- data_timeout = []
- data_tmode = []
- total = 0
- for fn in filter(lambda x: x.endswith('.sgf'), os.listdir('.')):
- with open(fn, 'r') as f:
- content = f.read()
- has_timeout = rex_res.search(content) is not None
- tm = rex_tm.search(content)
- tm_mode = None
- if tm is not None:
- tm_mode = tm.group(2)
- if len(rex_move.findall(content)) > 5:
- data_timeout += [has_timeout]
- data_tmode += [tm_mode]
- total += 1
- df = pd.DataFrame({
- 'timeout': data_timeout,
- 'tmode': data_tmode,
- 'count':1})
- sum_all = df.filter(items=['tmode','count']).groupby(by='tmode').sum()
- df2 = df[df.timeout == True]
- sum_to = df2.filter(items=['tmode','count']).groupby(by='tmode').sum()
- df5 = sum_all.merge(sum_to, on='tmode', suffixes=['_all', '_timeout'])
- df5.loc['TOTAL'] = df5.sum()
- df5['%timeout'] = df5['count_timeout'] / df5['count_all'] * 100
- df5.at['TOTAL','%timeout'] += 1000
- df5 = df5.sort_values(by='%timeout')
- df5.at['TOTAL','%timeout'] -= 1000
- print('ignored', total - len(data_timeout) + 1, 'immediately aborted games')
- print()
- print(df5)
- print()
- df5 = df5.drop(labels='TOTAL')
- import matplotlib.pyplot as plt
- fig,ax = plt.subplots()
- ax.pie(df5['%timeout'], labels=df5.index, autopct='%.1f%%')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement