#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-

from roc_function import *
from funkce2 import *
from lib.utilities import load_or_get

"""--------------------
POPIS:
vytvoření ROC křivek pro vybrané pacienty, pro každého všechny algoritmy
-------------------------------------------------------------------------------------"""
databases = [ 'LL_alg_Fnusa', 'Matt_alg_Fnusa', 'hilbert_alg_v2']

#-----volba parametrů
patients = range(2, 17) #patients = range(2, 34) #range je bez posledního
patients = [5, 7, 15, 18, 32]
database = databases[2] #volba 0, 1, 2
#-----

fpr_ll = dict()
tpr_ll = dict()
fpr_matt = dict()
tpr_matt = dict()
fpr_hilbert = dict()
tpr_hilbert = dict()
total_count = dict()
doctor = dict()


for vybrany_pacient in patients:
    try:
        fpr_ll[vybrany_pacient], tpr_ll[vybrany_pacient], total_count[vybrany_pacient], doctor[vybrany_pacient] = load_or_get(roc, databases[0], vybrany_pacient, vybrany_pacient, 'channel_name') #total_count[vybrany_pacient], doctor[vybrany_pacient] NECHCI
        fpr_matt[vybrany_pacient], tpr_matt[vybrany_pacient], total_count[vybrany_pacient], doctor[vybrany_pacient] = load_or_get(roc, databases[1], vybrany_pacient, vybrany_pacient, 'channel_name') #total_count[vybrany_pacient], doctor[vybrany_pacient] NECHCI
        fpr_hilbert[vybrany_pacient], tpr_hilbert[vybrany_pacient], total_count[vybrany_pacient], doctor[vybrany_pacient] = load_or_get(roc, databases[2], vybrany_pacient, vybrany_pacient, 'channel_name') #total_count[vybrany_pacient], doctor[vybrany_pacient] NECHCI
    except: pass

print(repr(fpr_ll))

#---vykreslení grafu
size = determine_graph_sizes(len(patients))
#size1 = 6
#size2 = 3


plt.figure('ROC')
i = 1
for patient in patients:
    try:
        plt.subplot(size, size, i) #případně size1, size2

        i += 1

        plt.title('Pacient cislo ' + str(patient))

        fpr_one_patient_ll = fpr_ll.get(patient)
        tpr_one_patient_ll = tpr_ll.get(patient)
        fpr_one_patient_matt = fpr_matt.get(patient)
        tpr_one_patient_matt = tpr_matt.get(patient)
        fpr_one_patient_hilbert = fpr_hilbert.get(patient)
        tpr_one_patient_hilbert = tpr_hilbert.get(patient)

        curve = plt.plot(fpr_one_patient_ll, tpr_one_patient_ll, 'r', fpr_one_patient_matt, tpr_one_patient_matt, 'g', fpr_one_patient_hilbert, tpr_one_patient_hilbert, 'b')

        #plt.gca().set_axis_bgcolor("#E0FFFF"); #bílé pozadí

        #plt.setp(curve, 'color', 'g', 'linewidth', 2.0, 'marker', '+')#, 'linestyle', '--'
        plt.setp(curve, 'linewidth', 2.0, 'marker', '+')#, 'linestyle', '--'
    except: pass
plt.legend([databases[0], databases[1],databases[2]], bbox_to_anchor=(1.04,1), loc="lower left") # bbox_to_anchor=(1, 0.5))
#plt.xlabel('False Positive Rate')
#plt.ylabel('True Positive Rate')
plt.show()





''' #nebo mnooohem hezčí vykreslení
sns.set(style="ticks")

# Create a dataset with many short random walks
rs = np.random.RandomState(4)
pos = rs.randint(-1, 2, (20, 5)).cumsum(axis=1)
pos -= pos[:, 0, np.newaxis]
step = np.tile(range(5), 20)
walk = np.repeat(range(20), 5)
df = pd.DataFrame(np.c_[pos.flat, step, walk],
                  columns=["position", "step", "walk"])


# Initialize a grid of plots with an Axes for each walk
grid = sns.FacetGrid(df, col="walk", hue="walk", col_wrap=5, size=1.5)

# Draw a horizontal line to show the starting point
grid.map(plt.axhline, y=0, ls=":", c=".5")

# Draw a line plot to show the trajectory of each random walk
grid.map(plt.plot, "step", "position", marker="o", ms=4)

# Adjust the tick positions and labels
grid.set(xticks=np.arange(5), yticks=[-3, 3],
         xlim=(-.5, 4.5), ylim=(-3.5, 3.5))

# Adjust the arrangement of the plots
grid.fig.tight_layout(w_pad=1)

'''
