From fa1216cfcdb399421f5b1e359b9e87fc5f840e3f Mon Sep 17 00:00:00 2001 From: Kento HASEGAWA Date: Fri, 26 Jul 2019 02:04:22 +0900 Subject: [PATCH] Improve displaying status --- static/js/adc2019.js | 69 ++++++++++++++++++++++-------- templates/part_problem_status.html | 10 ++--- templates/part_problems.html | 2 +- utils/data.py | 36 ++++++++++++++-- 4 files changed, 88 insertions(+), 29 deletions(-) diff --git a/static/js/adc2019.js b/static/js/adc2019.js index 347f992..c07d058 100644 --- a/static/js/adc2019.js +++ b/static/js/adc2019.js @@ -6,6 +6,8 @@ class StatusView { this.container = $(selector); this.problem_key = null; this.request_refresh_timer = null; + + this.event = Object(); } // 問題詳細画面を表示 @@ -29,6 +31,7 @@ class StatusView { _this.container.find('.save-button').click(()=>{ _this.save_solution(); + _this.fire('refresh'); }); _this.container.find('.solution-detail-row td').click((e) => { @@ -62,8 +65,8 @@ class StatusView { show: true }); _this.container.find('#solver-processing-modal').on('hidden.bs.modal', function(e){ - // console.log(e); _this.show_problem(); + _this.fire('refresh'); }) _this.container.find('.stop-button').click(()=>{ @@ -174,37 +177,66 @@ class StatusView { }); } + + // イベントの追加 + on(key, func){ + if(!this.event.hasOwnProperty(key)){ + this.event[key] = Array(); + } + this.event[key].push(func); + } + + // イベントの発火 + fire(key){ + if(this.event.hasOwnProperty(key)){ + for(var i=0; i { - $("#problem-list-container").empty(); - $("#problem-list-container").html(d); - - $(".problem-row td").click(function(){ - var $tr = $(this).parent("tr.problem-row"); - $(".problem-row").removeClass("q-selected"); - $tr.addClass("q-selected"); - var qname = $tr.data("qname"); - // show_problem_status(qname); - location.hash = "#" + qname; - return false; - }); + _this.container.empty(); + _this.container.html(d); var hash = location.hash.replace("#", ""); if(hash != ""){ - $(".problem-row[data-qname='" + hash + "']").addClass("q-selected"); + _this.container.find(".problem-row[data-problem='" + hash + "']").addClass("q-selected"); } + + _this.container.find(".problem-row td").click((e) => { + var $tr = $(e.target).parent("tr.problem-row"); + _this.container.find(".problem-row").removeClass("q-selected"); + $tr.addClass("q-selected"); + var problem_key = $tr.data("problem"); + location.hash = "#" + problem_key; + }); + }); } +} + +$(function(){ + + const status_view = new StatusView('#status-container'); + const problem_list_view = new ProblemListView('#problem-list-container'); + + status_view.on('refresh', ()=>{problem_list_view.refresh()}); $(window).on('hashchange', function(){ var hash = location.hash.replace("#", ""); @@ -213,9 +245,8 @@ $(function(){ }else{ status_view.show_problem(hash); } + problem_list_view.refresh(); }).trigger('hashchange'); - refresh_problems(); - }); diff --git a/templates/part_problem_status.html b/templates/part_problem_status.html index 5a74f4f..7548b1a 100644 --- a/templates/part_problem_status.html +++ b/templates/part_problem_status.html @@ -30,11 +30,11 @@ {{v.timestamp_str}} {{v.worker}} - {#% if v.nlcheck == -1 %#} - - {#% else %#} - {#{v.nlcheck}#} - {#% endif %#} + {% if v.is_valid_solution() %} + {{v.score}} ({{v.size_str}}) + {% else %} + {{v.status}} + {% endif %} {% endfor %} diff --git a/templates/part_problems.html b/templates/part_problems.html index 2a49aa6..361b0ec 100644 --- a/templates/part_problems.html +++ b/templates/part_problems.html @@ -9,7 +9,7 @@ {% for k, v in problems.items() %} - + {{v.name}} {{v.size_str}} {{v.block_num}} diff --git a/utils/data.py b/utils/data.py index 6641d4e..7a50f3b 100644 --- a/utils/data.py +++ b/utils/data.py @@ -15,7 +15,7 @@ class Problem(object): self.block_num = 0 self.blocks = dict() self.problem = '' - self.status = 'Ready' + # self.status = 'Ready' self.solutions = dict() self.solution_path = solution_path self.best_solution = None @@ -25,6 +25,27 @@ class Problem(object): @property def size_str(self): return f'{self.size[0]}X{self.size[1]}' + + @property + def status(self): + _status = 'None' + if self.problem != '': + _status = 'Ready' + if len(self.solutions) > 0: + _solved_count = 0 + _trial_count = 0 + for k, v in self.solutions.items(): + _trial_count += 1 + if v.is_valid_solution(): + _solved_count += 1 + if _solved_count > 0: + _status = f'Solved ({_solved_count}/{_trial_count})' + else: + _status = f'Tried ({_trial_count})' + if not self.best_solution is None: + _status = f'Saved' + + return _status def _load_problem(self, path): @@ -77,7 +98,7 @@ class Problem(object): self.blocks = blocks self.name = name self.problem = q_text - self.status = 'Ready' + # self.status = 'Ready' def get_dict(self): return { @@ -86,7 +107,7 @@ class Problem(object): 'size_str': self.size_str, 'block_num': self.block_num, 'problem': self.problem, - 'status': self.status + # 'status': self.status } def get_d3json(self): @@ -213,10 +234,17 @@ class Solution(object): @property def score(self): - if (len(self.size) == 2) and (self.size[0] is not None) and (self.size[1] is not None): + if self.is_valid_solution(): return self.size[0] * self.size[1] else: return None + + @property + def size_str(self): + if self.is_valid_solution(): + return f'{self.size[0]}X{self.size[1]}' + else: + return '-' def is_valid_solution(self): return self.status == 'done' -- 2.22.0