diff --git a/comm/server/main.py b/comm/server/main.py index 177d6c5a5c467b0d4d16027fa45618174dd0e715..4511d98918889a253d7493895878e66dd51b1cb4 100644 --- a/comm/server/main.py +++ b/comm/server/main.py @@ -67,11 +67,11 @@ def load_questions(): # 既に回答されているものを読み込む answer_path = os.path.abspath(app_args["out"]) - answer_list = glob.glob("{}/T03_A*.txt".format(answer_path)) + answer_list = glob.glob("{}/submit/T01_A*.txt".format(answer_path)) for v in answer_list: _ans_name = os.path.basename(v) - m = re.search(r"T03_A([0-9A-Za-z]+)\.txt", _ans_name) + m = re.search(r"T01_A([0-9A-Za-z]+)\.txt", _ans_name) if m: _name = "NL_Q{}.txt".format(m.group(1)) with open(v, "r") as fp: @@ -102,6 +102,9 @@ def update_answer_list(qname): answer_log = json.load(fp) questions[qname]['answers'][json_name] = answer_log + if questions[qname]['answer'] == answer_log['answer']: + questions[qname]['best_json'] = json_name + @app.before_request def before_request(): global app_args @@ -283,6 +286,43 @@ def get_status(): return json.dumps(res) +@app.route("/save", methods=["POST"]) +def save_best_solution(): + """ + それぞれの問題に対し,解き終わった答えの中で最も品質の高い解を + submitフォルダに出力する. + """ + global questions + global app_args + + qname = request.form["qname"] + + _best_score = -1 + _best_json = "" + + for k, v in questions[qname]['answers'].items(): + if v['nlcheck'] > _best_score: + _best_socer = v['nlcheck'] + _best_json = k + + if _best_json != "": + out_path = "{}/{}".format(app_args['out'], "submit") + if not os.path.isdir(out_path): + os.makedirs(out_path) + + qnumber = qname.replace("NL_Q", "").replace(".txt", "") + out_file_path = "{}/T01_A{}.txt".format(out_path, qnumber) + with open(out_file_path, 'w') as fp: + fp.write(questions[qname]['answers'][_best_json]['answer']) + + questions[qname]['best_json'] = _best_json + + res = {"status": "OK"} + else: + res = {"status": "No answer is found"} + + return json.dumps(res) + @app.route("/board-data", methods=["POST"]) def get_board_data(): diff --git a/comm/server/static/css/pynq-manager.css b/comm/server/static/css/pynq-manager.css index 36d1611dac466f32930581686f7dc9d17a227dae..72f5dc78a1e14d5d59bb69adf29bb5575b154148 100644 --- a/comm/server/static/css/pynq-manager.css +++ b/comm/server/static/css/pynq-manager.css @@ -71,3 +71,7 @@ body{ background-color: rgba(200, 100, 100, .15); } +#client-control-pane tr.answer-detail-row.submit-answer{ + background-color: rgba(100, 200, 100, .3); +} + diff --git a/comm/server/static/js/pynq-manager.js b/comm/server/static/js/pynq-manager.js index 6c19ac84fa8d1894f0c93e63db0506719a456c21..a48aa8de3f611bb030d2fd48bbf4d8eee68578e5 100644 --- a/comm/server/static/js/pynq-manager.js +++ b/comm/server/static/js/pynq-manager.js @@ -166,6 +166,17 @@ $(function(){ $("#client-control-pane").find(".stop-button").eq(0).click(function(){ pm.sendStop(); }); + $("#client-control-pane").find(".save-button").eq(0).click(function(){ + var qname = $(this).data("qname"); + $.ajax({ + type: "POST", + dataType: "json", + url: "/save", + data: {qname: qname} + }).done((data) => { + alert(data['status']); + }); + }); $(".answer-detail-row td").click(function(){ var json_name = $(this).parent("tr").data("json"); diff --git a/comm/server/templates/part_question_status.html b/comm/server/templates/part_question_status.html index 27b8df006ecc4148d62fa7b1f6062f3fa8bde935..225e00ec2829eb14717cbe0e2357dd759521938f 100644 --- a/comm/server/templates/part_question_status.html +++ b/comm/server/templates/part_question_status.html @@ -3,7 +3,8 @@
-
+
+