62 lines
2.6 KiB
Python
62 lines
2.6 KiB
Python
import json
|
|
from matplotlib import pyplot as plt
|
|
from island.match import Match
|
|
from island.matches import Matches
|
|
|
|
matches = Matches('wos-data-new')
|
|
|
|
percents = [0.0, 0.0]
|
|
|
|
op = 'C'
|
|
|
|
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'])
|
|
|
|
print(percents)
|
|
_all = sum(percents) / 100
|
|
percents[0] /= _all
|
|
percents[1] /= _all
|
|
|
|
|
|
labels = ['Insufficient Time Resource', 'Sufficient Time Resource']
|
|
|
|
plt.figure()
|
|
plt.pie(percents, labels=labels, autopct="%1.2f%%", pctdistance=1.1, labeldistance=2,startangle=90, colors=['#00b894', '#fdcb6e'])
|
|
plt.legend()
|
|
plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
|
|
# plt.show()
|
|
plt.savefig("graph/fail_reason_%s.eps"%op) |