Пример #1
0
def delete_tasks():
    """
    @@@
    ### description
    > Deleting Tasks.
    ### args
    |      args    | nullable | request type | type |        remarks           |
    |--------------|----------|--------------|------|--------------------------|
    |    task_id   |  false   |    body      | str  | task list |

    ### request
    ```json
    {"task_id": [1,3,4]}
    ```
    ### return
    ```json
    {"status": xxxx, "data": xxxx}
    ```
    @@@
    """
    task_ids = json.loads(request.form.get("task_id"))
    task_api = TaskApi()
    delete_status = task_api.delete_tasks(task_ids)
    if delete_status:
        return jsonify({
            "status": 200,
            "data": _("The delete result is true.")
        })
    else:
        return jsonify({
            "status": 400,
            "data": _("The delete result is false.")
        })
Пример #2
0
def current_language():
    """
    @@@
    ### description
    >Switching the GUI Language
    ### args
    |      args    | nullable | request type | type |        remarks           |
    |--------------|----------|--------------|------|--------------------------|
    |    task_id   |  false   |    body      | int  | task key in the database |

    ### request
    ```json
    {"task_id": 1}
    ```
    ### return
    ```json
    {"status": xxxx, "data": xxxx}
    ```
    @@@
    """
    language = request.form.get("language")
    res = set_current_language(language)
    if res:
        status_code = 200
        data = _('The language is set successfully.')
    else:
        status_code = 400
        data = _('Failed to set the language.')

    return jsonify({'status': status_code, 'data': data})
Пример #3
0
def set_dataset_info():
    """
    @@@
    ### description
    > Setting Task Data Information.
    ### args
    |      args    | nullable | request type | type |        remarks           |
    |--------------|----------|--------------|------|--------------------------|
    |    task_id   |  false   |    body      | int  | task key in the database |
    |   name_path  |  false   |    body      | str  | task path string         |
    ### request
    ```json
    {"task_id": 1}
    ```
    ### return
    ```json
    {"status": xxxx, "data": xxxx}
    ```
    @@@
    """
    task_id = request.form.get('task_id')
    name_path = request.form.get('name_path')
    dataset = DataSetApi(name_path)
    result = dataset.set_dataset_info(task_id)
    if result:
        return jsonify({
            'status': 200,
            'task_id': task_id,
            'data': _('The dataset is set successfully.')
        })
    return jsonify({
        'status': 400,
        'task_id': task_id,
        'data': _('The dataset fail to be set.')
    })
Пример #4
0
def check_label_dataset():
    """
    @@@
    ### description
    > Check whether the real image exists.
    ### args
    |      args     | nullable | request type | type |        remarks           |
    |---------------|----------|--------------|------|--------------------------|
    |label_data_path|  false   |    body      | str  |Checking Realistic Path   |

    ### request
    ```json
    {"task_id": 1}
    ```
    ### return
    ```json
    {"status": xxxx, "data": xxxx}
    ```
    @@@
    """
    label_path = request.form.get("label_data_path")
    evaluation = Evaluation()
    res = evaluation.check_label_dataset(label_path)
    if res:
        return jsonify({
            "status": 200,
            "data": _("The verification result is true.")
        })
    else:
        return jsonify({
            "status": 400,
            "data": _("The verification result is false.")
        })
Пример #5
0
def get_algorithm_names():
    """
    @@@
    ### description
    > Obtains the algorithm name list.
    ### args
    |      args    | nullable | request type | type |        remarks           |
    |--------------|----------|--------------|------|--------------------------|
    |    task_id   |  false   |    body      | int  | task key in the database |

    ### request
    ```json
    {"task_id": 1}
    ```
    ### return
    ```json
    {"status": xxxx, "data": xxxx}
    ```
    @@@
    """
    task_id = request.form.get('task_id')
    selected_algorithm = AlgorithmApi.get_algorithm(task_id)

    task_type = TaskApi().get_task_type(task_id)
    default = {1: "IID_LINEAR", 2: "PC"}

    if len(selected_algorithm) <= 0:
        selected_algorithm = {"algorithm": default[task_type]}

    if task_type == 1:
        return jsonify({
            "name": _("Sample Distribution"),
            "val": selected_algorithm['algorithm'],
            "default": default[task_type],
            "list": list(SEM_TYPE.keys())
        })
    elif task_type == 2:
        algorithm_names = AlgorithmApi.get_algorithm_names()
        return jsonify({
            "name": _("Selecting an algorithm"),
            "val": selected_algorithm['algorithm'],
            "default": default[task_type],
            "list": algorithm_names
        })
    else:
        return jsonify({
            'status': 400,
            'data': _('The task type is incorrect.')
        })
Пример #6
0
def export_task():
    """
    @@@
    ### description
    > Interface for Exporting Configuration Files.
    ### args
    |      args    | nullable | request type | type |        remarks           |
    |--------------|----------|--------------|------|--------------------------|
    |    task_id   |  false   |    body      | int  | task key in the database |

    ### request
    ```json
    {"task_id": 1}
    ```
    ### return
    ```json
    {"status": xxxx, "data": xxxx}
    ```
    @@@
    """
    task_id = request.form.get("task_id")
    file_name = save_param(task_id)
    task_name = TaskApi().get_task_name(task_id)
    if file_name:
        response = make_response(send_file(file_name))
        response.headers["Content-Disposition"] = \
            "attachment;" \
            "filename*=UTF-8''{utf_filename}".format(
                utf_filename=(task_name + ".yaml"))
        return response
    else:
        return jsonify({
            "status": 400,
            "data": _("The configuration file does not exist.")
        })
Пример #7
0
def upload_config_file():
    """
    @@@
    ### description
    > Uploading Configuration Files.
    ### files
    |      files   | nullable | request type | type |        remarks           |
    |--------------|----------|--------------|------|--------------------------|
    |    file      |  false   |    body      | str  | file name string         |

    ### request
    ```json
    {"file": xxxx}
    ```
    ### return
    ```json
    {"status": xxxx, "data": xxxx}
    ```
    @@@
    """
    f = request.files['file']
    file_name = os.path.join(FILE_PATH, f.filename)
    f.save(file_name)
    task_id = read_task(file_name)
    new_file_name = os.path.join(FILE_PATH, str(task_id) + "_" + f.filename)
    if os.path.exists(new_file_name):
        os.remove(new_file_name)
    os.rename(file_name, new_file_name)
    status_code = 200
    data = _('File uploaded successfully.')

    return jsonify({'status': status_code, 'data': data})
Пример #8
0
def check_dataset():
    """
    @@@
    ### description
    > Check whether the file path exists.
    ### args
    |      args    | nullable | request type | type |        remarks           |
    |--------------|----------|--------------|------|--------------------------|
    |    path      |  false   |    body      | str  | file path string  |

    ### request
    ```json
    {"path": xxxx}
    ```
    ### return
    ```json
    {"status": xxxx, "data": xxxx}
    ```
    @@@
    """
    path = request.form.get('path')
    check_result = DataSetApi.check_dataset(path)

    if check_result:
        return jsonify({"column_num": check_result})
    else:
        return jsonify({
            'status': 403,
            'data': _('The verification result is false.')
        })
Пример #9
0
def run_task():
    """
    @@@
    ### description
    > Perform causal discovery or data generation tasks.
    ### args
    |      args    | nullable | request type | type |        remarks           |
    |--------------|----------|--------------|------|--------------------------|
    |    task_id   |  false   |    body      | int  | task key in the database |

    ### request
    ```json
    {"task_id": 1}
    ```
    ### return
    ```json
    {"status": xxxx, "data": xxxx}
    ```
    @@@
    """
    result = None
    task_id = request.form.get('task_id')
    dataset = DataSetApi.get_dataset(task_id)
    algorithm_info = AlgorithmApi.get_algorithm(task_id)
    tasks = {1: run.run_data, 2: run.run_task}

    task_type = TaskApi().get_task_type(task_id)

    if dataset and len(algorithm_info) > 0 and task_type in tasks.keys():
        result = tasks[task_type](task_id, dataset,
                                  algorithm_info['algorithm'],
                                  algorithm_info['parameters'])

    if result:
        status_code = 200
        data = _('The task succeeds to begin to run.')
    else:
        status_code = 400
        data = _('The task fails to begin to run.')

    return jsonify({'status_code': status_code, 'data': data})
Пример #10
0
def download_file():
    """
    @@@
    ### description
    > Downloading task-related files in the list.
    ### args
    |      args    | nullable | request type | type |        remarks           |
    |--------------|----------|--------------|------|--------------------------|
    |    task_id   |  false   |    body      | int  | task key in the database |

    ### request
    ```json
    {"task_id": 1}
    ```
    ### return
    ```json
    {"status": xxxx, "data": xxxx}
    ```
    @@@
    """
    file_name = None
    task_id = request.form.get("task_id")
    task_api = TaskApi()
    task_type = task_api.get_task_type(task_id)
    if task_type == 1:
        data_path = DataSetApi.get_dataset(task_id)
        if data_path is None:
            data_path = os.path.join(FILE_PATH, 'inline')

        task_api = TaskApi()
        task_name = task_api.get_task_name(task_id)
        file_name = zip_data_file(task_id, task_name, data_path)
    elif task_type == 2:
        file_name = zip_alg_file(task_id)
    if file_name:
        response = make_response(send_file(file_name))
        response.headers["Content-Disposition"] = \
            "attachment;" \
            "filename*=UTF-8''{utf_filename}".format(
                utf_filename=(task_id + ".zip"))
        return response
    else:
        return jsonify({
            "status": 400,
            "data": _("The result file does not exist.")
        })
Пример #11
0
def set_causal_relationship():
    """
    @@@
    ### description
    > Modifying the Causality Diagram.
    ### args
    |      args    | nullable | request type | type |        remarks           |
    |--------------|----------|--------------|------|--------------------------|
    |    task_id   |  false   |    body      | int  | task key in the database |
    | relationship |  false   |    body      | str  | Modified Causality |
    ### request
    ```json
    {"task_id": 1}
    ```
    ### return
    ```json
    {"status": xxxx, "data": xxxx}
    ```
    @@@
    """
    task_id = request.form.get("task_id")
    relationship = request.form.get("relationship")
    write_result(relationship, task_id)
    return jsonify({'status': 200, 'data': _('The save result is true.')})