""" This file creates a dataset test with 4 species founded in the A.Malkassian's PhD

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...4 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...4 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('rhodomonas.csv', sep=";"))
    data2 = pd.DataFrame(pd.read_csv('chaetoceros.csv', sep=";"))
    data3 = pd.DataFrame(pd.read_csv('emiliana.csv', sep=";"))
    data4 = pd.DataFrame(pd.read_csv('anabena.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)
    data1 = data1[0:700]
    for cell in np.arange(0, 700):
        data1[cell] = data1[cell][:, [1, 5, 6, 7]]

    # Group 2
    data_grouped = data2.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data2 = np.asarray(data_matrix)
    data2 = data2[0:1150]
    for cell in np.arange(0, 1150):
        data2[cell] = data2[cell][:, [1, 5, 6, 7]]

    # Group 3
    data_grouped = data3.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data3 = np.asarray(data_matrix)
    data3 = data3[0:1450]
    for cell in np.arange(0, 1450):
        data3[cell] = data3[cell][:, [1, 5, 6, 7]]

    # Group 4
    data_grouped = data4.groupby("ID")
    data_matrix = data_grouped.apply(np.array)
    data4 = np.asarray(data_matrix)
    data4 = data4[0:10000]
    for cell in np.arange(0, 593):
        data4[cell] = data4[cell][:, [1, 5, 6, 7]]

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

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

    return data_final
