import csv
from math import floor
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import colors
from matplotlib import cm

data = np.loadtxt('outputs/decision.csv', delimiter=',')
# print(data)
print(data.shape)
ndata = np.zeros(shape=(6, 45))
for i in range(data.shape[0]):
    ans = floor(data[i, 0]) - 1
    if ans < 0:
        ans = 0
    elif ans >= 45:
        ans = 44
    ndata[int(data[i, 1]),  ans] += 1

print(ndata[4,11])


for i in range(ndata.shape[0]):
    for j in range(ndata.shape[1]):
        if ndata[i,j] == 0:
            ndata[i,j] = np.nan

# ndata = np.log(ndata+1)
# ndata += 1
fig = plt.figure()
ax = fig.gca()
# ax.set_xlabel()
ax.set_facecolor('white')
ax.set_xticks(np.arange(0,45,11))
colors = cm.get_cmap('OrRd')
colors.set_bad('white')
ax.set_xticklabels(np.arange(1, 46, 11))
dct = ax.imshow(ndata, cmap=colors, origin='lower')#, norm=colors.LogNorm())
# sc = ax.scatter(np.arange(7, 45), np.floor(45 / np.arange(8, 46)), s=20, facecolors='none', edgecolors='black', linewidths=0.75, linestyle='dotted', label='Maximal number of opponents')
# ax.scatter(np.arange(0, 7), [5]*7, s=20, facecolors='none', edgecolors='black', linewidths=0.75, linestyle='dotted')
# for i in range(0,7):
#     print(f"{i}: {floor(45/(i+1))}\n")
# plt.legend()
# ax2 = ax.twinx()
# ax2.set_ylabel("Maximal Number of opponents")
ax.set_xlabel("Average Decision time", fontsize=11)
ax.set_ylabel("Number of partners", fontsize=11)
ax.tick_params(labelsize=10)
ax.reset_position()
fig.set_size_inches(6,5)
fig.colorbar(dct, ax=ax, orientation='horizontal', aspect=30, shrink=1)

# plt.show()
# print(plt.rcParams)
plt.savefig('graph/decision_time.eps')
