def process_app_launch(request):
    try:
        if type(request) != dict:
            request_json_data = request.get_json(silent=True, force=True)
        else:
            request_json_data = request

        app_name = request_json_data.get("queryResult").get("parameters").get(
            "LaunchApplication").lower()

        if app_name is None or app_name == "":
            logger.logging.info('app_name was not provided.')
            agent.add_message('Requested activity cannot be fulfilled.')
            return agent.get_response()

        filters = [{
            'column': "synonyms",
            'operator': ">=",
            "key": app_name
        }, {
            'column': "synonyms",
            'operator': ">=",
            "key": app_name + "z"
        }]
        result = search("SupportedAppList", filters)

        if len(result) == 0:
            logger.logging.info('Records not found in Datastore')
            agent.add_message('Requested activity cannot be fulfilled.')
            return agent.get_response()

        vehicle_vin = request_json_data.get("originalDetectIntentRequest").get(
            "payload").get("vin")

        if vehicle_vin is None:
            logger.logging.info('vehicle_vin not found in payload')
            agent.add_message(
                'VIN not found in payload. Hence cannot send msg.')
            return agent.get_response()

        launch_app_json = {
            "category": "APPLAUNCH",
            "package_id": result[0].get("package"),
            "name": app_name
        }

        send_message(launch_app_json, vehicle_vin)

        agent.add_message(f'launching_app {app_name}')
        return agent.get_response()

    except:
        agent.add_message('Requested activity cannot be fulfilled.')
        return agent.get_response()
Example #2
0
def process_handle_indicator(request):
    try:
        if type(request) != dict:
            request_json_data = request.get_json(silent=True, force=True)
        else:
            request_json_data = request

        vehicle_vin = get_vehicle_vin(request_json_data)

        filter = [{"column": "vin", "operator": "=", "key": vehicle_vin}]
        result = search('VehicleStatus', filter)

        if len(result) == 0:
            agent.add_message("Could not find vehicle information")
            return agent.get_response()

        entity_row = result[0]

        if entity_row.get("yatch") == "0":
            agent.add_message("no_indicator")

        elif entity_row.get("yatch") == "1":
            if entity_row.get("parked") == "y":
                agent.add_message("blue_indicator_parked")
            else:
                agent.add_message("blue_indicator_driving")

        elif entity_row.get("yatch") == "2":
            if entity_row.get("parked") == "y":
                agent.add_message("red_indicator_parked")
            else:
                agent.add_message("red_indicator_driving")

        elif entity_row.get("yatch") == "3":
            if entity_row.get("parked") == "y":
                agent.add_message("blinking_red_indicator_parked")
            else:
                agent.add_message("blinking_red_indicator_driving")
        return agent.get_response()

    except:
        agent.add_message(f"Could not search for vehicle.")
        return agent.get_response()
Example #3
0
def search_data(request):
    request_json_data = request.get_json(silent=True, force=True)
    list1 = []

    if request_json_data is None or request_json_data.get('key') is None:
        logger.logging.info(
            'Query function is invoked without the key parameter')
        abort(
            make_response(
                jsonify(message='Please provide a valid key to search'), 400))

    key = request_json_data.get("key")
    filters = [{"column": "UnitName", "operator": "=", "key": key}]
    result = search("data", filters)

    if not result:
        data = "No result is returned"
    else:
        for i in result:
            list1.append(i)
        data = list1
    return make_response(jsonify(data=data), 200)
def process_handle_amb_light(request):
    try:
        if type(request) != dict:
            request_json_data = request.get_json(silent=True, force=True)
        else:
            request_json_data = request

        direction = request_json_data.get("queryResult").get("parameters").get(
            "level")
        by_approx = request_json_data.get("queryResult").get("parameters").get(
            "approx")
        type = request_json_data.get("queryResult").get("parameters").get(
            "hudval")
        by_how_much = int(
            request_json_data.get("queryResult").get("parameters").get(
                "numval"))
        percentage = int(
            request_json_data.get("queryResult").get("parameters").get("per"))
        print({
            'Direction': direction,
            'byApprox': by_approx,
            'type': type,
            'byHowMuch': by_how_much
        })

        ref_result = search('AmbLightRef')
        amb_light_ref_data = ref_result[0]
        print(f"AmbLight Ref: {amb_light_ref_data}")

        if percentage is None and (by_how_much is not None) and (
                by_how_much < amb_light_ref_data.get("minimum")
                or by_how_much > amb_light_ref_data.get("maximum")):
            agent.add_message(
                f"amb_light_not_in_range {amb_light_ref_data.get('minimum')} and  {amb_light_ref_data.get('maximum')}"
            )
            return agent.get_response()

        vehicle_vin = get_vehicle_vin(request_json_data)
        filter = [{"column": "vin", "operator": "=", "key": vehicle_vin}]
        result = search("VehicleStatus", filter)

        if type is not None:
            by_how_much = amb_light_ref_data.get("type")
            print(f"Type: {type},by_how_much: {by_how_much}")

        if len(result) == 0:
            vehicle_data = new_vehicle_status_entity()
            vehicle_data.vin = vehicle_vin
            if by_how_much is None:
                vehicle_data.amb_light = amb_light_ref_data.get("small")
            else:
                vehicle_data.amb_light = by_how_much
            old_amb_light_data = vehicle_data.get("amb_light")
        else:
            vehicle_data = result[0]
            old_amb_light_data = vehicle_data.get("amb_light")
            if direction == "increase":
                if vehicle_data.get("amb_light") >= amb_light_ref_data.get(
                        "maximum"):
                    agent.add_message("amb_light_already_max")
                    return agent.get_response()
                if by_approx == "little":
                    vehicle_data.amb_light = vehicle_data.amb_light + amb_light_ref_data.get(
                        "small")
                elif by_approx == "lot":
                    vehicle_data.amb_light = vehicle_data.amb_light + amb_light_ref_data.get(
                        "big")
                else:
                    if 0 < percentage <= 100:
                        by_how_much = old_amb_light_data + (
                            old_amb_light_data * percentage / 100)
                    else:
                        agent.add_message("amb_light_invalid_percentage")
                        return agent.get_response()
                    vehicle_data.amb_light = vehicle_data.amb_light + by_how_much

            elif direction == "decrease":
                if vehicle_data.amb_light <= amb_light_ref_data.get("minimum"):
                    agent.add_message("amb_light_already_min")
                    return agent.get_response()
                if by_approx == "little":
                    vehicle_data.amb_light = vehicle_data.amb_light - amb_light_ref_data.get(
                        "small")
                elif by_approx == "lot":
                    vehicle_data.amb_light = vehicle_data.amb_light - amb_light_ref_data.get(
                        "big")
                else:
                    if 0 < percentage <= 100:
                        by_how_much = old_amb_light_data - (
                            old_amb_light_data * percentage / 100)
                    else:
                        agent.add_message("amb_light_invalid_percentage")
                        return agent.get_response()
                    vehicle_data.amb_light = vehicle_data.amb_light + by_how_much
            else:
                vehicle_data.amb_light = by_how_much
                old_amb_light_data = 0

            print("Existing vehicle found")

        if vehicle_data.amb_light is None:
            agent.add_message("hud_error")
            return agent.get_response()
        if vehicle_data.amb_light >= amb_light_ref_data.get("maximum"):
            vehicle_data.amb_light = amb_light_ref_data.get("maximum")
        elif vehicle_data.amb_light <= amb_light_ref_data.get("minimum"):
            vehicle_data.amb_light = amb_light_ref_data.get("minimum")
        try:

            result = create_entity("VehicleStatus", vehicle_vin, vehicle_data)

            if type is not None:
                if type == 'minimum':
                    agent.add_message("amb_light_min")
                if type == 'maximum':
                    agent.add_message("amb_light_max")
                else:
                    agent.add_message("amb_light_mid")

            elif old_amb_light_data == 0:
                if vehicle_data.amb_light == amb_light_ref_data.get("minimum"):
                    agent.add_message("amb_light_min")
                elif vehicle_data.amb_light == amb_light_ref_data.get(
                        "maximum"):
                    agent.add_message("amb_light_max")
                else:
                    agent.add_message(
                        f"amb_light_set_to {vehicle_data.amb_light}")

            else:
                if old_amb_light_data <= vehicle_data.amb_light:
                    agent.add_message("raising")
                    agent.add_message("amb_light_changed")
                else:
                    agent.add_message("lowering")
                    agent.add_message("amb_light_changed")
            return agent.get_response()

        except:
            agent.add_message(
                "Ambient Light info could not be inserted or updated.")
            return agent.get_response()

    except:
        agent.add_message("Error while trying to search vehicle.")
        return agent.get_response()
def process_handle_hud_rel(request):
    try:

        if type(request) != dict:
            request_json_data = request.get_json(silent=True, force=True)
        else:
            request_json_data = request

        direction = request_json_data.get("queryResult").get("parameters").get(
            "level")
        by_approx = request_json_data.get("queryResult").get("parameters").get(
            "approx")
        type = request_json_data.get("queryResult").get("parameters").get(
            "hudval")
        by_how_much = int(
            request_json_data.get("queryResult").get("parameters").get(
                "numval"))
        print({
            'Direction': direction,
            'byApprox': by_approx,
            'type': type,
            'byHowMuch': by_how_much
        })

        hud_data = search('HudRef')
        hud_ref_data = hud_data[0]

        if by_how_much is not None and (
                by_how_much < hud_ref_data.get("minimum")
                or by_how_much < hud_ref_data.get("maximum")):
            agent.add_message(
                f"hud_angle_not_in_range of  {hud_ref_data.get('minimum')} and {hud_ref_data.get('maximum')}"
            )
        vehicle_vin = get_vehicle_vin(request_json_data)
        filter = [{"column": "vin", "operator": "=", "key": vehicle_vin}]

        result = search('VehicleStatus', filter)
        if type is not None:
            by_how_much = hud_ref_data.get("type")
            logger.logging.info({'type': type, 'by_how_much': by_how_much})
        if len(result) == 0:
            vehicle_data = new_vehicle_status_entity()
            vehicle_data.vin = vehicle_vin
            if by_how_much is None:
                vehicle_data.hud_angle = hud_ref_data.get('small')
            else:
                vehicle_data.hud_angle = by_how_much
            old_hud_angle_data = vehicle_data.hud_angle
        else:
            vehicle_data = result[0]
            old_hud_angle_data = vehicle_data.hud_angle

            if direction == 'increase':
                if vehicle_data.hud_angle >= hud_ref_data.get('maximum'):
                    agent.add_message("hud_angle_already_max")
                if by_approx == "little":
                    vehicle_data.hud_angle = vehicle_data.hud_angle + hud_ref_data.small
                elif by_approx == "lot":
                    vehicle_data.hud_angle = vehicle_data.hud_angle + hud_ref_data.big
                else:
                    vehicle_data.hud_angle = vehicle_data.hud_angle + by_how_much

            elif direction == "decrease":
                if vehicle_data.hud_angle <= hud_ref_data.get('minimum'):
                    agent.add_message("hud_angle_already_min")
                if by_approx == "little":
                    vehicle_data.hud_angle = vehicle_data.hud_angle - hud_ref_data.small
                elif by_approx == "lot":
                    vehicle_data.hud_angle = vehicle_data.hud_angle - hud_ref_data.big
                else:
                    vehicle_data.hud_angle = vehicle_data.hud_angle - by_how_much
            else:
                vehicle_data.hud_angle = by_how_much
                old_hud_angle_data = 0

            logger.logging.info("Existing vehicle found.")

            if vehicle_data.hud_angle is None:
                agent.add_message("hud_error")

            if vehicle_data.hud_angle >= hud_ref_data.maximum:
                vehicle_data.hud_angle = hud_ref_data.maximum
            elif vehicle_data.hud_angle <= hud_ref_data.minimum:
                vehicle_data.hud_angle = hud_ref_data.minimum

        try:
            result = create_entity("VehicleStatus", vehicle_vin, vehicle_data)

            if type is not None:
                if type == 'minimum':
                    agent.add_message("hud_angle_min")
                if type == 'maximum':
                    agent.add_message("hud_angle_max")
                else:
                    agent.add_message("hud_angle_mid")

            elif old_hud_angle_data == 0:
                if vehicle_data.hud_angle == hud_ref_data.minimum:
                    agent.add_message("hud_angle_min")
                elif vehicle_data.hud_angle == hud_ref_data.maximum:
                    agent.add_message("hud_angle_max")
                else:
                    agent.add_message(
                        f"hud_angle_set_to {vehicle_data.hud_angle}")
            else:
                if old_hud_angle_data <= vehicle_data.hud_angle:
                    agent.add_message("raising")
                else:
                    agent.add_message("lowering")
                    if old_hud_angle_data <= vehicle_data.hud_angle:
                        agent.add_message("raising")
                        agent.add_message("hud_angle_changed")
                    else:
                        agent.add_message("lowering")
                        agent.add_message("hud_angle_changed")

            return agent.get_response()

        except:
            agent.add_message("HUD info could not be inserted or updated")
            return agent.get_response()

    except:
        agent.add_message("Error while trying to search vehicle.")
        return agent.get_response()