Commit fa1216cf authored by Kento HASEGAWA's avatar Kento HASEGAWA

Improve displaying status

parent e7a02e9a
......@@ -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<this.event[key].length; i++){
this.event[key][i]();
}
}
}
}
$(function(){
// 問題一覧画面
class ProblemListView {
const status_view = new StatusView('#status-container');
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("#", "");
......@@ -213,9 +245,8 @@ $(function(){
}else{
status_view.show_problem(hash);
}
problem_list_view.refresh();
}).trigger('hashchange');
refresh_problems();
});
......@@ -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 %}
......
......@@ -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>
......
......@@ -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'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment