Loading static/js/adc2019.js +50 −19 Changes for static/js/adc2019.js: 50 added lines, 19 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ class StatusView { this.container = $(selector); this.problem_key = null; this.request_refresh_timer = null; this.event = Object(); } // 問題詳細画面を表示 Loading @@ -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) => { Loading Loading @@ -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(()=>{ Loading Loading @@ -174,37 +177,66 @@ class StatusView { }); } // イベントの追加 on(key, func){ if(!this.event.hasOwnProperty(key)){ this.event[key] = Array(); } this.event[key].push(func); } $(function(){ // イベントの発火 fire(key){ if(this.event.hasOwnProperty(key)){ for(var i=0; i<this.event[key].length; i++){ this.event[key][i](); } } } } const status_view = new StatusView('#status-container'); // 問題一覧画面 class ProblemListView { constructor(selector) { this.container = $(selector); } refresh(){ var _this = this; var refresh_problems = function(){ $.ajax({ type: "GET", dataType: "html", url: "/part/problems" }).done((d) => { $("#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("#", ""); Loading @@ -213,9 +245,8 @@ $(function(){ }else{ status_view.show_problem(hash); } problem_list_view.refresh(); }).trigger('hashchange'); refresh_problems(); }); templates/part_problem_status.html +5 −5 Changes for templates/part_problem_status.html: 5 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -30,11 +30,11 @@ <td>{{v.timestamp_str}}</td> <td>{{v.worker}}</td> <td> {#% if v.nlcheck == -1 %#} <!-- Not solved --> {#% else %#} {#{v.nlcheck}#} {#% endif %#} {% if v.is_valid_solution() %} {{v.score}} ({{v.size_str}}) {% else %} {{v.status}} {% endif %} </td> </tr> {% endfor %} Loading templates/part_problems.html +1 −1 Changes for templates/part_problems.html: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ </thead> <tbody> {% for k, v in problems.items() %} <tr class="problem-row" data-qname="{{v.name}}"> <tr class="problem-row" data-problem="{{v.name}}"> <td class="large-cell">{{v.name}}</td> <td class="small-cell">{{v.size_str}}</td> <td class="small-cell">{{v.block_num}}</td> Loading utils/data.py +32 −4 Changes for utils/data.py: 32 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -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 Loading @@ -26,6 +26,27 @@ class Problem(object): 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): with open(path, 'r') as fp: Loading Loading @@ -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 { Loading @@ -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): Loading Loading @@ -213,11 +234,18 @@ 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' Loading Loading
static/js/adc2019.js +50 −19 Changes for static/js/adc2019.js: 50 added lines, 19 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ class StatusView { this.container = $(selector); this.problem_key = null; this.request_refresh_timer = null; this.event = Object(); } // 問題詳細画面を表示 Loading @@ -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) => { Loading Loading @@ -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(()=>{ Loading Loading @@ -174,37 +177,66 @@ class StatusView { }); } // イベントの追加 on(key, func){ if(!this.event.hasOwnProperty(key)){ this.event[key] = Array(); } this.event[key].push(func); } $(function(){ // イベントの発火 fire(key){ if(this.event.hasOwnProperty(key)){ for(var i=0; i<this.event[key].length; i++){ this.event[key][i](); } } } } const status_view = new StatusView('#status-container'); // 問題一覧画面 class ProblemListView { constructor(selector) { this.container = $(selector); } refresh(){ var _this = this; var refresh_problems = function(){ $.ajax({ type: "GET", dataType: "html", url: "/part/problems" }).done((d) => { $("#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("#", ""); Loading @@ -213,9 +245,8 @@ $(function(){ }else{ status_view.show_problem(hash); } problem_list_view.refresh(); }).trigger('hashchange'); refresh_problems(); });
templates/part_problem_status.html +5 −5 Changes for templates/part_problem_status.html: 5 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -30,11 +30,11 @@ <td>{{v.timestamp_str}}</td> <td>{{v.worker}}</td> <td> {#% if v.nlcheck == -1 %#} <!-- Not solved --> {#% else %#} {#{v.nlcheck}#} {#% endif %#} {% if v.is_valid_solution() %} {{v.score}} ({{v.size_str}}) {% else %} {{v.status}} {% endif %} </td> </tr> {% endfor %} Loading
templates/part_problems.html +1 −1 Changes for templates/part_problems.html: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ </thead> <tbody> {% for k, v in problems.items() %} <tr class="problem-row" data-qname="{{v.name}}"> <tr class="problem-row" data-problem="{{v.name}}"> <td class="large-cell">{{v.name}}</td> <td class="small-cell">{{v.size_str}}</td> <td class="small-cell">{{v.block_num}}</td> Loading
utils/data.py +32 −4 Changes for utils/data.py: 32 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -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 Loading @@ -26,6 +26,27 @@ class Problem(object): 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): with open(path, 'r') as fp: Loading Loading @@ -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 { Loading @@ -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): Loading Loading @@ -213,11 +234,18 @@ 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' Loading