from island.match import Match from island.matches import Matches import numpy as np import csv def calcAndSave(mode): matches = Matches.from_profile(mode) times = np.zeros(15) cs = np.zeros(15) for m in matches.data: maxr = int(m.query('game', 'created').first()['info']['game_end_at']) for r in range(1, maxr+1): rows = m.query('action', 'done').where(lambda x: x['rno'] == r).raw_data coop = 0 for row in rows: if row['act_a'] == 'C': coop += 1 if row['act_b'] == 'C': coop += 1 if rows: times[r-1] += len(rows) * 2 cs[r-1] += coop for i in range(15): if(times[i] == 0): times[i] = 1 cs /= times with open("outputs/CR_%s.csv"%mode, 'w') as f: csv.writer(f).writerow(cs) if __name__ == '__main__': calcAndSave('CLASSIC') calcAndSave('SURVIVE')