Advertisement
Guest User

sgf timeout statistics

a guest
Mar 21st, 2022
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. import os
  2. import re
  3. import pandas as pd
  4.  
  5. rex_move = re.compile(r';[BW]\[[a-z]{2}\]')
  6. rex_res = re.compile(r'RE\[[BW]\+T\]')
  7. rex_tm = re.compile(r'OT\[([^ ]{0,100}) ?([^]]{2,100})\]')
  8.  
  9. data_timeout = []
  10. data_tmode = []
  11. total = 0
  12.  
  13. for fn in filter(lambda x: x.endswith('.sgf'), os.listdir('.')):
  14.     with open(fn, 'r') as f:
  15.         content = f.read()
  16.     has_timeout = rex_res.search(content) is not None
  17.     tm = rex_tm.search(content)
  18.     tm_mode = None
  19.     if tm is not None:
  20.         tm_mode = tm.group(2)
  21.     if len(rex_move.findall(content)) > 5:
  22.         data_timeout += [has_timeout]
  23.         data_tmode += [tm_mode]
  24.     total += 1
  25.  
  26. df = pd.DataFrame({
  27.     'timeout': data_timeout,
  28.     'tmode': data_tmode,
  29.     'count':1})
  30.  
  31. sum_all = df.filter(items=['tmode','count']).groupby(by='tmode').sum()
  32.  
  33. df2 = df[df.timeout == True]
  34. sum_to = df2.filter(items=['tmode','count']).groupby(by='tmode').sum()
  35.  
  36. df5 = sum_all.merge(sum_to, on='tmode', suffixes=['_all', '_timeout'])
  37. df5.loc['TOTAL'] = df5.sum()
  38. df5['%timeout'] = df5['count_timeout'] / df5['count_all'] * 100
  39. df5.at['TOTAL','%timeout'] += 1000
  40. df5 = df5.sort_values(by='%timeout')
  41. df5.at['TOTAL','%timeout'] -= 1000
  42.  
  43. print('ignored', total - len(data_timeout) + 1, 'immediately aborted games')
  44. print()
  45.  
  46. print(df5)
  47. print()
  48.  
  49. df5 = df5.drop(labels='TOTAL')
  50.  
  51. import matplotlib.pyplot as plt
  52. fig,ax = plt.subplots()
  53. ax.pie(df5['%timeout'], labels=df5.index, autopct='%.1f%%')
  54. plt.show()
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement