# Path: automlk/store.py
# def exists_key_store(key):
#     """
#     checks if a key exists
# 
#     :param key: key of the data
#     :return: True if the key exists else False
#     """
#     if get_use_redis():
#         return rds.exists(str(key))
#     else:
#         return os.path.exists(store_folder + '/' + __clean_key(key) + '.json')
# 
# def get_key_store(key):
#     """
#     retieves value from key in store
# 
#     :param key: key of the data
#     :return: value of the data
#     """
#     if get_use_redis():
#         return json.loads(rds.get(str(key)))
#     else:
#         try:
#             if exists_key_store(key):
#                 return json.load(open(store_folder + '/' + __clean_key(key) + '.json', 'r'))
#             else:
#                 return None
#         except:
#             return None
# 
# Path: automlk/dataset.py
# def get_dataset_ids():
# def get_dataset_list(include_results=False):
# def get_dataset_status(dataset_id):
# def get_dataset(dataset_id, include_results=False):
# def make_dataset(d):
# def create_dataset_json(dataset_id):
# def create_dataset(name, folder_id, description, source, mode, filename_train, filename_test='', filename_cols='',
#                    filename_submit='', url=''):
# def update_dataset(dataset_id, name, folder_id, description, source, url):
# def update_feature_dataset(dataset_id, name, description, to_keep, col_type, text_ref):
# def update_problem_dataset(dataset_id, problem_type, y_col, metric, other_metrics, val_col, cv_folds, val_col_shuffle,
#                            scan, holdout_ratio, col_submit):
# def reset_dataset(dataset_id):
# def delete_dataset(dataset_id):
# def get_dataset_sample(dataset_id):
#     def __init__(self, dataset_id, name, folder_id, description, source, mode, filename_train,
#                  filename_test, filename_cols, filename_submit, url, creation_date):
#     def initialize_data(self):
#     def update_stats(self, df_train, df_test, df_submit):
#     def update_calc(self):
#     def update_problem(self, problem_type, y_col, metric, other_metrics, val_col, cv_folds, val_col_shuffle, scan,
#                        holdout_ratio, col_submit, best_is_min=True):
#     def update_y_data(self):
#     def save(self, dataset_id):
#     def load(self, load_data, features):
#     def load_calc(self, calc_data):
#     def finalize_creation(self, df_train, df_test, df_submit):
#     def get_data(self, part='train'):
#     def create_folders(self):
#     def __folder(self):
#     def __check_data(self, filename, part='train'):
#     def __read_data(self, filename):
#     def __initialize_features(self, df, df_cols):
#     def update_features(self, df):
#     def __import_data(self, filename, part):
#     def __init__(self, name, raw_type, n_missing, n_unique_values, first_unique_values, description, to_keep,
#                  col_type, text_ref='', n_unique_ratio=0.):
# def get_y_eval(dataset_id):
# class DataSet(object):
# class Feature(object):
# 
# Path: automlk/prepare.py
# def get_idx_train_test(dataset_id):
#     """
#     get the index of the train and test set from the original train set
# 
#     :param dataset_id: id of the dataset
#     :return: train index, test index
#     """
#     return pickle.load(open(get_dataset_folder(dataset_id) + '/data/i_train_test.pkl', 'rb'))
# 
# def get_eval_sets(dataset_id):
#     """
#     get the complete eval set
# 
#     :param dataset_id: id of the dataset
#     :return: eval set (XySet object)
#     """
#     return pickle.load(open(get_dataset_folder(dataset_id) + '/data/eval_set.pkl', 'rb'))


import pickle
import json
import pandas as pd
import numpy as np
from .store import exists_key_store, get_key_store
from .dataset import get_dataset_list, get_dataset_folder, get_dataset
from .prepare import get_idx_train_test, get_eval_sets
    return pickle.load(open(get_dataset_folder(dataset_id) + '/predict/%s.pkl' % round_id, 'rb'))


def print_value(x):
    # easy print function for dictionary value
    return ('%6.4f' % x).rstrip('0').rstrip('.') if isinstance(x, float) else str(x)


def get_home_best():
    # get the list of datasets with their best results
    datasets = get_dataset_list(include_results=True)[::-1]
    for dt in datasets:
        if dt.status != 'created':
            best = get_best_models(dt.dataset_id)
            if len(best) > 0:
                best = best[0]
                dt.best_round_id = best['round_id']
                dt.best_model_name = best['model_name']
                dt.best_score_eval = best['score_eval']
                dt.best_score_test = best['score_test']
                dt.best_cv_mean = best['cv_mean']
                dt.best_cv_std = best['cv_std']
                dt.best_cv_max = best['cv_max']
    return datasets


def get_best_models(dataset_id):
    # get the best results per model
    key = 'dataset:%s:best' % dataset_id
    if exists_key_store(key):

# Path: automlk/store.py
# def exists_key_store(key):
#     """
#     checks if a key exists
# 
#     :param key: key of the data
#     :return: True if the key exists else False
#     """
#     if get_use_redis():
#         return rds.exists(str(key))
#     else:
#         return os.path.exists(store_folder + '/' + __clean_key(key) + '.json')
# 
# def get_key_store(key):
#     """
#     retieves value from key in store
# 
#     :param key: key of the data
#     :return: value of the data
#     """
#     if get_use_redis():
#         return json.loads(rds.get(str(key)))
#     else:
#         try:
#             if exists_key_store(key):
#                 return json.load(open(store_folder + '/' + __clean_key(key) + '.json', 'r'))
#             else:
#                 return None
#         except:
#             return None
# 
# Path: automlk/dataset.py
# def get_dataset_ids():
# def get_dataset_list(include_results=False):
# def get_dataset_status(dataset_id):
# def get_dataset(dataset_id, include_results=False):
# def make_dataset(d):
# def create_dataset_json(dataset_id):
# def create_dataset(name, folder_id, description, source, mode, filename_train, filename_test='', filename_cols='',
#                    filename_submit='', url=''):
# def update_dataset(dataset_id, name, folder_id, description, source, url):
# def update_feature_dataset(dataset_id, name, description, to_keep, col_type, text_ref):
# def update_problem_dataset(dataset_id, problem_type, y_col, metric, other_metrics, val_col, cv_folds, val_col_shuffle,
#                            scan, holdout_ratio, col_submit):
# def reset_dataset(dataset_id):
# def delete_dataset(dataset_id):
# def get_dataset_sample(dataset_id):
#     def __init__(self, dataset_id, name, folder_id, description, source, mode, filename_train,
#                  filename_test, filename_cols, filename_submit, url, creation_date):
#     def initialize_data(self):
#     def update_stats(self, df_train, df_test, df_submit):
#     def update_calc(self):
#     def update_problem(self, problem_type, y_col, metric, other_metrics, val_col, cv_folds, val_col_shuffle, scan,
#                        holdout_ratio, col_submit, best_is_min=True):
#     def update_y_data(self):
#     def save(self, dataset_id):
#     def load(self, load_data, features):
#     def load_calc(self, calc_data):
#     def finalize_creation(self, df_train, df_test, df_submit):
#     def get_data(self, part='train'):
#     def create_folders(self):
#     def __folder(self):
#     def __check_data(self, filename, part='train'):
#     def __read_data(self, filename):
#     def __initialize_features(self, df, df_cols):
#     def update_features(self, df):
#     def __import_data(self, filename, part):
#     def __init__(self, name, raw_type, n_missing, n_unique_values, first_unique_values, description, to_keep,
#                  col_type, text_ref='', n_unique_ratio=0.):
# def get_y_eval(dataset_id):
# class DataSet(object):
# class Feature(object):
# 
# Path: automlk/prepare.py
# def get_idx_train_test(dataset_id):
#     """
#     get the index of the train and test set from the original train set
# 
#     :param dataset_id: id of the dataset
#     :return: train index, test index
#     """
#     return pickle.load(open(get_dataset_folder(dataset_id) + '/data/i_train_test.pkl', 'rb'))
# 
# def get_eval_sets(dataset_id):
#     """
#     get the complete eval set
# 
#     :param dataset_id: id of the dataset
#     :return: eval set (XySet object)
#     """
#     return pickle.load(open(get_dataset_folder(dataset_id) + '/data/eval_set.pkl', 'rb'))


# Path: automlk/results.py
import pickle
import json
import pandas as pd
import numpy as np
from .store import exists_key_store, get_key_store
from .dataset import get_dataset_list, get_dataset_folder, get_dataset
from .prepare import get_idx_train_test, get_eval_sets

    return pickle.load(open(get_dataset_folder(dataset_id) + '/predict/%s.pkl' % round_id, 'rb'))


def print_value(x):
    # easy print function for dictionary value
    return ('%6.4f' % x).rstrip('0').rstrip('.') if isinstance(x, float) else str(x)


def get_home_best():
    # get the list of datasets with their best results
    datasets = get_dataset_list(include_results=True)[::-1]
    for dt in datasets:
        if dt.status != 'created':
            best = get_best_models(dt.dataset_id)
            if len(best) > 0:
                best = best[0]
                dt.best_round_id = best['round_id']
                dt.best_model_name = best['model_name']
                dt.best_score_eval = best['score_eval']
                dt.best_score_test = best['score_test']
                dt.best_cv_mean = best['cv_mean']
                dt.best_cv_std = best['cv_std']
                dt.best_cv_max = best['cv_max']
    return datasets


def get_best_models(dataset_id):
    # get the best results per model
    key = 'dataset:%s:best' % dataset_id
    if exists_key_store(key):

        return get_key_store(key)