Loading comm/client/main.py +2 −0 Changes for comm/client/main.py: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -52,6 +52,8 @@ def start(): "resolver": request.form['resolver'] } print(option['req_id']) pynqrouter.start_solver(boardstr, qseed, option) # 実行だけ開始する Loading comm/resolver/main.py +3 −1 Changes for comm/resolver/main.py: 3 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -60,8 +60,10 @@ def resolve(): with open(outpath, "r") as fp: resolved = fp.read() print(data['req_id']) res = { 'answer': resolved, 'solution': resolved, 'solved': True, 'solver': data['client'], 'resolver': client_baseurl, Loading comm/server/main.py +82 −13 Changes for comm/server/main.py: 82 added lines, 13 removed lines. Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ import threading import time from collections import OrderedDict from flask import Flask, render_template, request, g from gevent import pywsgi, monkey from geventwebsocket.handler import WebSocketHandler from queue import Queue sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../solver') Loading @@ -25,10 +27,12 @@ import BoardStr import adcclilib app = Flask(__name__) monkey.patch_all() app_args = {} questions = None clients = None current_seed = 1 wsq = None def load_questions(): global app_args Loading Loading @@ -58,10 +62,10 @@ def load_questions(): "path": v, "status": "Not solved", "answer": "", "queue": Queue(), "board_size": board_size, "line_num": line_num, "last_req": None, "solver": OrderedDict(), "answers": OrderedDict(), } Loading @@ -79,7 +83,7 @@ def load_questions(): with open(v, "r") as fp: _ans_dat = fp.read() try: questions[_name]["status"] = "Solved" questions[_name]["status"] = "Saved" questions[_name]["answer"] = _ans_dat except KeyError as e: pass Loading @@ -88,9 +92,14 @@ def update_answer_list(qname): global app_args global questions global clients questions[qname]['solver'] = OrderedDict() questions[qname]['answers'] = OrderedDict() for c in clients['solver']: questions[qname]['solver'][c[0]] = "-" _folder_name = os.path.splitext(qname)[0] _answers_path = "{}/{}".format(app_args['out'], _folder_name) if os.path.isdir(_answers_path): Loading @@ -98,30 +107,51 @@ def update_answer_list(qname): answer_log_file.sort() answer_log_file.reverse() is_solved = False for v2 in answer_log_file: json_name = os.path.basename(v2) with open(v2, "r") as fp: answer_log = json.load(fp) questions[qname]['answers'][json_name] = answer_log if answer_log['solved'] == "True": is_solved = True if questions[qname]['answer'] == answer_log['answer']: questions[qname]['best_json'] = json_name if (questions[qname]['last_req'] == float(answer_log['req_id'])): if answer_log['solver'] in questions[qname]['solver']: if answer_log['solved'] == "True": questions[qname]['solver'][answer_log['solver']] = "Solved" else: questions[qname]['solver'][answer_log['solver']] = "DNS" if is_solved > 0: questions[qname]['status'] = "Solved" @app.before_request def before_request(): global app_args g.local_mode = (request.remote_addr == "127.0.0.1") if app_args["force_local_mode"]: g.local_mode = True else: g.local_mode = (request.remote_addr in ["127.0.0.1", "::1"]) @app.route("/post", methods=["POST"]) def post(): global questions global app_args global wsq _qname = request.form["qname"] _answer = request.form["answer"] _answer = request.form["solution"] _client = request.form["client"] _req_id = request.form["req_id"] _is_solved = request.form["solved"] if "solver" in request.form: _solver = request.form["solver"] Loading @@ -132,14 +162,18 @@ def post(): receive_time_str = receive_time.strftime("%Y%m%d%H%M%S") dat = { "req_id": request.form['req_id'], "req_id": _req_id, "qname": _qname, "client": _client, "solver": _solver, "answer": _answer, "cputime": request.form['cputime'], "timestamp": receive_time.strftime("%Y/%m/%d %H:%M:%S") "timestamp": receive_time.strftime("%Y/%m/%d %H:%M:%S"), "nlcheck": -1, "solved": _is_solved, } if _is_solved == "True": # Create a temporary file to execute "nlcheck.py" tmp_path = "{}/{}".format(app_args['out'], "tmp") if not os.path.isdir(tmp_path): Loading @@ -160,8 +194,6 @@ def post(): m = re.match(pattern, nlcheck) if m and (m.group(1) == "True"): dat["nlcheck"] = float(m.group(2)) else: dat["nlcheck"] = -1 save_path = "{}/{}".format(app_args['out'], os.path.splitext(_qname)[0]) if not os.path.isdir(save_path): Loading @@ -171,6 +203,17 @@ def post(): save_file_path = "{}/{}".format(save_path, file_name) with open(save_file_path, "w") as fp: json.dump(dat, fp, indent=4) else: save_path = "{}/{}".format(app_args['out'], os.path.splitext(_qname)[0]) if not os.path.isdir(save_path): os.makedirs(save_path) file_name = "{}-{}.json".format(receive_time_str, _solver.replace(":", ".")) save_file_path = "{}/{}".format(save_path, file_name) with open(save_file_path, "w") as fp: json.dump(dat, fp, indent=4) wsq.put(dat) res = {"status": "OK"} Loading Loading @@ -317,6 +360,7 @@ def save_best_solution(): with open(out_file_path, 'w') as fp: fp.write(questions[qname]['answers'][_best_json]['answer']) questions[_name]["status"] = "Saved" questions[qname]['best_json'] = _best_json res = {"status": "OK"} Loading Loading @@ -547,7 +591,23 @@ def question_status(): update_answer_list(qname) qdata = questions[qname] return render_template("part_question_status.html", qname=qname, qdata=qdata, solvers=clients["solver"]) return render_template("part_question_status.html", qname=qname, qdata=qdata, solvers=clients["solver"], localmode=g.local_mode) @app.route('/ws') def ws(): global wsq if request.environ.get('wsgi.websocket'): ws = request.environ['wsgi.websocket'] while True: if wsq is None: time.sleep(1) continue else: data = wsq.get() str_data = json.dumps(data) ws.send(str_data) @app.route("/") def index(): Loading @@ -567,9 +627,7 @@ def init_system(): global app_args global questions global clients if questions is None: load_questions() global wsq if clients is None: Loading @@ -592,6 +650,12 @@ def init_system(): "resolver": resolver } if questions is None: load_questions() if wsq is None: wsq = Queue() if __name__ == "__main__": parser = argparse.ArgumentParser(description="PYNQ control panel.") Loading @@ -599,6 +663,7 @@ if __name__ == "__main__": 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("--force-local-mode", action="store_true", default=False, help="Apply local mode view to all clients.") parser.add_argument("--debug", action="store_true", default=False, help="Debug mode.") args = vars(parser.parse_args()) app_args = args Loading @@ -607,5 +672,9 @@ if __name__ == "__main__": if args["debug"]: app.debug = True app.run(host='0.0.0.0', threaded=True) app.threaded = True # app.run(host='0.0.0.0', threaded=True) server = pywsgi.WSGIServer(("", 5000), app, handler_class=WebSocketHandler) server.serve_forever() comm/server/static/css/pynq-manager.css +3 −5 Changes for comm/server/static/css/pynq-manager.css: 3 added lines, 5 removed lines. Original line number Diff line number Diff line html, body{ /*width: 800px;*/ /*height: 500px;*/ font-size: 11px; overflow: hidden; } Loading @@ -10,7 +8,7 @@ body{ /* scrollbar settings */ ::-webkit-scrollbar{ width: 25px; width: 20px; border: 1px solid rgba(0, 0, 50, .2); } ::-webkit-scrollbar-thumb{ Loading @@ -18,7 +16,7 @@ body{ } #question-table-wrapper{ height: 300px; height: calc(100vh - 50px); overflow-y: scroll; overflow-x: hidden; } Loading @@ -45,7 +43,7 @@ body{ } #client-control-pane{ height: 330px; height: calc(100vh - 20px); overflow-y: scroll; } Loading comm/server/static/js/pynq-manager.js +20 −3 Changes for comm/server/static/js/pynq-manager.js: 20 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -63,7 +63,6 @@ var PynqManager = (function(){ }).done(function(res){ var answer = res; $("#solving-question-status").text(answer["status"]); $("#solved-client").text(answer["answer"]["client"]); if (after !== null){ after(); Loading Loading @@ -110,6 +109,7 @@ $(function(){ var pynqClients = {} var pm = null; var last_req = 0; var refresh_question_table = function(){ $.ajax({ Loading Loading @@ -179,7 +179,7 @@ $(function(){ $("#adccli-status").text("ログアウト"); }); pm.getStatus(); if(pm) pm.getStatus(); }); } Loading @@ -195,7 +195,7 @@ $(function(){ $("#client-control-pane").find(".start-button").eq(0).click(function(){ var qname = $(this).data("qname"); pm.sendQuestion(qname, after=refresh_question_table); pm.sendQuestion(qname); }); $("#client-control-pane").find(".stop-button").eq(0).click(function(){ pm.sendStop(); Loading Loading @@ -241,6 +241,19 @@ $(function(){ } }).trigger('hashchange'); var ws = new WebSocket("ws://" + location.host + "/ws"); ws.onmessage = function(e){ var recv = JSON.parse(e.data.replace(/\n/g, "\\n")); console.log(recv); var hash = location.hash.replace("#", ""); if(hash == recv['qname']){ show_question_status(hash); } refresh_question_table(); }; refresh_question_table(); $.ajax({ Loading @@ -250,6 +263,10 @@ $(function(){ }).done(function(d){ pynqClients = d; pm = PynqManager(pynqClients); if(location.hash.replace("#", "") == ""){ pm.getStatus(); } }); }); Loading
comm/client/main.py +2 −0 Changes for comm/client/main.py: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -52,6 +52,8 @@ def start(): "resolver": request.form['resolver'] } print(option['req_id']) pynqrouter.start_solver(boardstr, qseed, option) # 実行だけ開始する Loading
comm/resolver/main.py +3 −1 Changes for comm/resolver/main.py: 3 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -60,8 +60,10 @@ def resolve(): with open(outpath, "r") as fp: resolved = fp.read() print(data['req_id']) res = { 'answer': resolved, 'solution': resolved, 'solved': True, 'solver': data['client'], 'resolver': client_baseurl, Loading
comm/server/main.py +82 −13 Changes for comm/server/main.py: 82 added lines, 13 removed lines. Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ import threading import time from collections import OrderedDict from flask import Flask, render_template, request, g from gevent import pywsgi, monkey from geventwebsocket.handler import WebSocketHandler from queue import Queue sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../solver') Loading @@ -25,10 +27,12 @@ import BoardStr import adcclilib app = Flask(__name__) monkey.patch_all() app_args = {} questions = None clients = None current_seed = 1 wsq = None def load_questions(): global app_args Loading Loading @@ -58,10 +62,10 @@ def load_questions(): "path": v, "status": "Not solved", "answer": "", "queue": Queue(), "board_size": board_size, "line_num": line_num, "last_req": None, "solver": OrderedDict(), "answers": OrderedDict(), } Loading @@ -79,7 +83,7 @@ def load_questions(): with open(v, "r") as fp: _ans_dat = fp.read() try: questions[_name]["status"] = "Solved" questions[_name]["status"] = "Saved" questions[_name]["answer"] = _ans_dat except KeyError as e: pass Loading @@ -88,9 +92,14 @@ def update_answer_list(qname): global app_args global questions global clients questions[qname]['solver'] = OrderedDict() questions[qname]['answers'] = OrderedDict() for c in clients['solver']: questions[qname]['solver'][c[0]] = "-" _folder_name = os.path.splitext(qname)[0] _answers_path = "{}/{}".format(app_args['out'], _folder_name) if os.path.isdir(_answers_path): Loading @@ -98,30 +107,51 @@ def update_answer_list(qname): answer_log_file.sort() answer_log_file.reverse() is_solved = False for v2 in answer_log_file: json_name = os.path.basename(v2) with open(v2, "r") as fp: answer_log = json.load(fp) questions[qname]['answers'][json_name] = answer_log if answer_log['solved'] == "True": is_solved = True if questions[qname]['answer'] == answer_log['answer']: questions[qname]['best_json'] = json_name if (questions[qname]['last_req'] == float(answer_log['req_id'])): if answer_log['solver'] in questions[qname]['solver']: if answer_log['solved'] == "True": questions[qname]['solver'][answer_log['solver']] = "Solved" else: questions[qname]['solver'][answer_log['solver']] = "DNS" if is_solved > 0: questions[qname]['status'] = "Solved" @app.before_request def before_request(): global app_args g.local_mode = (request.remote_addr == "127.0.0.1") if app_args["force_local_mode"]: g.local_mode = True else: g.local_mode = (request.remote_addr in ["127.0.0.1", "::1"]) @app.route("/post", methods=["POST"]) def post(): global questions global app_args global wsq _qname = request.form["qname"] _answer = request.form["answer"] _answer = request.form["solution"] _client = request.form["client"] _req_id = request.form["req_id"] _is_solved = request.form["solved"] if "solver" in request.form: _solver = request.form["solver"] Loading @@ -132,14 +162,18 @@ def post(): receive_time_str = receive_time.strftime("%Y%m%d%H%M%S") dat = { "req_id": request.form['req_id'], "req_id": _req_id, "qname": _qname, "client": _client, "solver": _solver, "answer": _answer, "cputime": request.form['cputime'], "timestamp": receive_time.strftime("%Y/%m/%d %H:%M:%S") "timestamp": receive_time.strftime("%Y/%m/%d %H:%M:%S"), "nlcheck": -1, "solved": _is_solved, } if _is_solved == "True": # Create a temporary file to execute "nlcheck.py" tmp_path = "{}/{}".format(app_args['out'], "tmp") if not os.path.isdir(tmp_path): Loading @@ -160,8 +194,6 @@ def post(): m = re.match(pattern, nlcheck) if m and (m.group(1) == "True"): dat["nlcheck"] = float(m.group(2)) else: dat["nlcheck"] = -1 save_path = "{}/{}".format(app_args['out'], os.path.splitext(_qname)[0]) if not os.path.isdir(save_path): Loading @@ -171,6 +203,17 @@ def post(): save_file_path = "{}/{}".format(save_path, file_name) with open(save_file_path, "w") as fp: json.dump(dat, fp, indent=4) else: save_path = "{}/{}".format(app_args['out'], os.path.splitext(_qname)[0]) if not os.path.isdir(save_path): os.makedirs(save_path) file_name = "{}-{}.json".format(receive_time_str, _solver.replace(":", ".")) save_file_path = "{}/{}".format(save_path, file_name) with open(save_file_path, "w") as fp: json.dump(dat, fp, indent=4) wsq.put(dat) res = {"status": "OK"} Loading Loading @@ -317,6 +360,7 @@ def save_best_solution(): with open(out_file_path, 'w') as fp: fp.write(questions[qname]['answers'][_best_json]['answer']) questions[_name]["status"] = "Saved" questions[qname]['best_json'] = _best_json res = {"status": "OK"} Loading Loading @@ -547,7 +591,23 @@ def question_status(): update_answer_list(qname) qdata = questions[qname] return render_template("part_question_status.html", qname=qname, qdata=qdata, solvers=clients["solver"]) return render_template("part_question_status.html", qname=qname, qdata=qdata, solvers=clients["solver"], localmode=g.local_mode) @app.route('/ws') def ws(): global wsq if request.environ.get('wsgi.websocket'): ws = request.environ['wsgi.websocket'] while True: if wsq is None: time.sleep(1) continue else: data = wsq.get() str_data = json.dumps(data) ws.send(str_data) @app.route("/") def index(): Loading @@ -567,9 +627,7 @@ def init_system(): global app_args global questions global clients if questions is None: load_questions() global wsq if clients is None: Loading @@ -592,6 +650,12 @@ def init_system(): "resolver": resolver } if questions is None: load_questions() if wsq is None: wsq = Queue() if __name__ == "__main__": parser = argparse.ArgumentParser(description="PYNQ control panel.") Loading @@ -599,6 +663,7 @@ if __name__ == "__main__": 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("--force-local-mode", action="store_true", default=False, help="Apply local mode view to all clients.") parser.add_argument("--debug", action="store_true", default=False, help="Debug mode.") args = vars(parser.parse_args()) app_args = args Loading @@ -607,5 +672,9 @@ if __name__ == "__main__": if args["debug"]: app.debug = True app.run(host='0.0.0.0', threaded=True) app.threaded = True # app.run(host='0.0.0.0', threaded=True) server = pywsgi.WSGIServer(("", 5000), app, handler_class=WebSocketHandler) server.serve_forever()
comm/server/static/css/pynq-manager.css +3 −5 Changes for comm/server/static/css/pynq-manager.css: 3 added lines, 5 removed lines. Original line number Diff line number Diff line html, body{ /*width: 800px;*/ /*height: 500px;*/ font-size: 11px; overflow: hidden; } Loading @@ -10,7 +8,7 @@ body{ /* scrollbar settings */ ::-webkit-scrollbar{ width: 25px; width: 20px; border: 1px solid rgba(0, 0, 50, .2); } ::-webkit-scrollbar-thumb{ Loading @@ -18,7 +16,7 @@ body{ } #question-table-wrapper{ height: 300px; height: calc(100vh - 50px); overflow-y: scroll; overflow-x: hidden; } Loading @@ -45,7 +43,7 @@ body{ } #client-control-pane{ height: 330px; height: calc(100vh - 20px); overflow-y: scroll; } Loading
comm/server/static/js/pynq-manager.js +20 −3 Changes for comm/server/static/js/pynq-manager.js: 20 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -63,7 +63,6 @@ var PynqManager = (function(){ }).done(function(res){ var answer = res; $("#solving-question-status").text(answer["status"]); $("#solved-client").text(answer["answer"]["client"]); if (after !== null){ after(); Loading Loading @@ -110,6 +109,7 @@ $(function(){ var pynqClients = {} var pm = null; var last_req = 0; var refresh_question_table = function(){ $.ajax({ Loading Loading @@ -179,7 +179,7 @@ $(function(){ $("#adccli-status").text("ログアウト"); }); pm.getStatus(); if(pm) pm.getStatus(); }); } Loading @@ -195,7 +195,7 @@ $(function(){ $("#client-control-pane").find(".start-button").eq(0).click(function(){ var qname = $(this).data("qname"); pm.sendQuestion(qname, after=refresh_question_table); pm.sendQuestion(qname); }); $("#client-control-pane").find(".stop-button").eq(0).click(function(){ pm.sendStop(); Loading Loading @@ -241,6 +241,19 @@ $(function(){ } }).trigger('hashchange'); var ws = new WebSocket("ws://" + location.host + "/ws"); ws.onmessage = function(e){ var recv = JSON.parse(e.data.replace(/\n/g, "\\n")); console.log(recv); var hash = location.hash.replace("#", ""); if(hash == recv['qname']){ show_question_status(hash); } refresh_question_table(); }; refresh_question_table(); $.ajax({ Loading @@ -250,6 +263,10 @@ $(function(){ }).done(function(d){ pynqClients = d; pm = PynqManager(pynqClients); if(location.hash.replace("#", "") == ""){ pm.getStatus(); } }); });