from island.match import Match from island.matches import Matches import numpy as np import csv import json def calcAndSave(mode, network_type=None): MAX_ROUND = 30 # matches = Matches.from_profile(mode) matches = Matches('wos-data-2022', network_type=network_type) times = np.zeros(MAX_ROUND) cs = np.zeros(MAX_ROUND) crs = [] for m in matches.data: maxr = int(m.query('game', 'created').first()['info']['game_end_at']) c = [0]*maxr 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 c[r - 1] = coop / (len(rows) * 2) crs.append(c) for i in range(MAX_ROUND): if(times[i] == 0): times[i] = 1 cs /= times with open("outputs/CR_%s_%s.csv"%(mode, network_type), 'w') as f: csv.writer(f).writerow(cs) with open("outputs/CRAW_%s_%s.json"%(mode, network_type), 'w') as f: json.dump(crs, f) if __name__ == '__main__': # calcAndSave('CLASSIC') # calcAndSave('SURVIVE') calcAndSave('NEW', 'BA') calcAndSave('NEW', 'WS')