""" 统计所有的连通子图规模 """ import csv import numpy as np from collections import Counter from island.matches import Matches from island.match import Match class ClusterStat: def __init__(self): self.detail = {} # self.matches = Matches.from_profile_expr(lambda r: True) self.matches = Matches.from_profile('SURVIVE') def stat(self): for m in self.matches.data: cluster = {} no = 0 for r in m.query('player','join').raw_data: cluster[r['pid']] = no no += 1 for r in m.query('action', 'done').raw_data: if cluster[r['a']] != cluster[r['b']]: if cluster[r['a']] < cluster[r['b']]: cmax, cmin = cluster[r['b']], cluster[r['a']] else: cmax, cmin = cluster[r['a']], cluster[r['b']] lmax = [k for (k,v) in cluster.items() if v == cmax] for k in lmax: cluster[k] = cmin res = [v for v in Counter(cluster.values()).values()] print(m.name, list(sorted(res, reverse=True))) self.detail[m.name] = res if __name__ == '__main__': c = ClusterStat() c.stat()