Пример #1
0
def add_eam(version=app.config['ACTUAL_API']):
    """
    This endpoint allows to pilots insert information about related EAMS from different type of activities.

    It allow to Expert Activity Model, have an input access to discover new activities based on user performed actions.


    An example in JSON could be:


    {
        "activity": "payingvisits",
        "locations": ["eu:c4a:seniorcenter", "eu:c4a:friendhome", "eu:c4a:familymemberhome"],
        "transformed_action": ["seniorcenter_enter", "seniorcenter_exit", "friendhome_enter"],
        "duration": 800,
        "start": [["10:00", "22:00"]]
    }


    :param basestring version: Api version

    :return: Response of the request
    """

    if Utilities.check_connection(app, version):
        # We created a list of Python dict.
        data = _convert_to_dict(request.json)
        msg = Utilities.check_add_eam_data(
            AR_DATABASE, data, USER.user_in_role[0].pilot_code or 'lcc')
        if data and not msg and USER:
            # The user data are correct. We proceed to insert it into DB
            # res = AR_DATABASE.add_eam(data, USER)
            res = AR_DATABASE.add_global_eam(data, USER)
            if res:
                logging.info(
                    "add_eam: the username: %s adds new EAM into database" %
                    USER.username)
                return Response('add_eam: data stored in database OK\n'), 200
            else:
                logging.error(
                    "add_eam: the username: %s failed to store data into database. 500"
                    % USER.username)
                return "There is an error in DB", 500
        else:
            logging.error("add_eam: there is a problem with entered data")
            # Data is not valid, check the problem
            if msg and "duplicated" in msg:
                # Data sent is duplicated.
                return Response(msg), 409
            else:
                # Standard Error
                return Response(msg), 400
Пример #2
0
def add_eam(version=app.config['ACTUAL_API']):
    """
    This endpoint allows to pilots insert information about related EAMS from different type of activities.

    It allow to Expert Activity Model, have an input access to discover new activities based on user performed actions.


    An example in JSON could be:

    {
        "activity_name": "AnsweringPhone",                      # This must exist previously
        "locations": ["Kitchen", "Office", "Bedroom"],
        "actions": ["KitchenPIR", "BedroomPIR"],
        "duration": 120,
        "start": [
            ["12:00", "12:05"],
            ["20:00", "20:10"]
        ]
    }


    :param version: Api version
    :return:
    """
    if Utilities.check_connection(app, version):
        # We created a list of Python dict.
        data = _convert_to_dict(request.json)
        res, msg = Utilities.check_add_eam_data(AR_DATABASE, data)
        if data and res and USER:
            # The user data are correct. We proceed to insert it into DB
            res = AR_DATABASE.add_eam(data)
            if res:
                Utilities.write_log_info(
                    app,
                    ("add_eam: the username: %s adds new EAM into database" %
                     USER.username))
                return Response('add_eam: data stored in database OK\n'), 200
            else:
                Utilities.write_log_error(app, (
                    "add_eam: the username: %s failed to store data into database. 500"
                    % USER.username))
                return "There is an error in DB", 500
        else:
            return Response(msg), 400