예제 #1
0
def delete_class(dataset_id):
    """Delete class and all of its recordings from a dataset.

    **Example request**:

    .. sourcecode:: json

        {
            "name": "Sad"
        }

    :reqheader Content-Type: *application/json*
    :<json string name: *Required.* Name of the class.

    :resheader Content-Type: *application/json*
    """
    ds = get_check_dataset(dataset_id, write=True)
    class_dict = request.get_json()

    try:
        dataset_validator.validate_class(class_dict, recordings_required=False)
    except dataset_validator.ValidationException as e:
        raise api_exceptions.APIBadRequest(e.error)

    db.dataset.delete_class(ds["id"], class_dict)
    return jsonify(success=True, message="Class deleted.")
예제 #2
0
def delete_class(dataset_id):
    """Delete class and all of its recordings from a dataset.

    **Example request**:

    .. sourcecode:: json

        {
            "name": "Sad"
        }

    :reqheader Content-Type: *application/json*
    :<json string name: *Required.* Name of the class.

    :resheader Content-Type: *application/json*
    """
    ds = get_check_dataset(dataset_id, write=True)
    class_dict = request.get_json()

    try:
        dataset_validator.validate_class(class_dict, recordings_required=False)
    except dataset_validator.ValidationException as e:
        raise api_exceptions.APIBadRequest(str(e))

    db.dataset.delete_class(ds["id"], class_dict)
    return jsonify(
        success=True,
        message="Class deleted."
    )
    def test_class(self):
        """ Validator for requests to add or delete a class """
        # Class validation is also tested in other tests below

        # recordings required depending on flag
        with self.assertRaises(dataset_validator.ValidationException) as out:
            dataset_validator.validate_class({"name": "Test", "description": "Desc"}, recordings_required=True)
        self.assertEqual(str(out.exception), "Field `recordings` is missing from class.")

        # Required=False, no error
        dataset_validator.validate_class({"name": "Test", "description": "Desc"}, recordings_required=False)
예제 #4
0
def add_class(dataset_id):
    """Add a class to a dataset.

    The data can include an optional list of recording ids. If these are included,
    the recordings are also added to the list. Duplicate recording ids are ignored.

    If a class with the given name already exists, the recordings (if provided) will
    be added to the existing class.

    **Example request**:

    .. sourcecode:: json

        {
            "name": "Not Mood",
            "description": "Dataset for mood misclassification.",
            "recordings": ["770cc467-8dde-4d22-bc4c-a42f91e"]
        }

    :reqheader Content-Type: *application/json*
    :<json string name: *Required.* Name of the class. Must be unique within a dataset.
    :<json string description: *Optional.* Description of the class.
    :<json array recordings: *Optional.* Array of recording MBIDs (``string``) to add into that class. For example:
        ``["770cc467-8dde-4d22-bc4c-a42f91e"]``.


    :resheader Content-Type: *application/json*
    """
    ds = get_check_dataset(dataset_id, write=True)
    class_dict = request.get_json()

    try:
        dataset_validator.validate_class(class_dict, recordings_required=False)
    except dataset_validator.ValidationException as e:
        raise api_exceptions.APIBadRequest(str(e))

    if "recordings" in class_dict:
        unique_mbids = list(set(class_dict["recordings"]))
        class_dict["recordings"] = unique_mbids

    db.dataset.add_class(ds["id"], class_dict)
    return jsonify(
        success=True,
        message="Class added."
    )
예제 #5
0
def add_class(dataset_id):
    """Add a class to a dataset.

    The data can include an optional list of recording ids. If these are included,
    the recordings are also added to the list. Duplicate recording ids are ignored.

    If a class with the given name already exists, the recordings (if provided) will
    be added to the existing class.

    **Example request**:

    .. sourcecode:: json

        {
            "name": "Not Mood",
            "description": "Dataset for mood misclassification.",
            "recordings": ["770cc467-8dde-4d22-bc4c-a42f91e"]
        }

    :reqheader Content-Type: *application/json*
    :<json string name: *Required.* Name of the class. Must be unique within a dataset.
    :<json string description: *Optional.* Description of the class.
    :<json array recordings: *Optional.* Array of recording MBIDs (``string``) to add into that class. For example:
        ``["770cc467-8dde-4d22-bc4c-a42f91e"]``.


    :resheader Content-Type: *application/json*
    """
    ds = get_check_dataset(dataset_id, write=True)
    class_dict = request.get_json()

    try:
        dataset_validator.validate_class(class_dict, recordings_required=False)
    except dataset_validator.ValidationException as e:
        raise api_exceptions.APIBadRequest(e.error)

    if "recordings" in class_dict:
        unique_mbids = list(set(class_dict["recordings"]))
        class_dict["recordings"] = unique_mbids

    db.dataset.add_class(ds["id"], class_dict)
    return jsonify(success=True, message="Class added.")
    def test_class(self):
        """ Validator for requests to add or delete a class """
        # Class validation is also tested in other tests below

        # recordings required depending on flag
        with self.assertRaises(dataset_validator.ValidationException) as out:
            dataset_validator.validate_class(
                {
                    "name": "Test",
                    "description": "Desc"
                },
                recordings_required=True)
        self.assertEqual(six.ensure_text(out.exception.error),
                         "Field `recordings` is missing from class.")

        # Required=False, no error
        dataset_validator.validate_class(
            {
                "name": "Test",
                "description": "Desc"
            }, recordings_required=False)