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

import sqlalchemy as sqla  # Import knihovny sqlalchemy - pro komunikaci s mysql serverem
import matplotlib.pyplot as plt
import pandas as pd
import pickle
from funkce2 import*
from roc_function import *

""" -------------------------------------------------------------------------------------
POPIS:
vykreslení ozložení hodnot vypočtených metodou lineární korelace a relativní entropie v závislosti na
jednotlivých frekvenčních pásmech
------------------------------------------------------------------------------------- """
#----otevření dat
patient_id = 15
seeg = patient_id


#---pandas read csv
#data18 = pd.read_csv('C:/Users/admin/ownCloud/BakalarskaPrace/cache/connectivity_wm_seeg_018.csv', sep='; ')#connectivity_wm_seeg_018.csv
#data18[data18.keys()[3:-3]] = data18[data18.keys()[3:-3]].apply(pd.to_numeric)

with open('C:/Users/admin/ownCloud/BakalarskaPrace/cache/connectivity_wm_seeg_018.pkl', 'rb') as f:
   data18= pickle.load(f)


#-----
with open('C:/Users/admin/ownCloud/BakalarskaPrace/cache/connectivity_wm_seeg_005_marked.pkl', 'rb') as f:
   data5= pickle.load(f)
with open('C:/Users/admin/ownCloud/BakalarskaPrace/cache/connectivity_wm_seeg_007_marked.pkl', 'rb') as f:
   data7= pickle.load(f)
with open('C:/Users/admin/ownCloud/BakalarskaPrace/cache/connectivity_wm_seeg_015_marked.pkl', 'rb') as f:
    data15 = pickle.load(f)
with open('C:/Users/admin/ownCloud/BakalarskaPrace/cache/connectivity_wm_seeg_018_marked.pkl', 'rb') as f:
    data18 = pickle.load(f)
with open('C:/Users/admin/ownCloud/BakalarskaPrace/cache/connectivity_wm_seeg_032_marked.pkl', 'rb') as f:
    data32 = pickle.load(f)

conn_df = [data5, data7, data15, data18, data32]
conn_df = pd.concat(conn_df)


conn_df[conn_df.keys()[3:-3]] = conn_df[conn_df.keys()[3:-3]].apply(pd.to_numeric)

patient_id = [5,7,15,18,32]

#patient_id = 18
#frames = [df1, df2, df3]
#conn_df.to_pickle('C:/Users/admin/ownCloud/BakalarskaPrace/cache/connectivity_wm_seeg_005_007_015_018_032.pkl')

len(conn_df.loc[conn_df['soz_info'] == 'SOZ'])  # --pro zajímavost
len(conn_df.loc[conn_df['soz_info'] == 'NON_SOZ'])  # --pro zajímavost
len(conn_df.loc[conn_df['soz_info'] == 'BRIDGE'])  # --pro zajímavost

#----analýza - sattistika
from scipy.stats import ttest_ind
bu = conn_df
bu.reset_index(inplace=True)
SOZ_data = bu[bu.soz_info == 'SOZ'].soz_info.values
NON_SOZ_data = bu[bu.soz_info == 'NON_SOZ'].soz_info.values

bu.reset_index(inplace=True)

bu = conn_df.groupby(by=('channel_name_1', 'soz_info')).mean()
bu.reset_index(inplace=True)

len(bu.loc[bu['soz_info'] == 'BRIDGE'])  # --pro zajímavost

bu = conn_df.groupby(by=('soz_info', 'channel_name_1')).mean()


conn_df = data32
conn_df[conn_df.keys()[3:-3]] = conn_df[conn_df.keys()[3:-3]].apply(pd.to_numeric)
patient_id = 32
# #----------vykreslení dat
sns.set_style("whitegrid")

plt.figure()
sns.boxplot(x="low_fc", y="lin_corr_median", hue="soz_info", data=conn_df,  hue_order=["NON_SOZ", "BRIDGE", "SOZ"]).set_title(
    "Pacient cislo %s, lin_corr_median" % (patient_id))

plt.figure()
sns.boxplot(x="low_fc", y="ren_median", hue="soz_info", data=conn_df, hue_order=["NON_SOZ", "BRIDGE", "SOZ"]).set_title(
    "Pacient cislo %s, ren_median" % (patient_id))

plt.figure()
sns.boxplot(x="low_fc", y="phase_sync_median", hue="soz_info", data=conn_df,  hue_order=["NON_SOZ", "BRIDGE", "SOZ"]).set_title(
    "Pacient cislo %s, phase_sync_median" % (patient_id))

plt.figure()
sns.boxplot(x="low_fc", y="phase_const_median", hue="soz_info", data=conn_df,  hue_order=["NON_SOZ", "BRIDGE", "SOZ"]).set_title(
    "Pacient cislo %s, phase_const_median" % (patient_id))

plt.figure()
sns.boxplot(x="low_fc", y="lin_corr_std", hue="soz_info", data=conn_df,  hue_order=["NON_SOZ", "BRIDGE", "SOZ"]).set_title(
    "Pacient cislo %s, lin_corr_std" % (patient_id))

plt.figure()
sns.boxplot(x="low_fc", y="ren_std", hue="soz_info", data=conn_df,  hue_order=["NON_SOZ", "BRIDGE", "SOZ"]).set_title(
    "Pacient cislo %s, ren_std" % (patient_id))

plt.figure()
sns.boxplot(x="low_fc", y="phase_sync_std", hue="soz_info", data=conn_df,  hue_order=["NON_SOZ", "BRIDGE", "SOZ"]).set_title(
    "Pacient cislo %s, phase_sync_std" % (patient_id))

plt.figure()
sns.boxplot(x="low_fc", y="phase_const_std", hue="soz_info", data=conn_df,  hue_order=["NON_SOZ", "BRIDGE", "SOZ"]).set_title(
    "Pacient cislo %s, phase_const_std" % (patient_id))
