Loading comm/server/adcclilib.py 0 → 100644 +59 −0 Changes for comm/server/adcclilib.py: 59 added lines, 0 removed lines. Original line number Diff line number Diff line #!/usr/bin/env python3 import subprocess PYTHON2 = "/usr/bin/python" 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): cmd = "--URL='{}' --username='{}' --password='{}' login".format(url, username, password) return _exec_adccli(cmd) def logout(): cmd = "logout" return _exec_adccli(cmd) def whoami(): cmd = "whoami" return _exec_adccli(cmd) def put_message(message): cmd = "put-user-alive '{}'" return _exec_adccli(cmd) def post_user_q(qnum, filepath): cmd = "post-user-q {} {}".format(qnum, filepath) return _exec_adccli(cmd) 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: 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) return _exec_adccli(cmd) def put_a_info(qnum, cpu, mem, misc): cmd = "put-a-info {} {} {} '{}'".format(qnum, cpu, mem, misc) return _exec_adccli(cmd) comm/server/main.py +73 −0 Changes for comm/server/main.py: 73 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ from queue import Queue sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../solver') import BoardStr import adcclilib app = Flask(__name__) app_args = {} questions = None Loading Loading @@ -440,6 +442,76 @@ def get_clients(): return json.dumps(res) @app.route("/adccli-login") def adccli_login(): global app_args with open(app_args['adccli'], 'r') as fp: d = json.load(fp) r = adcclilib.login(d['url'], d['username'], d['password']) res = {'message': r} return json.dumps(res) @app.route("/adccli-logout") def adccli_logout(): r = adcclilib.logout() res = {'message': r} return json.dumps(res) @app.route("/adccli-whoami") def adccli_whoami(): global app_args with open(app_args['adccli'], 'r') as fp: d = json.load(fp) r = adcclilib.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(): Loading Loading @@ -524,6 +596,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description="PYNQ control panel.") parser.add_argument("-c", "--client", action="store", type=str, default=None, required=True, help="Client list.") parser.add_argument("-a", "--adccli", action="store", type=str, default="./adccli.json", help="Path to the ADCCLI configuration json file.") parser.add_argument("-q", "--question", action="store", type=str, default="./problems", help="Path to the question folder.") parser.add_argument("-o", "--out", action="store", type=str, default="./answers", help="Path to the output folder.") parser.add_argument("--debug", action="store_true", default=False, help="Debug mode.") Loading comm/server/static/js/pynq-manager.js +45 −0 Changes for comm/server/static/js/pynq-manager.js: 45 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -145,6 +145,40 @@ $(function(){ }).done(function(d){ $("#client-control-pane").html(""); $("#client-control-pane").html(d); var button_action_with_ajax = function($obj, url){ $obj.prop("disabled", "disabled"); $.ajax({ type: "GET", 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(){ button_action_with_ajax($(this), "/adccli-logout"); }); $("#adccli-get-all-q").click(function(){ button_action_with_ajax($(this), "/adccli-get-all-q"); }); $.ajax({ type: "GET", url: "/adccli-whoami", dataType: "json", }).done((data)=>{ if(data['status']) $("#adccli-status").text("ログイン中"); else $("#adccli-status").text("ログアウト"); }); pm.getStatus(); }); } Loading Loading @@ -177,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"); Loading comm/server/templates/part_client_table.html +7 −0 Changes for comm/server/templates/part_client_table.html: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -9,6 +9,13 @@ Viewer Mode {% endif %} </p> <h4>自動運営システム</h4> <button type="button" class="btn btn-primary" id="adccli-login-button">Login</button> <button type="button" class="btn btn-light" id="adccli-logout-button">Logout</button> <span id="adccli-status"></span> <br /> <button type="button" class="btn btn-info" id="adccli-get-all-q">問題DL</button> <h4>クライアント</h4> <table class="table table-bordered" id="clients-table"> <tr> Loading comm/server/templates/part_question_status.html +4 −1 Changes for comm/server/templates/part_question_status.html: 4 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -3,8 +3,11 @@ <h3> 【{{qname}}】</h3> <p> <button class="btn btn-primary btn-lg start-button" type="button" data-qname="{{qname}}">Start</button> <button class="btn btn-danger btn-lg stop-button" type="button" data-qname="all">Stop</button><br /> <button class="btn btn-danger btn-lg stop-button" type="button" data-qname="all">Stop</button> </p> <p> <button class="btn btn-info btn-lg save-button" type="button" data-qname="{{qname}}">Save</button> <button class="btn btn-success btn-lg submit-button" type="button" data-qname="{{qname}}">Up</button> </p> </div> <div class="col-8"> Loading Loading
comm/server/adcclilib.py 0 → 100644 +59 −0 Changes for comm/server/adcclilib.py: 59 added lines, 0 removed lines. Original line number Diff line number Diff line #!/usr/bin/env python3 import subprocess PYTHON2 = "/usr/bin/python" 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): cmd = "--URL='{}' --username='{}' --password='{}' login".format(url, username, password) return _exec_adccli(cmd) def logout(): cmd = "logout" return _exec_adccli(cmd) def whoami(): cmd = "whoami" return _exec_adccli(cmd) def put_message(message): cmd = "put-user-alive '{}'" return _exec_adccli(cmd) def post_user_q(qnum, filepath): cmd = "post-user-q {} {}".format(qnum, filepath) return _exec_adccli(cmd) 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: 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) return _exec_adccli(cmd) def put_a_info(qnum, cpu, mem, misc): cmd = "put-a-info {} {} {} '{}'".format(qnum, cpu, mem, misc) return _exec_adccli(cmd)
comm/server/main.py +73 −0 Changes for comm/server/main.py: 73 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ from queue import Queue sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../solver') import BoardStr import adcclilib app = Flask(__name__) app_args = {} questions = None Loading Loading @@ -440,6 +442,76 @@ def get_clients(): return json.dumps(res) @app.route("/adccli-login") def adccli_login(): global app_args with open(app_args['adccli'], 'r') as fp: d = json.load(fp) r = adcclilib.login(d['url'], d['username'], d['password']) res = {'message': r} return json.dumps(res) @app.route("/adccli-logout") def adccli_logout(): r = adcclilib.logout() res = {'message': r} return json.dumps(res) @app.route("/adccli-whoami") def adccli_whoami(): global app_args with open(app_args['adccli'], 'r') as fp: d = json.load(fp) r = adcclilib.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(): Loading Loading @@ -524,6 +596,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description="PYNQ control panel.") parser.add_argument("-c", "--client", action="store", type=str, default=None, required=True, help="Client list.") parser.add_argument("-a", "--adccli", action="store", type=str, default="./adccli.json", help="Path to the ADCCLI configuration json file.") parser.add_argument("-q", "--question", action="store", type=str, default="./problems", help="Path to the question folder.") parser.add_argument("-o", "--out", action="store", type=str, default="./answers", help="Path to the output folder.") parser.add_argument("--debug", action="store_true", default=False, help="Debug mode.") Loading
comm/server/static/js/pynq-manager.js +45 −0 Changes for comm/server/static/js/pynq-manager.js: 45 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -145,6 +145,40 @@ $(function(){ }).done(function(d){ $("#client-control-pane").html(""); $("#client-control-pane").html(d); var button_action_with_ajax = function($obj, url){ $obj.prop("disabled", "disabled"); $.ajax({ type: "GET", 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(){ button_action_with_ajax($(this), "/adccli-logout"); }); $("#adccli-get-all-q").click(function(){ button_action_with_ajax($(this), "/adccli-get-all-q"); }); $.ajax({ type: "GET", url: "/adccli-whoami", dataType: "json", }).done((data)=>{ if(data['status']) $("#adccli-status").text("ログイン中"); else $("#adccli-status").text("ログアウト"); }); pm.getStatus(); }); } Loading Loading @@ -177,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"); Loading
comm/server/templates/part_client_table.html +7 −0 Changes for comm/server/templates/part_client_table.html: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -9,6 +9,13 @@ Viewer Mode {% endif %} </p> <h4>自動運営システム</h4> <button type="button" class="btn btn-primary" id="adccli-login-button">Login</button> <button type="button" class="btn btn-light" id="adccli-logout-button">Logout</button> <span id="adccli-status"></span> <br /> <button type="button" class="btn btn-info" id="adccli-get-all-q">問題DL</button> <h4>クライアント</h4> <table class="table table-bordered" id="clients-table"> <tr> Loading
comm/server/templates/part_question_status.html +4 −1 Changes for comm/server/templates/part_question_status.html: 4 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -3,8 +3,11 @@ <h3> 【{{qname}}】</h3> <p> <button class="btn btn-primary btn-lg start-button" type="button" data-qname="{{qname}}">Start</button> <button class="btn btn-danger btn-lg stop-button" type="button" data-qname="all">Stop</button><br /> <button class="btn btn-danger btn-lg stop-button" type="button" data-qname="all">Stop</button> </p> <p> <button class="btn btn-info btn-lg save-button" type="button" data-qname="{{qname}}">Save</button> <button class="btn btn-success btn-lg submit-button" type="button" data-qname="{{qname}}">Up</button> </p> </div> <div class="col-8"> Loading