From 7dcb3457ae1e5dbf9fa8ee6df7cb7e7c249834b9 Mon Sep 17 00:00:00 2001 From: Kento HASEGAWA Date: Thu, 16 Aug 2018 17:26:00 +0900 Subject: [PATCH] Add support for downloading answers and uploading solutions via adccli (#14) --- comm/server/adcclilib.py | 15 +++++-- comm/server/main.py | 39 +++++++++++++++++++ comm/server/static/js/pynq-manager.js | 34 +++++++++------- comm/server/templates/part_client_table.html | 2 + .../templates/part_question_status.html | 5 ++- 5 files changed, 78 insertions(+), 17 deletions(-) diff --git a/comm/server/adcclilib.py b/comm/server/adcclilib.py index a413e64..fb03db3 100644 --- a/comm/server/adcclilib.py +++ b/comm/server/adcclilib.py @@ -7,8 +7,10 @@ ADCCLI = "/home/pi/adc2018/conmgr/client/adccli" def _exec_adccli(cmd): exec_cmd = "{} {} {}".format(PYTHON2, ADCCLI, cmd).strip() + print("ADCCLI: {}".format(exec_cmd)) p = subprocess.run(exec_cmd, stdout=subprocess.PIPE, shell=True) res = p.stdout.decode().strip() + print(res) return res def login(url, username, password): @@ -35,10 +37,17 @@ def get_q_all(outpath): cmd = "get-q" question_list = _exec_adccli(cmd).split("\n") + print("--- ADCCLI questions ---") + print(question_list) + for v in question_list: - out_file_path = "{}/NL_Q{:02d}.txt".format(outpath, int(v)) - cmd = "--output {} get-q {}".format(out_file_path, v.rstrip()) - _exec_adccli(cmd) + if v.startswith("Q"): + qnumber = int(v.replace("Q", "")) + out_file_path = "{}/NL_Q{:02d}.txt".format(outpath, qnumber) + cmd = "--output {} get-q {}".format(out_file_path, qnumber) + r = _exec_adccli(cmd) + + return question_list def put_a(qnum, filepath): cmd = "put-a {} {}".format(qnum, filepath) diff --git a/comm/server/main.py b/comm/server/main.py index 2b097e8..68157a4 100644 --- a/comm/server/main.py +++ b/comm/server/main.py @@ -473,6 +473,45 @@ def adccli_whoami(): res = {'message': r, 'status': r == d['username']} return json.dumps(res) +@app.route("/adccli-get-all-q") +def adccli_get_all_q(): + global app_args + + out_abspath = os.path.abspath(app_args['question']) + r = adcclilib.get_q_all(out_abspath) + + load_questions() + + res = {'message': r} + return json.dumps(res) + +@app.route("/adccli-put-a", methods=["POST"]) +def adccli_put_a(): + global app_args + global questions + + qname = request.form["qname"] + + if not "best_json" in questions[qname]: + res = {'message': "Required to 'save' before submission"} + else: + out_path = "{}/{}".format(app_args['out'], "submit") + qnumber = qname.replace("NL_Q", "").replace(".txt", "") + ans_file_path = "{}/T01_A{}.txt".format(out_path, qnumber) + ans_file_abspath = os.path.abspath(ans_file_path) + + r = adcclilib.put_a(qnumber, ans_file_abspath) + mes = r + "\n" + + json_name = questions[qname]['best_json'] + data = questions[qname]['answers'][json_name] + r = adcclilib.put_a_info(qnumber, data['cputime'], "0", "Test") + mes += r + + res = {'message': mes} + + return json.dumps(res) + @app.route("/board-viewer", methods=["GET"]) def show_board_viewer(): diff --git a/comm/server/static/js/pynq-manager.js b/comm/server/static/js/pynq-manager.js index fa801c1..995d93c 100644 --- a/comm/server/static/js/pynq-manager.js +++ b/comm/server/static/js/pynq-manager.js @@ -146,29 +146,26 @@ $(function(){ $("#client-control-pane").html(""); $("#client-control-pane").html(d); - $("#adccli-login-button").click(function(){ - var $obj = $(this); + var button_action_with_ajax = function($obj, url){ $obj.prop("disabled", "disabled"); $.ajax({ type: "GET", - url: "/adccli-login", + url: url, dataType: "json", }).done((data)=>{ $obj.prop("disabled", false); alert(data['message']); }); + }; + + $("#adccli-login-button").click(function(){ + button_action_with_ajax($(this), "/adccli-login"); }); $("#adccli-logout-button").click(function(){ - var $obj = $(this); - $obj.prop("disabled", "disabled"); - $.ajax({ - type: "GET", - url: "/adccli-logout", - dataType: "json", - }).done((data)=>{ - $obj.prop("disabled", false); - alert(data['message']); - }); + button_action_with_ajax($(this), "/adccli-logout"); + }); + $("#adccli-get-all-q").click(function(){ + button_action_with_ajax($(this), "/adccli-get-all-q"); }); $.ajax({ @@ -214,6 +211,17 @@ $(function(){ alert(data['status']); }); }); + $("#client-control-pane").find(".submit-button").eq(0).click(function(){ + var qname = $(this).data("qname"); + $.ajax({ + type: "POST", + dataType: "json", + url: "/adccli-put-a", + data: {qname: qname} + }).done((data) => { + alert(data['message']); + }); + }); $(".answer-detail-row td").click(function(){ var json_name = $(this).parent("tr").data("json"); diff --git a/comm/server/templates/part_client_table.html b/comm/server/templates/part_client_table.html index af8fe2e..7386b49 100644 --- a/comm/server/templates/part_client_table.html +++ b/comm/server/templates/part_client_table.html @@ -13,6 +13,8 @@ Viewer Mode +
+

クライアント

diff --git a/comm/server/templates/part_question_status.html b/comm/server/templates/part_question_status.html index 225e00e..a6f634c 100644 --- a/comm/server/templates/part_question_status.html +++ b/comm/server/templates/part_question_status.html @@ -3,8 +3,11 @@

【{{qname}}】

-
+ +

+

+

-- 2.22.0