Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
adc2019-system
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
adc2019
adc2019-system
Commits
c2566bbc
You need to sign in or sign up before continuing.
Commit
c2566bbc
authored
Jul 24, 2019
by
Kento HASEGAWA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add solution viewer
parent
2dcebcae
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
546 additions
and
5 deletions
+546
-5
main.py
main.py
+4
-0
host.py
roles/host.py
+20
-0
adc2019-viewer.js
static/js/adc2019-viewer.js
+377
-0
adc2019.js
static/js/adc2019.js
+3
-3
view-solution.html
templates/view-solution.html
+49
-0
data.py
utils/data.py
+93
-2
No files found.
main.py
View file @
c2566bbc
...
@@ -16,6 +16,10 @@ def webui_index():
...
@@ -16,6 +16,10 @@ def webui_index():
# return adc2019system.role.role
# return adc2019system.role.role
return
render_template
(
'index.html'
)
return
render_template
(
'index.html'
)
@
webui
.
route
(
'/view/solution'
)
def
webui_view_solution
():
return
render_template
(
'view-solution.html'
)
@
webui
.
route
(
'/part/problems'
)
@
webui
.
route
(
'/part/problems'
)
def
webui_part_problems
():
def
webui_part_problems
():
if
(
adc2019system
.
role
is
not
None
)
and
(
adc2019system
.
role
.
type
==
'host'
):
if
(
adc2019system
.
role
is
not
None
)
and
(
adc2019system
.
role
.
type
==
'host'
):
...
...
roles/host.py
View file @
c2566bbc
...
@@ -94,6 +94,22 @@ class Host(object):
...
@@ -94,6 +94,22 @@ class Host(object):
return
self
.
request
[
request_id
]
.
get_status
()
return
self
.
request
[
request_id
]
.
get_status
()
else
:
else
:
return
{
'status'
:
'unknown request'
}
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
):
def
call_api
(
self
,
method
,
cmd
,
params
):
if
cmd
==
'role'
:
if
cmd
==
'role'
:
...
@@ -109,6 +125,10 @@ class Host(object):
...
@@ -109,6 +125,10 @@ class Host(object):
elif
cmd
==
'request/status'
:
elif
cmd
==
'request/status'
:
request_id
=
float
(
params
[
'request_id'
])
request_id
=
float
(
params
[
'request_id'
])
return
self
.
get_request_status
(
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
:
else
:
return
None
return
None
...
...
static/js/adc2019-viewer.js
0 → 100644
View file @
c2566bbc
This diff is collapsed.
Click to expand it.
static/js/adc2019.js
View file @
c2566bbc
...
@@ -30,7 +30,7 @@ class StatusView {
...
@@ -30,7 +30,7 @@ class StatusView {
_this
.
container
.
find
(
'.solution-detail-row td'
).
click
((
e
)
=>
{
_this
.
container
.
find
(
'.solution-detail-row td'
).
click
((
e
)
=>
{
var
solution_id
=
$
(
e
.
target
).
parent
(
"tr"
).
data
(
"solution-id"
);
var
solution_id
=
$
(
e
.
target
).
parent
(
"tr"
).
data
(
"solution-id"
);
var
problem_name
=
$
(
e
.
target
).
parent
(
"tr"
).
data
(
"problem"
);
var
problem_name
=
$
(
e
.
target
).
parent
(
"tr"
).
data
(
"problem"
);
var
viewer_url
=
"/view
er
/solution#"
+
problem_name
+
"/"
+
solution_id
;
var
viewer_url
=
"/view/solution#"
+
problem_name
+
"/"
+
solution_id
;
window
.
open
(
viewer_url
,
"_blank"
);
window
.
open
(
viewer_url
,
"_blank"
);
})
})
});
});
...
@@ -59,7 +59,7 @@ class StatusView {
...
@@ -59,7 +59,7 @@ class StatusView {
show
:
true
show
:
true
});
});
_this
.
container
.
find
(
'#solver-processing-modal'
).
on
(
'hidden.bs.modal'
,
function
(
e
){
_this
.
container
.
find
(
'#solver-processing-modal'
).
on
(
'hidden.bs.modal'
,
function
(
e
){
console
.
log
(
e
);
//
console.log(e);
_this
.
show_problem
();
_this
.
show_problem
();
})
})
...
@@ -78,7 +78,7 @@ class StatusView {
...
@@ -78,7 +78,7 @@ class StatusView {
_this
.
container
.
find
(
'#request-status-container'
).
html
(
d
);
_this
.
container
.
find
(
'#request-status-container'
).
html
(
d
);
status
=
$
(
d
).
find
(
'#request-status-value'
).
text
();
status
=
$
(
d
).
find
(
'#request-status-value'
).
text
();
console
.
log
(
status
);
//
console.log(status);
if
(
status
==
'done'
){
if
(
status
==
'done'
){
_this
.
request_refresh_timer
=
null
;
_this
.
request_refresh_timer
=
null
;
}
else
{
}
else
{
...
...
templates/view-solution.html
0 → 100644
View file @
c2566bbc
<!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>
utils/data.py
View file @
c2566bbc
import
datetime
import
datetime
import
json
import
json
import
os
import
os
import
re
import
time
import
time
import
uuid
import
uuid
...
@@ -12,6 +13,7 @@ class Problem(object):
...
@@ -12,6 +13,7 @@ class Problem(object):
self
.
name
=
''
self
.
name
=
''
self
.
size
=
(
0
,
0
)
self
.
size
=
(
0
,
0
)
self
.
block_num
=
0
self
.
block_num
=
0
self
.
blocks
=
dict
()
self
.
problem
=
''
self
.
problem
=
''
self
.
status
=
'Ready'
self
.
status
=
'Ready'
self
.
solutions
=
dict
()
self
.
solutions
=
dict
()
...
@@ -27,22 +29,51 @@ class Problem(object):
...
@@ -27,22 +29,51 @@ class Problem(object):
with
open
(
path
,
'r'
)
as
fp
:
with
open
(
path
,
'r'
)
as
fp
:
q_text
=
fp
.
read
()
q_text
=
fp
.
read
()
q_lines
=
fp
.
readlines
()
q_lines
=
q_text
.
splitlines
()
board_size
=
[
0
,
0
]
board_size
=
[
0
,
0
]
block_num
=
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
:
if
"SIZE"
in
_l
:
board_size_str
=
_l
.
strip
()
.
split
()[
1
]
board_size_str
=
_l
.
strip
()
.
split
()[
1
]
board_size
=
[
int
(
v
)
for
v
in
board_size_str
.
split
(
'X'
)]
board_size
=
[
int
(
v
)
for
v
in
board_size_str
.
split
(
'X'
)]
if
'BLOCK_NUM'
in
_l
:
if
'BLOCK_NUM'
in
_l
:
block_num
=
int
(
_l
.
strip
()
.
split
()[
1
])
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
]
name
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
path
))[
0
]
self
.
size
=
board_size
self
.
size
=
board_size
self
.
block_num
=
block_num
self
.
block_num
=
block_num
self
.
blocks
=
blocks
self
.
name
=
name
self
.
name
=
name
self
.
problem
=
q_text
self
.
problem
=
q_text
self
.
status
=
'Ready'
self
.
status
=
'Ready'
...
@@ -56,6 +87,15 @@ class Problem(object):
...
@@ -56,6 +87,15 @@ class Problem(object):
'problem'
:
self
.
problem
,
'problem'
:
self
.
problem
,
'status'
:
self
.
status
'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
):
def
put_solution
(
self
,
data
):
solution
=
Solution
(
data
)
solution
=
Solution
(
data
)
...
@@ -68,6 +108,12 @@ class Problem(object):
...
@@ -68,6 +108,12 @@ class Problem(object):
def
get_solutions
(
self
):
def
get_solutions
(
self
):
return
self
.
solutions
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
):
class
Solution
(
object
):
...
@@ -96,6 +142,51 @@ class Solution(object):
...
@@ -96,6 +142,51 @@ class Solution(object):
'solution'
:
self
.
solution
'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
):
def
save
(
self
,
basedir
):
outdir
=
f
"{basedir}/{self.problem}"
outdir
=
f
"{basedir}/{self.problem}"
if
not
os
.
path
.
exists
(
outdir
):
if
not
os
.
path
.
exists
(
outdir
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment