예제 #1
0
def network_parameters():

    conn, cursor = data.connect_db(db=mysql)

    required_params = ['datetime']
    model_params = request.args.to_dict()

    params_check = api_lib.params_checker(
        required_params=required_params,
        model_params=model_params,
        input_type='url').params_exist_populated()

    if not params_check.check:
        return api_lib.request_sender(
            data=None, status_code=400,
            message=params_check.message).get_response()

    # Query database for given data
    network = data.get_network(cursor=cursor, time=model_params['datetime'])

    response = api_lib.request_sender(
        data=network, status_code=200,
        message=params_check.message).get_response()

    conn.close()

    return response
예제 #2
0
def classify_parameters():

    conn, cursor = data.connect_db(db=mysql)

    required_params = ['datetime', 'origin', 'dest']
    model_params = request.args.to_dict()

    params_check = api_lib.params_checker(
        required_params=required_params,
        model_params=model_params,
        input_type='url').params_exist_populated()

    if not params_check.check:
        return api_lib.request_sender(
            data=None, status_code=400,
            message=params_check.message).get_response()

    # Query database for given data then classify
    train_X, train_Y = data.get_classify_train_data(
        cursor=cursor, start_date=model_params['datetime'], time_interval=20)

    predict_X = data.get_classify_predict_data(
        cursor=cursor,
        time=model_params['datetime'],
        origin=model_params['origin'],
        destination=model_params['dest'])

    # Check to make sure we have data
    if predict_X is not None:
        prediction = model.classify_fit_predict(X_train=train_X,
                                                y_train=train_Y,
                                                X_predict=predict_X)
    else:
        # We can't make a prediction without all the data
        prediction = None

    response = api_lib.request_sender(
        data=prediction, status_code=200,
        message=params_check.message).get_response()

    conn.close()

    return response
예제 #3
0
def model_json():

    # TODO update this with the framework used for GET above or just delete so we're not doubling up on everything
    required_params = ['id']

    if request.method == 'POST':
        model_params = request.get_json()

        # list of dictionaries
        if isinstance(model_params, list):
            for item_params in model_params:

                params_check = api_lib.params_checker(
                    required_params=required_params,
                    model_params=item_params,
                    input_type='json').params_exist_populated()

                if not params_check.check:
                    return api_lib.request_sender(
                        data=None,
                        status_code=400,
                        message=params_check.message).get_response()
        # dictionary
        elif isinstance(model_params, dict):

            params_check = api_lib.params_checker(
                required_params=required_params,
                model_params=item_params,
                input_type='json').params_exist_populated()

            if not params_check.check:
                return api_lib.request_sender(
                    data=None, status_code=400,
                    message=params_check.message).get_response()

        return api_lib.request_sender(
            data=data, status_code=200,
            message=params_check.message).get_response()
    else:
        raise api_lib.request_sender(data=None,
                                     status_code=400,
                                     message='Something went wrong')