swdata/fail_reason.py
2018-03-11 17:27:59 +08:00

58 lines
2.5 KiB
Python

import json
from matplotlib import pyplot as plt
from island.match import Match
from island.matches import Matches
matches = Matches('wos-data-casual')
labels = ['not enough tr', 'other reason']
percents = [0.0, 0.0]
op = 'D'
def get_reason(m, i, target):
r = m.query('action', 'request').where(lambda x: x['rno'] == i+1 and x['from'] == target).raw_data
rs = m.query('action', 'approve').where(lambda x: x['rno'] == i+1 and x['to'] == target).raw_data
rsn = [n['from'] for n in rs]
for j in r:
if j['to'] not in rsn:
tr = 1440
for k in m.query('action', 'request').where(lambda x: x['rno'] == i+1 and x['from'] == j['to']).raw_data:
tr -= k['tr']
for k in m.query('action', 'cancel').where(lambda x: x['rno'] == i+1 and x['from'] == j['to']).raw_data:
tr += m.query('action', 'request').where(lambda x: x['rno'] == i+1 and x['from'] == j['to'] and x['to'] == k['to'] and x['log_id'] < k['log_id']).orderby('log_id').raw_data[-1]['tr']
for k in m.query('action', 'deny').where(lambda x: x['rno'] == i+1 and x['to'] == j['to']).raw_data:
tr += m.query('action', 'request').where(lambda x: x['rno'] == i+1 and x['from'] == j['to'] and x['to'] == k['from'] and x['log_id'] < k['log_id']).orderby('log_id').raw_data[-1]['tr']
for k in m.query('action', 'approve').where(lambda x: x['rno'] == i+1 and x['from'] == j['to']).raw_data:
tr -= k['tr']
print(tr)
if tr >= j['tr']:
percents[1] += 1
else:
percents[0] += 1
for m in matches.data:
info = m.query('game', 'created').select('info').first()['info']
conf = json.loads(info['config'])
game_end_at = int(info['game_end_at'])
for i in range(1, game_end_at):
calced = set()
for row in m.query('action', 'done').where(lambda x: (x['act_a'] == op or x['act_b'] == op) and x['rno'] == i).raw_data:
if row['act_a'] == op and row['a'] not in calced:
get_reason(m, i, row['a'])
calced.add(row['a'])
if row['act_b'] == op and row['b'] not in calced:
get_reason(m, i, row['b'])
calced.add(row['b'])
_all = sum(percents) / 100
percents[0] /= _all
percents[1] /= _all
plt.figure()
plt.pie(percents, labels=labels, autopct='%1.2f%%', startangle=90)
plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
plt.show()
# plt.savefig('graph/unlink_has_neighbor.png')