Commit c2566bbc authored by Kento HASEGAWA's avatar Kento HASEGAWA

Add solution viewer

parent 2dcebcae
......@@ -16,6 +16,10 @@ def webui_index():
# return adc2019system.role.role
return render_template('index.html')
@webui.route('/view/solution')
def webui_view_solution():
return render_template('view-solution.html')
@webui.route('/part/problems')
def webui_part_problems():
if (adc2019system.role is not None) and (adc2019system.role.type == 'host'):
......
......@@ -94,6 +94,22 @@ class Host(object):
return self.request[request_id].get_status()
else:
return {'status': 'unknown request'}
def get_solution_for_viewer(self, problem_key, solution_id):
problem = self.get_problem(problem_key)
if problem is None:
return None
problem_data = problem.get_d3json()
solution = problem.get_solution(solution_id)
if solution is None:
return None
solution_data = solution.get_d3json()
return {
'problem': problem_data,
'solution': solution_data
}
def call_api(self, method, cmd, params):
if cmd == 'role':
......@@ -109,6 +125,10 @@ class Host(object):
elif cmd == 'request/status':
request_id = float(params['request_id'])
return self.get_request_status(request_id)
elif cmd == 'view/solution':
problem_key = params['problem']
solution_id = params['solution']
return self.get_solution_for_viewer(problem_key, solution_id)
else:
return None
......
This diff is collapsed.
......@@ -30,7 +30,7 @@ class StatusView {
_this.container.find('.solution-detail-row td').click((e) => {
var solution_id = $(e.target).parent("tr").data("solution-id");
var problem_name = $(e.target).parent("tr").data("problem");
var viewer_url = "/viewer/solution#" + problem_name + "/" + solution_id;
var viewer_url = "/view/solution#" + problem_name + "/" + solution_id;
window.open(viewer_url, "_blank");
})
});
......@@ -59,7 +59,7 @@ class StatusView {
show: true
});
_this.container.find('#solver-processing-modal').on('hidden.bs.modal', function(e){
console.log(e);
// console.log(e);
_this.show_problem();
})
......@@ -78,7 +78,7 @@ class StatusView {
_this.container.find('#request-status-container').html(d);
status = $(d).find('#request-status-value').text();
console.log(status);
// console.log(status);
if(status == 'done'){
_this.request_refresh_timer = null;
}else{
......
<!DOCTYPE html>
<html>
<head>
<title>ADC2019 Solver System</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/adc2019.css">
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.bundle.min.js"></script>
<script src="/static/js/d3.min.js"></script>
<script src="/static/js/adc2019-viewer.js"></script>
<style>
.axis path {
display: none;
}
.axis line {
stroke-opacity: 0.3;
shape-rendering: crispEdges;
}
input[type="range"] {
right: 0;
top: 0;
position: absolute;
}
svg{
width: 100%;
height: 100vh;
display: block;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="control-panel-wrapper" class="container-fluid">
<div id="board-container"></div>
</div>
</div>
</body>
</html>
import datetime
import json
import os
import re
import time
import uuid
......@@ -12,6 +13,7 @@ class Problem(object):
self.name = ''
self.size = (0, 0)
self.block_num = 0
self.blocks = dict()
self.problem = ''
self.status = 'Ready'
self.solutions = dict()
......@@ -27,22 +29,51 @@ class Problem(object):
with open(path, 'r') as fp:
q_text = fp.read()
q_lines = fp.readlines()
q_lines = q_text.splitlines()
board_size = [0, 0]
block_num = 0
blocks = dict()
def intplus(v):
if v.isdecimal():
return int(v)
else:
return v
for _l in q_lines:
li = 0
while li < len(q_lines):
_l = q_lines[li]
if "SIZE" in _l:
board_size_str = _l.strip().split()[1]
board_size = [int(v) for v in board_size_str.split('X')]
if 'BLOCK_NUM' in _l:
block_num = int(_l.strip().split()[1])
if 'BLOCK#' in _l:
p = r'BLOCK#([0-9]+) +([0-9]+)X([0-9]+)'
m = re.match(p, _l.strip())
bi = int(m.group(1))
bw = int(m.group(2))
bh = int(m.group(3))
blocks[bi] = {
'index': bi,
'w': bw,
'h': bh,
'cells': list()
}
for _h in range(bh):
li += 1
_l = q_lines[li].strip()
blocks[bi]['cells'].append([intplus(v.strip()) for v in _l.split(',')])
li += 1
name = os.path.splitext(os.path.basename(path))[0]
self.size = board_size
self.block_num = block_num
self.blocks = blocks
self.name = name
self.problem = q_text
self.status = 'Ready'
......@@ -56,6 +87,15 @@ class Problem(object):
'problem': self.problem,
'status': self.status
}
def get_d3json(self):
return {
'block': self.blocks,
'w': self.size[0],
'h': self.size[1],
'n': self.block_num
}
def put_solution(self, data):
solution = Solution(data)
......@@ -68,6 +108,12 @@ class Problem(object):
def get_solutions(self):
return self.solutions
def get_solution(self, solution_id):
if solution_id in self.solutions:
return self.solutions[solution_id]
else:
return None
class Solution(object):
......@@ -96,6 +142,51 @@ class Solution(object):
'solution': self.solution
}
def get_d3json(self):
board_size = [0, 0]
block_num = 0
_lines = self.solution.splitlines()
li = 0
bw, bh = 0, 0
bmap = list()
bposition = dict()
while li < len(_lines):
_l = _lines[li].strip()
if 'SIZE' in _l:
board_size_str = _l.strip().split()[1]
board_solution_size = [int(v) for v in board_size_str.split('X')]
bw = board_solution_size[0]
bh = board_solution_size[1]
for _h in range(bh):
li += 1
_l = _lines[li].strip()
bmap.append([int(v.strip()) for v in _l.split(',')])
if 'BLOCK' in _l:
p = r'BLOCK#([0-9]+) +@\(([0-9]+), *([0-9]+)\)'
m = re.match(p, _l.strip())
bi = int(m.group(1))
bx = int(m.group(2))
by = int(m.group(3))
bposition[bi] = {
'index': bi,
'x': bx,
'y': by,
}
li += 1
return {
'w': bw,
'h': bh,
'map': bmap,
'block': bposition
}
def save(self, basedir):
outdir = f"{basedir}/{self.problem}"
if not os.path.exists(outdir):
......
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