#
# This program is distributed without any warranty and it
# can be freely redistributed for research, classes or private studies,
# since the copyright notices are not removed.
#
# This file just read the data to calculate the statistical test
#
# Jadson Santos - jadsonjs@gmail.com
# 
# to run this exemple install pyhton modules:
#
# pip3 install pandas
#

# Python Data Analysis Library
# https://pandas.pydata.org
import pandas as pd

# This module provides functions for calculating mathematical statistics of numeric (Real-valued) data.
# https://docs.python.org/3/library/statistics.html
import statistics 
  

#
# PUT THE RESULT DIRECTORY AND ENSEMBLE ALGORITHM GENEREATED BY WEKA ON HERE
#
# read the CSV file with your data base and put into a Pandas DataFrame 
# https://www.shanelynn.ie/using-pandas-dataframe-creating-editing-viewing-data-in-python/
#

directory = '/Users/jadson/tmp/results/'  # where are the files generated by weka

#
# prints the data of all homogeneous ensemble 
#
def printHomogeneo():
    for model in ['knn', 'ad', 'nb', 'mlp']:
        for ensemble in ['bagging', 'boosting', 'stacking_homogeneo']:

            print(' -------------------- ')
            print(model+' --> '+ensemble)
            print(' -------------------- ')

            for num_classifiers in [10, 15, 20]:
                df = pd.read_csv( directory+ensemble+'_'+model+'_'+str(num_classifiers)+'.csv' )

                #Getting the precision data
                precision = df['IR_precision'].values

                # {0} is the num of argument of format function : {.4} sets the precision to 4 decimals.
                for p in range(len(precision)):
                    print('{0:.4}'.format(precision[p])) 


#
# prints the data of all heterogeneous ensemble 
#
def printHeterogeneo():
    for ensemble in ['stacking_heterogeneo']:

        print(' -------------------- ')
        print(ensemble)
        print(' -------------------- ')

        for model in ['MLP_AD', 'MLP_NB', 'MLP_NB_AD', 'NB_AD']:

            for num_classifiers in [10, 15, 20]:
                df = pd.read_csv( directory+ensemble+'_'+model+'_'+str(num_classifiers)+'.csv' )

                #Getting the precision data
                precision = df['IR_precision'].values

                # {0} is the num of argument of format function : {.4} sets the precision to 4 decimals.
                for p in range(len(precision)):
                    print('{0:.4}'.format(precision[p])) 



printHomogeneo()
printHeterogeneo()


print the to calc statistical test