""" This file creates a dataset test with 10 species from a real dataset given by G.Gregori

Marjorie ROSCIAN Master CCI 2017-2018


Libraries:
numpy
pandas
os
"""

import numpy as np
import pandas as pd
import os


def donnees():

    """ This function creates a dataset test
    # input :
    # output : data_final is the final dataset test in matrix type (ndarray)
    # other : data1...10 is a dataframe containing data for each group
              data_grouped is a dataframe ordered by the ID of cells
              data_matrix is the same dataset as data_grouped in matrix type
              data1...10 is then the same dataset with only 4 profils : FWS, SWS, FLR, FLO

    """

    # Choose the working directory
    os.chdir('/home/roscian/Bureau/roscian/Documents/PhytoClus/PhytoClusData')

    # Open files
    data1 = pd.DataFrame(pd.read_csv('Background_Noise.csv', sep=","))
    data2 = pd.DataFrame(pd.read_csv('Crypto.csv', sep=","))
    data3 = pd.DataFrame(pd.read_csv('Microeukaryotes.csv', sep=","))
    data4 = pd.DataFrame(pd.read_csv('Nanoeukaryotes.csv', sep=","))
    data5 = pd.DataFrame(pd.read_csv('Picoeukaryotes.csv', sep=","))
    data6 = pd.DataFrame(pd.read_csv('Picoeukaryotes2.csv', sep=","))
    data7 = pd.DataFrame(pd.read_csv('Predators.csv', sep=","))
    data8 = pd.DataFrame(pd.read_csv('Prochlorococcus.csv', sep=","))
    data9 = pd.DataFrame(pd.read_csv('Synechococcus.csv', sep=","))
    data10 = pd.DataFrame(pd.read_csv('Synecho-LowFLR.csv', sep=","))

    # Select  and create each group
    # Group 1
    data_grouped = data1.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data1 = np.asarray(data_matrix)
    for cell in np.arange(0, data1.size):
        data1[cell] = data1[cell][:, [1, 2, 3, 4]]
    print("1")

    # Group 2
    data_grouped = data2.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data2 = np.asarray(data_matrix)
    for cell in np.arange(0, data2.size):
        data2[cell] = data2[cell][:, [1, 2, 3, 4]]
    print("2")

    # Group 3
    data_grouped = data3.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data3 = np.asarray(data_matrix)
    for cell in np.arange(0, data3.size):
        data3[cell] = data3[cell][:, [1, 2, 3, 4]]
    print("3")

    # Group 4
    data_grouped = data4.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data4 = np.asarray(data_matrix)
    for cell in np.arange(0, data4.size):
        data4[cell] = data4[cell][:, [1, 2, 3, 4]]
    print("4")

    # Group 5
    data_grouped = data5.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data5 = np.asarray(data_matrix)
    for cell in np.arange(0, data5.size):
        data5[cell] = data5[cell][:, [1, 2, 3, 4]]
    print("5")

    # Group 6
    data_grouped = data6.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data6 = np.asarray(data_matrix)
    for cell in np.arange(0, data6.size):
        data6[cell] = data6[cell][:, [1, 2, 3, 4]]
    print("6")

    # Group 7
    data_grouped = data7.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data7 = np.asarray(data_matrix)
    for cell in np.arange(0, data7.size):
        data7[cell] = data7[cell][:, [1, 2, 3, 4]]
    print("7")

    # Group 8
    data_grouped = data8.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data8 = np.asarray(data_matrix)
    for cell in np.arange(0, data8.size):
        data8[cell] = data8[cell][:, [1, 2, 3, 4]]
    print("8")

    # Group 9
    data_grouped = data9.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data9 = np.asarray(data_matrix)
    for cell in np.arange(0, data9.size):
        data9[cell] = data9[cell][:, [1, 2, 3, 4]]
    print("9")

    # Group 10
    data_grouped = data10.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data10 = np.asarray(data_matrix)
    for cell in np.arange(0, data10.size):
        data10[cell] = data10[cell][:, [1, 2, 3, 4]]
    print("10")

    # Create the final dataset
    data_final = np.concatenate((data1, data2, data3, data4, data5, data6, data7, data8))

    # Can get a CSV file with :
    # df = pd.DataFrame(data_final)
    # df.to_csv("datTest.csv")

    return data_final
