# 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/worker.py
# def get_search_rounds(dataset_id):
#     """
#     get all the results of the search with preprocessing and models
# 
#     :param dataset_id: id of the dataset
#     :return: results of the search as a dataframe
#     """
#     results = list_key_store('dataset:%s:rounds' % dataset_id)
#     return pd.DataFrame(results)


import os
import sys
import glob
import zipfile
import pandas as pd
import numpy as np
import jinja2
import subprocess
from .context import get_dataset_folder
from .results import *
from automlk.worker import get_search_rounds
from .print import *
    """
    t = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath="../automlk/templates/")).get_template(template)
    with open(fileout, 'w') as f:
        f.write(t.render({**kwargs, **jinja_globals}))


def gener_doc(dataset):
    """
    generate the documentation of this dataset

    :param dataset: dataset object
    :return:
    """
    # check or create doc folder
    folder = get_dataset_folder(dataset.dataset_id) + '/docs'
    if not os.path.exists(folder):
        os.makedirs(folder)
        os.makedirs(folder + '/_build')
        os.makedirs(folder + '/_static')
        os.makedirs(folder + '/_templates')

    # generate conf.py
    render('conf.txt', folder + '/conf.py', dataset=dataset)
    render('make.bat', folder + '/make.bat', dataset=dataset)
    render('makefile.txt', folder + '/Makefile', dataset=dataset)

    # generate index
    render('index.rst', folder + '/index.rst', dataset=dataset)

    # dataset data and features

# 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/worker.py
# def get_search_rounds(dataset_id):
#     """
#     get all the results of the search with preprocessing and models
# 
#     :param dataset_id: id of the dataset
#     :return: results of the search as a dataframe
#     """
#     results = list_key_store('dataset:%s:rounds' % dataset_id)
#     return pd.DataFrame(results)


# Path: automlk/doc.py
import os
import sys
import glob
import zipfile
import pandas as pd
import numpy as np
import jinja2
import subprocess
from .context import get_dataset_folder
from .results import *
from automlk.worker import get_search_rounds
from .print import *

    """
    t = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath="../automlk/templates/")).get_template(template)
    with open(fileout, 'w') as f:
        f.write(t.render({**kwargs, **jinja_globals}))


def gener_doc(dataset):
    """
    generate the documentation of this dataset

    :param dataset: dataset object
    :return:
    """
    # check or create doc folder
    folder = get_dataset_folder(dataset.dataset_id) + '/docs'
    if not os.path.exists(folder):
        os.makedirs(folder)
        os.makedirs(folder + '/_build')
        os.makedirs(folder + '/_static')
        os.makedirs(folder + '/_templates')

    # generate conf.py
    render('conf.txt', folder + '/conf.py', dataset=dataset)
    render('make.bat', folder + '/make.bat', dataset=dataset)
    render('makefile.txt', folder + '/Makefile', dataset=dataset)

    # generate index
    render('index.rst', folder + '/index.rst', dataset=dataset)

    # dataset data and features

    search = get_search_rounds(dataset.dataset_id)