51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
import json
|
|
from matplotlib import pyplot as plt
|
|
from island.match import Match
|
|
from island.matches import Matches
|
|
import numpy as np
|
|
|
|
|
|
matches = Matches.from_profile_expr(lambda r: 'CLASSIC' in r)
|
|
max_round = 15
|
|
|
|
coopr = []
|
|
yerr_min = []
|
|
yerr_max = []
|
|
x = np.arange(1, max_round+1)
|
|
bx = []
|
|
|
|
survivals = {}
|
|
with open('survivals.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]))
|
|
else:
|
|
coopr.append(0)
|
|
|
|
|
|
plt.figure()
|
|
# plt.errorbar(x, coopr, yerr=[yerr_min, yerr_max], fmt='o', capsize=4)
|
|
# plt.boxplot(bx, showmeans=True, meanline=True)
|
|
plt.plot(x, coopr)
|
|
plt.show()
|
|
# plt.savefig('graph/co_per_round.png')
|