swdata/coopr_per_round.py
2018-03-11 17:16:26 +08:00

45 lines
1.1 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')
max_round = 17
coopr = []
yerr_min = []
yerr_max = []
x = []
bx = []
survivals = {}
with open('winner.json','r') as f:
survivals = json.load(f)
for i in range(max_round):
co = []
for j in range(len(matches.data)):
coop = 0
rows = matches.data[j].query('action', 'done').where(lambda x: x['rno']==i+1).raw_data
for row in rows:
if row['act_a'] == 'C' and row['act_b'] == 'C':
coop += 1
if rows:
co.append(float(coop) / float(len(rows)))
bx.append(co)
if co:
coopr.append(sum(co) / len(co))
yerr_min.append(coopr[-1] - min(co))
yerr_max.append(max(co) - coopr[-1])
print("%f, %f, %f"%(yerr_min[-1], yerr_max[-1], coopr[-1]))
x.append(i+1)
plt.figure()
# plt.errorbar(x, coopr, yerr=[yerr_min, yerr_max], fmt='o', capsize=4)
plt.boxplot(bx, showmeans=True, meanline=True)
# plt.show()
plt.savefig('graph/co_per_round.png')