import json
from matplotlib import pyplot as plt
from island.match import Match
from island.matches import Matches
from numpy import mean, std
import numpy as np


matches = Matches('wos-data-new-2')
max_round = 15



fig = plt.figure(figsize=(6.4, 3.6))
ax = fig.gca()
index = np.arange(13)
ax.set_xlabel('k')
ax.set_ylabel('p(k)')

c = ['#00b894','#00cec9','#0984e3','#6c5ce7','#e84393','#d63031','#e17055','#fdcb6e','#2d3436','#6ab04c','#30336b','#ED4C67']

for i in range(len(matches.data)):
    k = np.zeros(13)
    m = matches.data[i]
    n = {}
    for r in m.query('neighbor', 'create').raw_data:
        if r['a'] in n:
            n[r['a']].append(r['b'])
        else:
            n[r['a']] = [r['b']]

        if r['b'] in n:
            n[r['b']].append(r['a'])
        else:
            n[r['b']] = [r['a']]
    for j in n.keys():
        print(n[j], len(n[j]))
        k[len(n[j])] += 1
    pk = k / np.sum(k)
    print(i)
    # ax.scatter(index, pk, color=c[i])
    ax.scatter(index, pk)

# ax.set_title('Scores by group and gender')
fig.tight_layout()
plt.show()
# plt.savefig('graph/neigh_per_round.eps')