from island.match import Match
from island.matches import Matches
import numpy as np
import csv


def calc(mode):
    matches = Matches.from_profile_expr(lambda a: mode in a)
    trs = 0
    acts = 0
    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
            for row in rows:
                trs += row['tr']
            acts += len(rows)
    return trs, acts, trs / acts


if __name__ == '__main__':
    print(calc('CLASSIC'))
    print(calc('SURVIVE'))

