# Path: xcessiv/functions.py
# def hash_file(path, block_size=65536):
# def hash_string(string):
# def import_object_from_path(path, object):
# def import_object_from_string_code(code, object):
# def import_string_code_as_module(code):
# def verify_dataset(X, y):
# def is_valid_json(x):
# def make_serializable(json):
# def get_sample_dataset(dataset_properties):
# def verify_estimator_class(est, meta_feature_generator, metric_generators, dataset_properties):
# def get_path_from_query_string(req):
#     def __init__(self, path):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_val, exc_tb):
# class DBContextManager():
# 
# Path: xcessiv/models.py
# class JsonEncodedDict(TypeDecorator):
# class JsonEncodedList(TypeDecorator):
# class Extraction(Base):
# class BaseLearnerOrigin(Base):
# class AutomatedRun(Base):
# class BaseLearner(Base):
# class StackedEnsemble(Base):
#     def process_bind_param(self, value, dialect):
#     def process_result_value(self, value, dialect):
#     def process_bind_param(self, value, dialect):
#     def process_result_value(self, value, dialect):
#     def __init__(self):
#     def return_main_dataset(self):
#     def return_train_dataset(self):
#     def return_test_dataset(self):
#     def __init__(self, source='', name='Base Learner Setup',
#                  meta_feature_generator='predict_proba', metric_generators=None):
#     def serialize(self):
#     def return_estimator(self):
#     def cleanup(self, path):
#     def export_as_file(self, filepath, hyperparameters):
#     def __init__(self, source, job_status, category, base_learner_origin=None):
#     def serialize(self):
#     def __init__(self, hyperparameters, job_status, base_learner_origin):
#     def return_estimator(self):
#     def meta_features_path(self, path):
#     def serialize(self):
#     def delete_meta_features(self, path):
#     def cleanup(self, path):
#     def export_as_file(self, filepath):
#     def __init__(self, secondary_learner_hyperparameters, base_learners,
#                  base_learner_origin, job_status):
#     def return_secondary_learner(self):
#     def export_as_code(self, cv_source):
#     def export_as_file(self, file_path, cv_source):
#     def export_as_package(self, package_path, cv_source):
#     def serialize(self):
# 
# Path: xcessiv/constants.py
# DEFAULT_EXTRACTION_MAIN_DATASET = {
#     "source": extraction_default_source.format('main', 'main', 'main', 'main')
# }
# DEFAULT_EXTRACTION_TEST_DATASET = {
#     "method": None,
#     "source": extraction_default_source.format('test', 'test', 'test', 'test')
# }
# DEFAULT_EXTRACTION_META_FEATURE_GENERATION = {
#     "source": meta_feature_generation_default_source
# }


from rq import get_current_job
from xcessiv import functions
from xcessiv import models
from xcessiv import constants
from six import iteritems
from bayes_opt import BayesianOptimization
import numpy as np
import os
import sys
import traceback
import numbers
    module = functions.import_string_code_as_module(automated_run.source)
    assert module.metric_to_optimize in automated_run.base_learner_origin.metric_generators

    best_ensemble = []  # List containing IDs of best performing ensemble for the last round

    secondary_learner = automated_run.base_learner_origin.return_estimator()
    secondary_learner.set_params(**module.secondary_learner_hyperparameters)

    for i in range(module.max_num_base_learners):
        best_score = -float('inf')  # Best metric for this round (not in total!)
        current_ensemble = best_ensemble[:]  # Shallow copy of best ensemble
        for base_learner in session.query(models.BaseLearner).filter_by(job_status='finished').all():
            if base_learner in current_ensemble:  # Don't append when learner is already in
                continue
            current_ensemble.append(base_learner)

            # Check if our "best ensemble" already exists
            existing_ensemble = session.query(models.StackedEnsemble).\
                filter_by(base_learner_origin_id=automated_run.base_learner_origin.id,
                          secondary_learner_hyperparameters=secondary_learner.get_params(),
                          base_learner_ids=sorted([bl.id for bl in current_ensemble])).first()

            if existing_ensemble and existing_ensemble.job_status == 'finished':
                score = existing_ensemble.individual_score[module.metric_to_optimize]

            elif existing_ensemble and existing_ensemble.job_status != 'finished':
                eval_stacked_ensemble(existing_ensemble, session, path)
                score = existing_ensemble.individual_score[module.metric_to_optimize]

            else:

# Path: xcessiv/functions.py
# def hash_file(path, block_size=65536):
# def hash_string(string):
# def import_object_from_path(path, object):
# def import_object_from_string_code(code, object):
# def import_string_code_as_module(code):
# def verify_dataset(X, y):
# def is_valid_json(x):
# def make_serializable(json):
# def get_sample_dataset(dataset_properties):
# def verify_estimator_class(est, meta_feature_generator, metric_generators, dataset_properties):
# def get_path_from_query_string(req):
#     def __init__(self, path):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_val, exc_tb):
# class DBContextManager():
# 
# Path: xcessiv/models.py
# class JsonEncodedDict(TypeDecorator):
# class JsonEncodedList(TypeDecorator):
# class Extraction(Base):
# class BaseLearnerOrigin(Base):
# class AutomatedRun(Base):
# class BaseLearner(Base):
# class StackedEnsemble(Base):
#     def process_bind_param(self, value, dialect):
#     def process_result_value(self, value, dialect):
#     def process_bind_param(self, value, dialect):
#     def process_result_value(self, value, dialect):
#     def __init__(self):
#     def return_main_dataset(self):
#     def return_train_dataset(self):
#     def return_test_dataset(self):
#     def __init__(self, source='', name='Base Learner Setup',
#                  meta_feature_generator='predict_proba', metric_generators=None):
#     def serialize(self):
#     def return_estimator(self):
#     def cleanup(self, path):
#     def export_as_file(self, filepath, hyperparameters):
#     def __init__(self, source, job_status, category, base_learner_origin=None):
#     def serialize(self):
#     def __init__(self, hyperparameters, job_status, base_learner_origin):
#     def return_estimator(self):
#     def meta_features_path(self, path):
#     def serialize(self):
#     def delete_meta_features(self, path):
#     def cleanup(self, path):
#     def export_as_file(self, filepath):
#     def __init__(self, secondary_learner_hyperparameters, base_learners,
#                  base_learner_origin, job_status):
#     def return_secondary_learner(self):
#     def export_as_code(self, cv_source):
#     def export_as_file(self, file_path, cv_source):
#     def export_as_package(self, package_path, cv_source):
#     def serialize(self):
# 
# Path: xcessiv/constants.py
# DEFAULT_EXTRACTION_MAIN_DATASET = {
#     "source": extraction_default_source.format('main', 'main', 'main', 'main')
# }
# DEFAULT_EXTRACTION_TEST_DATASET = {
#     "method": None,
#     "source": extraction_default_source.format('test', 'test', 'test', 'test')
# }
# DEFAULT_EXTRACTION_META_FEATURE_GENERATION = {
#     "source": meta_feature_generation_default_source
# }


# Path: xcessiv/automatedruns.py
from rq import get_current_job
from xcessiv import functions
from xcessiv import models
from xcessiv import constants
from six import iteritems
from bayes_opt import BayesianOptimization
import numpy as np
import os
import sys
import traceback
import numbers

    module = functions.import_string_code_as_module(automated_run.source)
    assert module.metric_to_optimize in automated_run.base_learner_origin.metric_generators

    best_ensemble = []  # List containing IDs of best performing ensemble for the last round

    secondary_learner = automated_run.base_learner_origin.return_estimator()
    secondary_learner.set_params(**module.secondary_learner_hyperparameters)

    for i in range(module.max_num_base_learners):
        best_score = -float('inf')  # Best metric for this round (not in total!)
        current_ensemble = best_ensemble[:]  # Shallow copy of best ensemble
        for base_learner in session.query(models.BaseLearner).filter_by(job_status='finished').all():
            if base_learner in current_ensemble:  # Don't append when learner is already in
                continue
            current_ensemble.append(base_learner)

            # Check if our "best ensemble" already exists
            existing_ensemble = session.query(models.StackedEnsemble).\
                filter_by(base_learner_origin_id=automated_run.base_learner_origin.id,
                          secondary_learner_hyperparameters=secondary_learner.get_params(),
                          base_learner_ids=sorted([bl.id for bl in current_ensemble])).first()

            if existing_ensemble and existing_ensemble.job_status == 'finished':
                score = existing_ensemble.individual_score[module.metric_to_optimize]

            elif existing_ensemble and existing_ensemble.job_status != 'finished':
                eval_stacked_ensemble(existing_ensemble, session, path)
                score = existing_ensemble.individual_score[module.metric_to_optimize]

            else:

                stacked_ensemble = models.StackedEnsemble(