in mephisto/client/review/review_server.py [0:0]
def task_data_by_id(id):
"""
This route takes a parameter of the id of an item being reviewed.
This id represents the index (beginning at 0) of the item in the list of items being reviewed.
If this route receives a GET request the data of the item at that position in the list of review items is returned.
If this route receives a POST request a review is written for the item at the given index based on the body of JSON in the request.
Accordingly for POST requests all review data must be in the JSON body of the request.
The JSON for the review is written directly into the output file specified for mephisto review.
"""
global finished, current_data, ready_for_next, counter, all_data_list
id = int(id) if type(id) is int or (type(id) is str and id.isdigit()) else None
if request.method == "GET":
if all_data:
list_len = len(all_data_list)
if id is None or id < 0 or id >= list_len:
return jsonify(
{"error": f"Data with ID: {id} does not exist", "mode": MODE}
)
return jsonify({"data": all_data_list[id], "mode": MODE})
else:
if id is None or id != counter - 1:
return jsonify(
{
"error": f"Please review the data point with ID: {counter - 1}",
"mode": MODE,
}
)
data = {
"data": current_data if not finished else None,
"id": counter - 1,
}
if finished:
func = request.environ.get("werkzeug.server.shutdown")
if func is None:
raise RuntimeError("Not running with the Werkzeug Server")
func()
return jsonify(
{
"finished": finished,
"data": data,
"mode": MODE,
}
)
else:
review = request.get_json(force=True)
if output == "":
print("ID: {}, REVIEW: {}".format(id, review))
sys.stdout.flush()
else:
with open(output, "a+") as f:
f.write("ID: {}, REVIEW: {}\n".format(id, review))
if not all_data:
ready_for_next.set()
time.sleep(0)
return jsonify(
{"result": RESULT_SUCCESS, "finished": finished, "mode": MODE}
)