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
f3ba4ba7
Commit
f3ba4ba7
authored
Aug 26, 2019
by
Kento HASEGAWA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for adc2019 official tools
parent
9d989358
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
95 additions
and
46 deletions
+95
-46
.gitmodules
.gitmodules
+3
-0
Makefile
Makefile
+2
-0
adc2019
adc2019
+1
-0
host.py
roles/host.py
+26
-31
adc2019.js
static/js/adc2019.js
+25
-4
part_solution_status.html
templates/part_solution_status.html
+1
-0
adcclilib.py
utils/adcclilib.py
+10
-9
data.py
utils/data.py
+27
-2
No files found.
.gitmodules
View file @
f3ba4ba7
...
@@ -13,3 +13,6 @@
...
@@ -13,3 +13,6 @@
[submodule "solvers/nszw"]
[submodule "solvers/nszw"]
path = solvers/nszw
path = solvers/nszw
url = git@togawa-gitlab:adc2019/nszw-solver.git
url = git@togawa-gitlab:adc2019/nszw-solver.git
[submodule "adc2019"]
path = adc2019
url = https://github.com/dasadc/adc2019.git
Makefile
View file @
f3ba4ba7
...
@@ -2,3 +2,5 @@
...
@@ -2,3 +2,5 @@
.PHONY
:
clean
.PHONY
:
clean
clean
:
clean
:
rm
-rf
./solutions/
*
rm
-rf
./solutions/
*
rm
-rf
./solvers/hsgw/P
*
.txt
rm
-rf
./solvers/kwmr/A
*
.txt
adc2019
@
a4084656
Subproject commit a40846560bf682e7a6165ae50216c7bb49dccd26
roles/host.py
View file @
f3ba4ba7
...
@@ -7,6 +7,7 @@ import requests
...
@@ -7,6 +7,7 @@ import requests
from
utils
import
Problem
,
GroupPart
from
utils
import
Problem
,
GroupPart
import
utils.adcclilib
as
adccli
import
utils.adcclilib
as
adccli
# import adc2019.client.adcclient
class
Host
(
object
):
class
Host
(
object
):
...
@@ -212,47 +213,41 @@ class Host(object):
...
@@ -212,47 +213,41 @@ class Host(object):
solution_id
=
params
[
'solution'
]
solution_id
=
params
[
'solution'
]
return
self
.
get_viewer_data
(
problem_key
,
solution_id
)
return
self
.
get_viewer_data
(
problem_key
,
solution_id
)
elif
cmd
==
'adccli/login'
:
elif
cmd
==
'adccli/login'
:
with
open
(
'path-to-adccli-login'
,
'r'
)
as
fp
:
r
=
adccli
.
login
(
self
.
config
[
'adccli'
][
'url'
],
self
.
config
[
'adccli'
][
'username'
],
self
.
config
[
'adccli'
][
'password'
])
d
=
json
.
load
(
fp
)
return
{
'status'
:
r
}
r
=
adccli
.
login
(
d
[
'url'
],
d
[
'username'
],
d
[
'password'
])
res
=
{
'message'
:
r
}
return
json
.
dumps
(
res
)
elif
cmd
==
'adccli/logout'
:
elif
cmd
==
'adccli/logout'
:
r
=
adccli
.
logout
()
r
=
adccli
.
logout
()
res
=
{
'message'
:
r
}
return
{
'status'
:
r
}
return
json
.
dumps
(
res
)
elif
cmd
==
'adccli/whoami'
:
elif
cmd
==
'adccli/whoami'
:
with
open
(
'path-to-adccli-login'
,
'r'
)
as
fp
:
d
=
json
.
load
(
fp
)
r
=
adccli
.
whoami
()
r
=
adccli
.
whoami
()
res
=
{
'message'
:
r
,
'status'
:
r
==
d
[
'username'
]}
return
{
'message'
:
r
,
'status'
:
r
==
self
.
config
[
'adccli'
]}
return
json
.
dumps
(
res
)
elif
cmd
==
'adccli/download-problem'
:
elif
cmd
==
'adccli/download-problem'
:
out_abspath
=
os
.
path
.
abspath
(
self
.
config
[
'problem_path'
])
out_abspath
=
os
.
path
.
abspath
(
self
.
config
[
'problem_path'
])
r
=
adccli
.
get_q_all
(
out_abspath
)
r
=
adccli
.
get_q_all
(
out_abspath
)
self
.
_load_problems
(
self
.
config
[
'problem_path'
])
self
.
_load_problems
(
self
.
config
[
'problem_path'
])
res
=
{
'message'
:
r
}
return
{
'status'
:
r
}
return
json
.
dumps
(
res
)
elif
cmd
==
'adccli/upload-solution'
:
elif
cmd
==
'adccli/upload-solution'
:
qname
=
params
[
'problem'
]
problem_key
=
params
[
'problem'
]
if
not
"best_json"
in
questions
[
qname
]:
problem
=
self
.
problems
[
problem_key
]
res
=
{
'message'
:
"Required to 'save' before submission"
}
if
problem
.
best_solution_key
is
None
:
res
=
{
'status'
:
"Required to 'save' before submission"
}
else
:
else
:
out_path
=
"{}/{}"
.
format
(
self
.
config
[
'solution_path'
],
"submit"
)
solution_path
=
f
"{self.config['solution_path']}/{problem_key}/submit/{problem_key}.txt"
# qnumber = qname.replace("NL_Q", "").replace(".txt", "")
qnumber
=
problem_key
.
replace
(
"NL_Q"
,
""
)
.
replace
(
".txt"
,
""
)
# ans_file_path = "{}/T01_A{}.txt".format(out_path, qnumber)
# ans_file_abspath = os.path.abspath(ans_file_path)
solution_abspath
=
os
.
path
.
abspath
(
solution_path
)
# r = adccli.put_a(qnumber, ans_file_abspath)
r
=
adccli
.
put_a
(
qnumber
,
solution_abspath
)
# mes = r + "\n"
mes
=
r
+
"
\n
"
# json_name = questions[qname]['best_json']
best_solution_key
=
problem
.
best_solution_key
# data = questions[qname]['answers'][json_name]
best_solution
=
problem
.
get_solution
(
best_solution_key
)
# r = adccli.put_a_info(qnumber, data['cputime'], "0", "Test")
cputime
=
f
'{best_solution.elapsed_time:.3f}'
# mes += r
info_mes
=
f
'Solver: {best_solution.worker}, RID: {best_solution.request_id}'
mes
=
''
r
=
adccli
.
put_a_info
(
qnumber
,
cputime
,
"0"
,
info_mes
)
res
=
{
'message'
:
mes
}
mes
+=
r
return
json
.
dumps
(
res
)
res
=
{
'status'
:
mes
}
return
res
else
:
else
:
return
None
return
None
...
...
static/js/adc2019.js
View file @
f3ba4ba7
...
@@ -41,6 +41,10 @@ class StatusView {
...
@@ -41,6 +41,10 @@ class StatusView {
_this
.
fire
(
'refresh'
);
_this
.
fire
(
'refresh'
);
});
});
_this
.
container
.
find
(
'.submit-button'
).
click
(()
=>
{
_this
.
save_solution
();
});
_this
.
container
.
find
(
'#chk-solver-all'
).
prop
(
'checked'
,
false
);
_this
.
container
.
find
(
'#chk-solver-all'
).
prop
(
'checked'
,
false
);
_this
.
container
.
find
(
'#chk-solver-all'
).
on
(
'change'
,
(
e
)
=>
{
_this
.
container
.
find
(
'#chk-solver-all'
).
on
(
'change'
,
(
e
)
=>
{
...
@@ -145,6 +149,23 @@ class StatusView {
...
@@ -145,6 +149,23 @@ class StatusView {
});
});
}
}
// アップロード
upload_solution
(){
var
_this
=
this
;
$
.
ajax
({
type
:
"POST"
,
dataType
:
"json"
,
url
:
"/api/adccli/upload-solution"
,
data
:
JSON
.
stringify
({
"problem"
:
_this
.
problem_key
}),
contentType
:
'application/json'
}).
done
((
d
)
=>
{
alert
(
d
);
});
}
update_status_view
(){
update_status_view
(){
var
_this
=
this
;
var
_this
=
this
;
$
.
ajax
({
$
.
ajax
({
...
@@ -227,18 +248,18 @@ class StatusView {
...
@@ -227,18 +248,18 @@ class StatusView {
});
});
$
(
"#adccli-login-button"
).
click
(
function
(){
$
(
"#adccli-login-button"
).
click
(
function
(){
button_action_with_ajax
(
$
(
this
),
"/a
dccli-
login"
);
button_action_with_ajax
(
$
(
this
),
"/a
pi/adccli/
login"
);
});
});
$
(
"#adccli-logout-button"
).
click
(
function
(){
$
(
"#adccli-logout-button"
).
click
(
function
(){
button_action_with_ajax
(
$
(
this
),
"/a
dccli-
logout"
);
button_action_with_ajax
(
$
(
this
),
"/a
pi/adccli/
logout"
);
});
});
$
(
"#adccli-get-all-q"
).
click
(
function
(){
$
(
"#adccli-get-all-q"
).
click
(
function
(){
button_action_with_ajax
(
$
(
this
),
"/a
dccli-get-all-q
"
);
button_action_with_ajax
(
$
(
this
),
"/a
pi/adccli/download-problem
"
);
});
});
$
.
ajax
({
$
.
ajax
({
type
:
"GET"
,
type
:
"GET"
,
url
:
"/a
dccli-
whoami"
,
url
:
"/a
pi/adccli/
whoami"
,
dataType
:
"json"
,
dataType
:
"json"
,
}).
done
((
data
)
=>
{
}).
done
((
data
)
=>
{
if
(
data
[
'status'
])
if
(
data
[
'status'
])
...
...
templates/part_solution_status.html
View file @
f3ba4ba7
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
{% else %}
{% else %}
{{v.status}}
{{v.status}}
{% endif %}
{% endif %}
{{v.nlcheck}}
</td>
</td>
</tr>
</tr>
{% endfor %}
{% endfor %}
...
...
utils/adcclilib.py
View file @
f3ba4ba7
#!/usr/bin/env python3
import
os
import
subprocess
import
subprocess
PYTHON2
=
"/usr/bin/python"
PYTHON_BIN
=
"python3"
ADCCLI
=
"/home/pi/adc2018/conmgr/client/adccli"
BASEDIR
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
))
ADCCLI
=
f
"{BASEDIR}/../adc2019/client/adccli"
def
_exec_adccli
(
cmd
):
def
_exec_adccli
(
cmd
):
exec_cmd
=
"{} {} {}"
.
format
(
PYTHON2
,
ADCCLI
,
cmd
)
.
strip
()
exec_cmd
=
f
"{PYTHON_BIN} {ADCCLI} {cmd}"
.
strip
()
print
(
"ADCCLI: {}"
.
format
(
exec_cmd
))
print
(
"ADCCLI: {}"
.
format
(
exec_cmd
))
p
=
subprocess
.
run
(
exec_cmd
,
stdout
=
subprocess
.
PIPE
,
shell
=
True
)
# p = subprocess.run(exec_cmd, stdout=subprocess.PIPE, shell=True)
res
=
p
.
stdout
.
decode
()
.
strip
()
# res = p.stdout.decode().strip()
res
=
''
print
(
res
)
print
(
res
)
return
res
return
res
def
login
(
url
,
username
,
password
):
def
login
(
url
,
username
,
password
):
cmd
=
"--URL='{}' --username='{}' --password='{}' login"
.
format
(
url
,
username
,
password
)
cmd
=
f
"--URL='{url}' --username='{username}' --password='{password}' login"
return
_exec_adccli
(
cmd
)
return
_exec_adccli
(
cmd
)
def
logout
():
def
logout
():
...
@@ -35,7 +36,7 @@ def post_user_q(qnum, filepath):
...
@@ -35,7 +36,7 @@ def post_user_q(qnum, filepath):
def
get_q_all
(
outpath
):
def
get_q_all
(
outpath
):
cmd
=
"get-q"
cmd
=
"get-q"
question_list
=
_exec_adccli
(
cmd
)
.
split
(
"
\n
"
)
question_list
=
_exec_adccli
(
cmd
)
.
split
lines
(
)
print
(
"--- ADCCLI questions ---"
)
print
(
"--- ADCCLI questions ---"
)
print
(
question_list
)
print
(
question_list
)
...
...
utils/data.py
View file @
f3ba4ba7
...
@@ -5,6 +5,7 @@ import math
...
@@ -5,6 +5,7 @@ import math
import
os
import
os
import
queue
import
queue
import
re
import
re
import
subprocess
import
time
import
time
import
uuid
import
uuid
...
@@ -353,6 +354,24 @@ class Problem(object):
...
@@ -353,6 +354,24 @@ class Problem(object):
print
(
f
'I: Put a solution: {solution_id}'
)
print
(
f
'I: Put a solution: {solution_id}'
)
self
.
solutions
[
solution_id
]
=
solution
self
.
solutions
[
solution_id
]
=
solution
if
solution
.
status
==
'done'
:
problem_path
=
self
.
path
solution_path
=
f
'{self.solution_path}/{self.name}/tmp-{solution.request_id}-{solution.worker}.txt'
with
open
(
solution_path
,
'w'
)
as
fp
:
fp
.
write
(
solution
.
solution
)
BASEDIR
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
))
NLCHECK
=
f
"{BASEDIR}/../adc2019/server/adc2019.py"
exec_cmd
=
f
"python3 {NLCHECK} --Q-file {problem_path} --A-file {solution_path}"
.
strip
()
print
(
"ADCCLI: {}"
.
format
(
exec_cmd
))
p
=
subprocess
.
run
(
exec_cmd
,
stdout
=
subprocess
.
PIPE
,
shell
=
True
)
try
:
res
=
float
(
p
.
stdout
.
decode
()
.
strip
())
except
:
res
=
-
1
solution
.
nlcheck
=
res
# Save solution
# Save solution
solution
.
save
(
self
.
solution_path
)
solution
.
save
(
self
.
solution_path
)
...
@@ -425,6 +444,11 @@ class Solution(object):
...
@@ -425,6 +444,11 @@ class Solution(object):
self
.
solution
=
data
[
'solution'
]
self
.
solution
=
data
[
'solution'
]
self
.
status
=
data
[
'status'
]
self
.
status
=
data
[
'status'
]
if
'nlcheck'
in
data
:
self
.
nlcheck
=
data
[
'nlcheck'
]
else
:
self
.
nlcheck
=
-
1
self
.
size
=
(
None
,
None
)
self
.
size
=
(
None
,
None
)
self
.
map
=
None
self
.
map
=
None
self
.
block
=
dict
()
self
.
block
=
dict
()
...
@@ -516,7 +540,8 @@ class Solution(object):
...
@@ -516,7 +540,8 @@ class Solution(object):
'elapsed_time'
:
self
.
elapsed_time
,
'elapsed_time'
:
self
.
elapsed_time
,
'problem'
:
self
.
problem
,
'problem'
:
self
.
problem
,
'solution'
:
self
.
solution
,
'solution'
:
self
.
solution
,
'status'
:
self
.
status
'status'
:
self
.
status
,
'nlcheck'
:
self
.
nlcheck
}
}
def
get_d3json
(
self
):
def
get_d3json
(
self
):
...
...
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