# Path: automlk/dataset.py
# def create_dataset(name, folder_id, description, source, mode, filename_train, filename_test='', filename_cols='',
#                    filename_submit='', url=''):
#     """
#     creates a dataset
# 
#     :param name: name of the dataset
#     :param folder_id: folder for classification
#     :param description: description of the dataset
#     :param source: source of the dataset
#     :param mode: standard (train set), benchmark (train + test set), competition (train + submit set)
#     :param filename_train: file path of the training set
#     :param filename_test: name of the test set (benchmark mode)
#     :param filename_cols: file to describe columns
#     :param filename_submit: name of the submit set (competition mode)
#     :param url: url of the dataset
#     :return: dataset object
#     """
# 
#     # create object and control data
#     creation_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 
#     # others = [m for m in other_metrics.replace(' ', '').split(',') if m != '']
#     dt = DataSet(0, name, folder_id, description, source, mode, filename_train,
#                  filename_test=filename_test, filename_cols=filename_cols,
#                  filename_submit=filename_submit,
#                  url=url, creation_date=creation_date)
# 
#     # control data
#     df_cols, df_train, df_test, df_submit = dt.initialize_data()
# 
#     # update stats
#     dt.update_stats(df_train, df_test, df_submit)
# 
#     # save and create objects and graphs related to the dataset
#     dataset_id = str(incr_key_store('dataset:counter'))
#     set_key_store('dataset:%s:status' % dataset_id, 'created')
#     set_key_store('dataset:%s:grapher' % dataset_id, False)
#     set_key_store('dataset:%s:results' % dataset_id, 0)
#     set_key_store('dataset:%s:level' % dataset_id, 1)
#     rpush_key_store('dataset:list', dataset_id)
# 
#     dt.save(dataset_id)
#     dt.create_folders()
#     dt.finalize_creation(df_train, df_test, df_submit)
# 
#     return dt


import pandas as pd
from automlk.dataset import create_dataset

"""
loads a dataset from a csv file description
"""

for line in pd.read_csv('../datasets/datasets.csv').fillna('').to_dict(orient='records'):
    print('-'*60)
    print('creating dataset %s in %s' % (line['name'], line['problem_type']))
    line['other_metrics'] = line['other_metrics'].replace(' ', '').split(',')

# Path: automlk/dataset.py
# def create_dataset(name, folder_id, description, source, mode, filename_train, filename_test='', filename_cols='',
#                    filename_submit='', url=''):
#     """
#     creates a dataset
# 
#     :param name: name of the dataset
#     :param folder_id: folder for classification
#     :param description: description of the dataset
#     :param source: source of the dataset
#     :param mode: standard (train set), benchmark (train + test set), competition (train + submit set)
#     :param filename_train: file path of the training set
#     :param filename_test: name of the test set (benchmark mode)
#     :param filename_cols: file to describe columns
#     :param filename_submit: name of the submit set (competition mode)
#     :param url: url of the dataset
#     :return: dataset object
#     """
# 
#     # create object and control data
#     creation_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 
#     # others = [m for m in other_metrics.replace(' ', '').split(',') if m != '']
#     dt = DataSet(0, name, folder_id, description, source, mode, filename_train,
#                  filename_test=filename_test, filename_cols=filename_cols,
#                  filename_submit=filename_submit,
#                  url=url, creation_date=creation_date)
# 
#     # control data
#     df_cols, df_train, df_test, df_submit = dt.initialize_data()
# 
#     # update stats
#     dt.update_stats(df_train, df_test, df_submit)
# 
#     # save and create objects and graphs related to the dataset
#     dataset_id = str(incr_key_store('dataset:counter'))
#     set_key_store('dataset:%s:status' % dataset_id, 'created')
#     set_key_store('dataset:%s:grapher' % dataset_id, False)
#     set_key_store('dataset:%s:results' % dataset_id, 0)
#     set_key_store('dataset:%s:level' % dataset_id, 1)
#     rpush_key_store('dataset:list', dataset_id)
# 
#     dt.save(dataset_id)
#     dt.create_folders()
#     dt.finalize_creation(df_train, df_test, df_submit)
# 
#     return dt


# Path: run/dataset_loader.py
import pandas as pd
from automlk.dataset import create_dataset


"""
loads a dataset from a csv file description
"""

for line in pd.read_csv('../datasets/datasets.csv').fillna('').to_dict(orient='records'):
    print('-'*60)
    print('creating dataset %s in %s' % (line['name'], line['problem_type']))
    line['other_metrics'] = line['other_metrics'].replace(' ', '').split(',')

    dt = create_dataset(**line)