diff --git a/.gitignore b/.gitignore index 0ebe4bcbc542cd5011608aebbb1eb8f08911c764..d4eb4b6c035cba27c21db393dd75b8ad8a5da0b5 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,7 @@ solver # Python files *.pyc __pycache__/ + +# client-icons +client-icon/ + diff --git a/comm/server/main.py b/comm/server/main.py index 56d07ec5c7b949cd3c74bb7fe87701e70fcde47b..232ee8e43c2202a17229a53c2cb6837bf9d2f5dd 100644 --- a/comm/server/main.py +++ b/comm/server/main.py @@ -28,6 +28,59 @@ questions = None clients = None current_seed = 1 +def load_questions(): + global app_args + global questions + + question_path = os.path.abspath(app_args["question"]) + question_list = glob.glob("{}/NL_*.txt".format(question_path)) + question_list.sort() + + questions = OrderedDict() + + for v in question_list: + # 問題の情報を読み込む + with open(v, "r") as fp: + _q_lines = fp.readlines() + board_size = "" + line_num = -1 + for l in _q_lines: + if "SIZE" in l: + board_size = l.strip().split()[1] + if "LINE_NUM" in l: + line_num = int(l.strip().split()[1]) + break + + _name = os.path.basename(v) + questions[_name] = { + "path": v, + "status": "Not solved", + "answer": "", + "queue": Queue(), + "board_size": board_size, + "line_num": line_num, + "answers": [], + } + + update_answer_list(_name) + + # 既に回答されているものを読み込む + answer_path = os.path.abspath(app_args["out"]) + answer_list = glob.glob("{}/T03_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) + if m: + _name = "NL_Q{}.txt".format(m.group(1)) + with open(v, "r") as fp: + _ans_dat = fp.read() + try: + questions[_name]["status"] = "Solved" + questions[_name]["answer"] = _ans_dat + except KeyError as e: + pass + def update_answer_list(qname): global app_args @@ -50,65 +103,8 @@ def update_answer_list(qname): @app.before_request def before_request(): global app_args - global questions - global clients - - if questions is None: - question_path = os.path.abspath(app_args["question"]) - question_list = glob.glob("{}/NL_*.txt".format(question_path)) - question_list.sort() - - questions = OrderedDict() - - for v in question_list: - # 問題の情報を読み込む - with open(v, "r") as fp: - _q_lines = fp.readlines() - board_size = "" - line_num = -1 - for l in _q_lines: - if "SIZE" in l: - board_size = l.strip().split()[1] - if "LINE_NUM" in l: - line_num = int(l.strip().split()[1]) - break - - _name = os.path.basename(v) - questions[_name] = { - "path": v, - "status": "Not solved", - "answer": "", - "queue": Queue(), - "board_size": board_size, - "line_num": line_num, - "answers": [], - } - - update_answer_list(_name) - - # 既に回答されているものを読み込む - answer_path = os.path.abspath(app_args["out"]) - answer_list = glob.glob("{}/T03_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) - if m: - _name = "NL_Q{}.txt".format(m.group(1)) - with open(v, "r") as fp: - _ans_dat = fp.read() - try: - questions[_name]["status"] = "Solved" - questions[_name]["answer"] = _ans_dat - except KeyError as e: - pass - - if clients is None: - - with open(app_args["client"], "r") as fp: - _clients = fp.readlines() - clients = [v.rstrip() for v in _clients] + g.local_mode = (request.remote_addr == "127.0.0.1") @app.route("/post", methods=["POST"]) def post(): @@ -237,7 +233,8 @@ def solve_questions(qname, qstr): request_time = time.time() for c in clients: - _th = threading.Thread(name=c, target=worker, args=(c, qname, qstr, current_seed, request_time)) + client_addr = c[0] + _th = threading.Thread(name=client_addr, target=worker, args=(client_addr, qname, qstr, current_seed, request_time)) _th.start() threads.append(_th) current_seed += 1 @@ -269,7 +266,8 @@ def get_clients(): res = OrderedDict() for c in clients: - res[c] = "http://{}".format(c) + client_ip = c[0] + res[client_ip] = "http://{}".format(client_ip) return json.dumps(res) @@ -289,7 +287,7 @@ def client_table(): global app_args global clients - return render_template("part_client_table.html", clients=clients) + return render_template("part_client_table.html", clients=clients, local_mode=g.local_mode) @app.route("/get_question_status") def question_status(): @@ -314,22 +312,42 @@ def index(): question_path = os.path.abspath(app_args["question"]) + print(g.local_mode) + return render_template("index.html", questions=questions, question_path=question_path, clients=clients) def main(args): raise NotImprementedError() +def init_system(): + + global app_args + global questions + global clients + + if questions is None: + load_questions() + + if clients is None: + + with open(app_args["client"], "r") as fp: + _clients = fp.readlines() + + clients = [v.rstrip().split() for v in _clients] + 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("-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("-t", "--timeout", action="store", type=int, default=300, help="Timeout.") parser.add_argument("--debug", action="store_true", default=False, help="Debug mode.") args = vars(parser.parse_args()) app_args = args + init_system() + if args["debug"]: app.debug = True app.run(host='0.0.0.0', threaded=True) + diff --git a/comm/server/static/css/pynq-manager.css b/comm/server/static/css/pynq-manager.css index dd2cd54eb79a785ef5034aa5f195275997b9d3fc..4ef3532a257a1d441b833a5441b583fb907aa4e7 100644 --- a/comm/server/static/css/pynq-manager.css +++ b/comm/server/static/css/pynq-manager.css @@ -46,9 +46,13 @@ body{ overflow-y: scroll; } -#client-control-pane table th, -#client-control-pane table td{ - width: 50%; +#client-control-pane table th.large-cell, +#client-control-pane table td.large-cell{ + width: 40%; +} +#client-control-pane table th.small-cell, +#client-control-pane table td.small-cell{ + width: 20%; } #question-control-pane h3{ diff --git a/comm/server/static/js/pynq-manager.js b/comm/server/static/js/pynq-manager.js index 82deab0ce4d0088c3a9dc0b48732de4dbf8f5611..9e718c2f4f3bc24ea62981258dd3439ed9faca1f 100644 --- a/comm/server/static/js/pynq-manager.js +++ b/comm/server/static/js/pynq-manager.js @@ -101,13 +101,19 @@ $(function(){ $(".question-row").removeClass("q-selected"); $tr.addClass("q-selected"); var qname = $tr.data("qname"); - show_question_status(qname); + // show_question_status(qname); + location.hash = "#" + qname; return false; }); + + var hash = location.hash.replace("#", ""); + if(hash != ""){ + $(".question-row[data-qname='" + hash + "']").addClass("q-selected"); + } }); } - var refresh_client_table = function(){ + var show_client_table = function(){ $.ajax({ type: "GET", dataType: "html", @@ -145,12 +151,15 @@ $(function(){ }); } - refresh_question_table(); - refresh_client_table(); + $(window).on('hashchange', function(){ + var hash = location.hash.replace("#", ""); + if(hash == ""){ + show_client_table(); + }else{ + show_question_status(hash); + } + }).trigger('hashchange'); - $("#view-server-status-button").click(function(){ - refresh_client_table(); - return false; - }); + refresh_question_table(); }); diff --git a/comm/server/templates/index.html b/comm/server/templates/index.html index ea6802291df850455a9d292f39a14090ab3435c4..24a79484577912faa30a0754b295bc1f423b09eb 100644 --- a/comm/server/templates/index.html +++ b/comm/server/templates/index.html @@ -20,7 +20,7 @@
Loading...
+{% if local_mode %} +Normal Mode +{% else %} +Viewer Mode +{% endif %} +
+ +クライアント名 | -ステータス | +Client | +Role | +Status |
---|---|---|---|---|
{{c}} | +||||
+ {% if c|length > 3 %}
+ |
+ {{c[1]}} |