# Path: automlk/context.py
# def get_dataset_folder(dataset_id):
#     """
#     storage folder of the dataset
#     :param dataset_id: id of the dataset
#     :return: folder path (root of the structure)
#     """
#     return get_data_folder() + '/%s' % dataset_id
# 
# Path: automlk/dataset.py
# def get_dataset(dataset_id, include_results=False):
#     """
#     get the descriptive data of a dataset
# 
#     :param dataset_id: id of the dataset
#     :param include_results: if need to extract results also
#     :return: dataset object
#     """
#     dt = make_dataset(get_key_store('dataset:%s' % dataset_id))
#     dt.status = get_key_store('dataset:%s:status' % dataset_id)
# 
#     # add counters and results
#     dt.grapher = get_key_store('dataset:%s:grapher' % dataset_id)
#     dt.round_counter = get_counter_store('dataset:%s:round_counter' % dataset_id)
# 
#     if include_results:
#         dt.results = get_key_store('dataset:%s:results' % dataset_id)
# 
#     return dt
# 
# def get_dataset_sample(dataset_id):
#     """
#     retrieves a sample of the dataset
# 
#     :param dataset_id: dataset id
#     :return: list of records as dictionaries
#     """
#     filename = get_dataset_folder(dataset_id) + '/data/sample.pkl'
#     if os.path.exists(filename):
#         return pickle.load(open(filename, 'rb')).to_dict(orient='records')
#     else:
#         return [{}]


import pickle
import eli5
import pandas as pd
from eli5.sklearn import PermutationImportance
from automlk.context import get_dataset_folder
from automlk.dataset import get_dataset, get_dataset_sample


dataset_id = '37'
round_id = '19'

dataset = get_dataset(dataset_id)
ds = pickle.load(open(get_dataset_folder(dataset_id) + '/data/eval_set.pkl', 'rb'))

folder = get_dataset_folder(dataset_id) + '/models/'

names = list(pickle.load(open(folder + '%s_feature_names.pkl' % round_id, 'rb')))
print(names)

model = pickle.load(open(folder + '%s_model.pkl' % round_id, 'rb'))
pipe_model = pickle.load(open(folder + '%s_pipe_model.pkl' % round_id, 'rb'))
pipe_transform = pickle.load(open(folder + '%s_pipe_transform.pkl' % round_id, 'rb'))


# Path: automlk/context.py
# def get_dataset_folder(dataset_id):
#     """
#     storage folder of the dataset
#     :param dataset_id: id of the dataset
#     :return: folder path (root of the structure)
#     """
#     return get_data_folder() + '/%s' % dataset_id
# 
# Path: automlk/dataset.py
# def get_dataset(dataset_id, include_results=False):
#     """
#     get the descriptive data of a dataset
# 
#     :param dataset_id: id of the dataset
#     :param include_results: if need to extract results also
#     :return: dataset object
#     """
#     dt = make_dataset(get_key_store('dataset:%s' % dataset_id))
#     dt.status = get_key_store('dataset:%s:status' % dataset_id)
# 
#     # add counters and results
#     dt.grapher = get_key_store('dataset:%s:grapher' % dataset_id)
#     dt.round_counter = get_counter_store('dataset:%s:round_counter' % dataset_id)
# 
#     if include_results:
#         dt.results = get_key_store('dataset:%s:results' % dataset_id)
# 
#     return dt
# 
# def get_dataset_sample(dataset_id):
#     """
#     retrieves a sample of the dataset
# 
#     :param dataset_id: dataset id
#     :return: list of records as dictionaries
#     """
#     filename = get_dataset_folder(dataset_id) + '/data/sample.pkl'
#     if os.path.exists(filename):
#         return pickle.load(open(filename, 'rb')).to_dict(orient='records')
#     else:
#         return [{}]


# Path: tests/test_eli5.py
import pickle
import eli5
import pandas as pd
from eli5.sklearn import PermutationImportance
from automlk.context import get_dataset_folder
from automlk.dataset import get_dataset, get_dataset_sample



dataset_id = '37'
round_id = '19'

dataset = get_dataset(dataset_id)
ds = pickle.load(open(get_dataset_folder(dataset_id) + '/data/eval_set.pkl', 'rb'))

folder = get_dataset_folder(dataset_id) + '/models/'

names = list(pickle.load(open(folder + '%s_feature_names.pkl' % round_id, 'rb')))
print(names)

model = pickle.load(open(folder + '%s_model.pkl' % round_id, 'rb'))
pipe_model = pickle.load(open(folder + '%s_pipe_model.pkl' % round_id, 'rb'))
pipe_transform = pickle.load(open(folder + '%s_pipe_transform.pkl' % round_id, 'rb'))


sample = get_dataset_sample(dataset_id)