Exemplo n.º 1
0
 def post(username):
     try:
         content = request.get_json()
         # if type, host, and port are provided, setup experiment database and update user
         if 'host' in content['db_configuration'] and 'port' in content[
                 'db_configuration'] and 'type' in content[
                     'db_configuration']:
             setup_experiment_database(
                 str(content['db_configuration']['type']),
                 str(content['db_configuration']['host']),
                 str(content['db_configuration']['port']))
             user_db().update_user(content)
             # start execution scheduler using updated config
             initialize_execution_scheduler(10)
             resp = jsonify({
                 "message":
                 "Update successful",
                 "token":
                 jwt.encode({"user": content}, key, algorithm="HS256")
             })
             resp.status_code = 200
             return resp
         else:
             resp = jsonify(
                 {"message": "Host and/or port values are missing"})
             resp.status_code = 404
             return resp
     except ConnectionError as e:
         resp = jsonify({"message": e.message})
         resp.status_code = 404
         return resp
Exemplo n.º 2
0
    def post():
        try:
            content = request.get_json()
            username = content["username"]
            password = content["password"]
            if len(username) != 0 and len(password) != 0:
                user_info_without_id = user_db().get_user(username)[1]
                print user_info_without_id
                if len(user_info_without_id) is not 0:
                    # assuming that only one user is returned from DB
                    user_info_without_id = user_info_without_id[0]
                    if check_password_hash(user_info_without_id['password'],
                                           password):
                        del user_info_without_id['password']
                        encoded_jwt = jwt.encode(
                            {"user": user_info_without_id},
                            key,
                            algorithm="HS256")

                        if 'host' in user_info_without_id[
                                'db_configuration'] and 'port' in user_info_without_id[
                                    'db_configuration'] and 'type' in user_info_without_id[
                                        'db_configuration']:
                            # if user is logged-in, and configured experiments database previously:
                            # initialize experiment database and start execution scheduler if they are not done before
                            if db() is None:
                                setup_experiment_database(
                                    str(user_info_without_id[
                                        'db_configuration']['type']),
                                    str(user_info_without_id[
                                        'db_configuration']['host']),
                                    str(user_info_without_id[
                                        'db_configuration']['port']))
                            if get_execution_scheduler_timer() is None:
                                initialize_execution_scheduler(10)

                        # return the usual jwt token
                        return {"token": encoded_jwt}, 200
                    else:
                        return {
                            "message": "Provided credentials are not correct"
                        }, 403
                else:
                    return {
                        "message":
                        "User does not exist. Please register first."
                    }, 404
            else:
                return {"message": "Invalid information"}, 404
        except Exception as e:
            tb = traceback.format_exc()
            print(tb)
            return {"message": e.message}, 404
Exemplo n.º 3
0
 def test_a_db_1(self):
     config = parse_config(["oeda", "databases"], "experiment_db_config")
     self.assertTrue(config)
     self.assertTrue(config["host"])
     self.assertTrue(config["port"])
     self.assertTrue(config["index"]["name"])
     UnitTest.elasticsearch_index = config["index"]["name"] + "_test"
     UnitTest.elasticsearch_ip = str(config["host"])
     UnitTest.elasticsearch_port = str(config["port"])
     setup_experiment_database("elasticsearch",
                               UnitTest.elasticsearch_ip,
                               UnitTest.elasticsearch_port,
                               for_tests=True)
     self.assertTrue(db())
Exemplo n.º 4
0

def check_homogenity_of_variance_assumption(experiment_id, step_no, key,
                                            alpha):
    stage_ids, samples, knobs = get_tuples(experiment_id, step_no, key)
    statistic, pvalue = stats.levene(*samples)
    # Levene's test of homogeneity of variance is non-significant which indicates that the groups have equal variances
    if pvalue < alpha:
        return False
    return True


if __name__ == '__main__':
    nrOfImportantFactors = 3  # to be retrieved from analysis definition
    alpha = 0.05  # to be retrieved from analysis definition
    setup_experiment_database("elasticsearch", "localhost", 9200)
    experiment_id = "076861f3-b77b-d1a3-90c4-cc34c00712aa"
    experiment = db().get_experiment(experiment_id)
    pp.pprint(experiment)
    ttest_step_no = experiment["numberOfSteps"]

    anova_step_no = "1"  # 1 denotes step-strategy phase for ANOVA, last one denotes T-test, intermediate ones denote Bayesian Opt
    key = "fuelConsumption"
    # test_data_points(experiment_id, step_no)
    # start_workflow_with_anova(experiment_id, anova_step_no, key, alpha, nrOfImportantFactors, 'self-optimizer', True)
    # start_workflow_with_ttest(experiment_id=experiment_id, key=key, alpha=alpha)

    # normality = check_normality_assumption(experiment_id, anova_step_no, key, alpha)
    # hom_var = check_homogenity_of_variance_assumption(experiment_id, anova_step_no, key, alpha)
    # print("Normality of ANOVA", normality)
    # print("Homogenity of variances ANOVA", hom_var)
Exemplo n.º 5
0
    def post():
        try:
            content = request.get_json()
            username = content["username"]
            password = content["password"]

            if len(username) != 0 and len(password) != 0:
                users = user_db().get_user(username)
                if users is not None:
                    user_info_without_id = users[0]
                    print(user_info_without_id)
                    if check_password_hash(user_info_without_id['password'],
                                           password):
                        del user_info_without_id['password']
                        encoded_jwt = jwt.encode(
                            {"user": user_info_without_id},
                            key,
                            algorithm="HS256")

                        if 'host' in user_info_without_id[
                                'db_configuration'] and 'port' in user_info_without_id[
                                    'db_configuration'] and 'type' in user_info_without_id[
                                        'db_configuration']:
                            # if user is logged-in, and configured experiments database previously:
                            # initialize experiment database and start execution scheduler if they are not done before
                            if experiments_db() is None:
                                try:
                                    setup_experiment_database(
                                        str(user_info_without_id[
                                            'db_configuration']['type']),
                                        str(user_info_without_id[
                                            'db_configuration']['host']),
                                        str(user_info_without_id[
                                            'db_configuration']['port']))
                                except:
                                    return {
                                        "message":
                                        "Experiments database configuration needs to be set before proceeding"
                                    }, 500

                            if get_execution_scheduler_timer() is None:
                                initialize_execution_scheduler(10)
                        else:
                            print('emptiness')
                            user_info_without_id['db_configuration'] = {}
                            user_info_without_id['db_configuration'][
                                'type'] = "elasticsearch"
                            user_info_without_id['db_configuration'][
                                'host'] = "localhost"
                            user_info_without_id['db_configuration'][
                                'port'] = 9200

                            if experiments_db() is None:
                                try:
                                    setup_experiment_database(
                                        str(user_info_without_id[
                                            'db_configuration']['type']),
                                        str(user_info_without_id[
                                            'db_configuration']['host']),
                                        str(user_info_without_id[
                                            'db_configuration']['port']))
                                except:
                                    return {
                                        "message":
                                        "Experiments database configuration needs to be set before proceeding"
                                    }, 500

                            if get_execution_scheduler_timer() is None:
                                initialize_execution_scheduler(10)
                        # return the usual jwt token
                        return {"token": str(encoded_jwt)}, 200
                    else:
                        return {
                            "message": "Provided credentials are not correct"
                        }, 403
                else:
                    return {
                        "message":
                        "User does not exist. Please register first."
                    }, 404

                # try with elasticsearch for backward compatibility TODO?
                # user_info_without_id = single_user[1]
                # #print(user_info_without_id)
                # if len(user_info_without_id) is not 0:
                #     # assuming that only one user is returned from DB
                #     user_info_without_id = user_info_without_id[0]
                #     if check_password_hash(user_info_without_id['password'], password):
                #         del user_info_without_id['password']
                #         encoded_jwt = jwt.encode({"user": user_info_without_id}, key, algorithm="HS256")
                #
                #         if 'host' in user_info_without_id['db_configuration'] and 'port' in user_info_without_id['db_configuration'] and 'type' in user_info_without_id['db_configuration']:
                #             # if user is logged-in, and configured experiments database previously:
                #             # initialize experiment database and start execution scheduler if they are not done before
                #             if experiments_db() is None:
                #                 setup_experiment_database(str(user_info_without_id['db_configuration']['type']), str(user_info_without_id['db_configuration']['host']), str(user_info_without_id['db_configuration']['port']))
                #             if get_execution_scheduler_timer() is None:
                #                 initialize_execution_scheduler(10)
                #
                #         # return the usual jwt token
                #         return {"token": encoded_jwt}, 200
                #     else:
                #         return {"message": "Provided credentials are not correct"}, 403
                # else:
                #     return {"message": "User does not exist. Please register first."}, 404

            else:
                return {"message": "Invalid information"}, 404

        except Exception as e:
            tb = traceback.format_exc()
            print(tb)
            return {"message": e.message}, 404