From 79ed74b16d9d3840fd68e3e7373e8d1dcf2af51f Mon Sep 17 00:00:00 2001 From: Kento HASEGAWA Date: Thu, 18 Jul 2019 01:39:07 +0900 Subject: [PATCH] Add the status view when solving a problem --- main.py | 9 ++++++ roles/host.py | 19 +++++++++++- static/js/adc2019.js | 45 ++++++++++++++++++++++++++++- templates/part_question_status.html | 25 +--------------- templates/part_request_status.html | 15 ++++++++++ 5 files changed, 87 insertions(+), 26 deletions(-) create mode 100644 templates/part_request_status.html diff --git a/main.py b/main.py index fcefdf8..bcf3aa4 100644 --- a/main.py +++ b/main.py @@ -32,6 +32,15 @@ def webui_template_workers(): else: return abort(404) +@webui.route('/part/request/') +def webui_part_request_status(request_id=None): + if (adc2019system.role is not None) and (adc2019system.role.type == 'host'): + request_status = adc2019system.role.get_request_status(float(request_id)) + print(request_status) + return render_template('part_request_status.html', status=request_status) + else: + return abort(404) + @webui.route('/template/question/') def webui_template_question_status(name=None): diff --git a/roles/host.py b/roles/host.py index e8f8c03..6bd3f5a 100644 --- a/roles/host.py +++ b/roles/host.py @@ -219,11 +219,28 @@ class Request(object): status = 'timeout' else: status = 'processing' + + if self.broadcast_time is None: + progress = 0, + else: + progress_question = response_count / worker_count * 100 + progress_time = (time.time() - self.broadcast_time) / self.timeout * 100 + progress = min(100, max(progress_question, progress_time)) + + worker_list = self.worker_manager.get_workers().keys() + worker_status = dict() + for v in all_workers: + if v in self.response: + worker_status[v] = 'Processed' + else: + worker_status[v] = 'Waiting for response' return { 'status': status, 'workers': worker_count, - 'solutions': response_count + 'solutions': response_count, + 'progress': progress, + 'worker_status': worker_status } def broadcast(self): diff --git a/static/js/adc2019.js b/static/js/adc2019.js index e313a91..799b598 100644 --- a/static/js/adc2019.js +++ b/static/js/adc2019.js @@ -5,6 +5,7 @@ class StatusView { constructor(selector) { this.container = $(selector); this.question_key = null; + this.request_refresh_timer = null; } // 問題詳細画面を表示 @@ -42,8 +43,50 @@ class StatusView { contentType: 'application/json' }).done((d) => { // TODO: タイムアウトになる時間まで,モーダル表示させる - console.log(d); + var request_id = d['request_id']; + var timeout = d['timeout']; + _this.container.find('#solver-processing-modal').modal('show'); + _this.container.find('#solver-processing-modal').on('hidden.bs.modal', function(e){ + _this.show_question(); + }) + + _this.get_request_status(request_id, timeout); + }); + } + + get_request_status(request_id, timeout){ + var _this = this; + // $.ajax({ + // type: 'POST', + // dataType: 'json', + // url: '/api/request/status', + // data: JSON.stringify({ + // 'request_id': request_id + // }), + // contentType: 'application/json' + // }).done((d) => { + // if(d['status'] != 'done'){ + // _this.request_refresh_timer = setTimeout(_this.get_request_status(request_id, timeout), 1000); + // } + // console.log(d); + // }); + $.ajax({ + type: 'GET', + dataType: 'html', + url: '/part/request/' + request_id + }).done((d) => { + _this.container.find('#request-status-container').empty(); + _this.container.find('#request-status-container').html(d); + + status = $(d).find('#request-status-value').text(); + console.log(status); + if(status == 'done'){ + _this.request_refresh_timer = null; + // _this.show_question(); + }else{ + _this.request_refresh_timer = setTimeout(_this.get_request_status(request_id, timeout), 1000); + } }); } diff --git a/templates/part_question_status.html b/templates/part_question_status.html index 655e43c..ed28243 100644 --- a/templates/part_question_status.html +++ b/templates/part_question_status.html @@ -11,29 +11,6 @@ {#% else %#} {#% endif %#} -
@@ -73,7 +50,7 @@
-