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
bffa7d2f
Commit
bffa7d2f
authored
Aug 26, 2019
by
Kento HASEGAWA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve UI and adccli co-operation
parent
f3ba4ba7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
48 deletions
+67
-48
host.py
roles/host.py
+46
-33
solver.py
roles/solver.py
+3
-3
adc2019.js
static/js/adc2019.js
+6
-4
adcclilib.py
utils/adcclilib.py
+8
-8
data.py
utils/data.py
+4
-0
No files found.
roles/host.py
View file @
bffa7d2f
import
glob
import
glob
import
json
import
json
import
os
import
sys
import
sys
import
threading
import
threading
import
time
import
time
...
@@ -207,6 +208,9 @@ class Host(object):
...
@@ -207,6 +208,9 @@ class Host(object):
return
{
'status'
:
'stopped'
}
return
{
'status'
:
'stopped'
}
elif
cmd
==
'worker/status'
:
elif
cmd
==
'worker/status'
:
self
.
worker_manager
.
update_status
(
params
[
'address'
],
params
[
'status'
])
self
.
worker_manager
.
update_status
(
params
[
'address'
],
params
[
'status'
])
if
'request_id'
in
params
[
'params'
]:
request_id
=
params
[
'params'
][
'request_id'
]
self
.
request
[
request_id
]
.
set_running
()
return
{
'status'
:
'updated'
}
return
{
'status'
:
'updated'
}
elif
cmd
==
'view'
:
elif
cmd
==
'view'
:
problem_key
=
params
[
'problem'
]
problem_key
=
params
[
'problem'
]
...
@@ -219,28 +223,28 @@ class Host(object):
...
@@ -219,28 +223,28 @@ class Host(object):
r
=
adccli
.
logout
()
r
=
adccli
.
logout
()
return
{
'status'
:
r
}
return
{
'status'
:
r
}
elif
cmd
==
'adccli/whoami'
:
elif
cmd
==
'adccli/whoami'
:
r
=
adccli
.
whoami
()
r
=
adccli
.
whoami
()
.
strip
()
return
{
'
message'
:
r
,
'status'
:
r
==
self
.
config
[
'adccli
'
]}
return
{
'
status'
:
r
,
'is_logged_in'
:
r
==
self
.
config
[
'adccli'
][
'username
'
]}
elif
cmd
==
'adccli/download-problem'
:
elif
cmd
==
'adccli/download-problem'
:
out_abspath
=
os
.
path
.
abspath
(
self
.
config
[
'problem_path'
]
)
out_abspath
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
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'
])
return
{
'status'
:
r
}
return
{
'status'
:
r
}
elif
cmd
==
'adccli/upload-solution'
:
elif
cmd
==
'adccli/upload-solution'
:
problem_key
=
params
[
'problem'
]
problem_key
=
params
[
'problem'
]
problem
=
self
.
problems
[
problem_key
]
problem
=
self
.
problems
[
problem_key
]
if
problem
.
best_solution
_key
is
None
:
if
problem
.
best_solution
is
None
:
res
=
{
'status'
:
"Required to 'save' before submission"
}
res
=
{
'status'
:
"Required to 'save' before submission"
}
else
:
else
:
solution_path
=
f
"{self.config['solution_path']}/
{problem_key}/
submit/{problem_key}.txt"
solution_path
=
f
"{self.config['solution_path']}/submit/{problem_key}.txt"
qnumber
=
problem_key
.
replace
(
"
NL_
Q"
,
""
)
.
replace
(
".txt"
,
""
)
qnumber
=
problem_key
.
replace
(
"Q"
,
""
)
.
replace
(
".txt"
,
""
)
solution_abspath
=
os
.
path
.
abspath
(
solution_path
)
solution_abspath
=
os
.
path
.
abspath
(
solution_path
)
r
=
adccli
.
put_a
(
qnumber
,
solution_abspath
)
r
=
adccli
.
put_a
(
qnumber
,
solution_abspath
)
mes
=
r
+
"
\n
"
mes
=
r
+
"
\n
"
best_solution_key
=
problem
.
best_solution
_key
best_solution_key
=
problem
.
best_solution
best_solution
=
problem
.
get_solution
(
best_solution_key
)
best_solution
=
problem
.
get_solution
(
best_solution_key
)
cputime
=
f
'{best_solution.elapsed_time:.3f}'
cputime
=
f
'{best_solution.elapsed_time:.3f}'
info_mes
=
f
'Solver: {best_solution.worker}, RID: {best_solution.request_id}'
info_mes
=
f
'Solver: {best_solution.worker}, RID: {best_solution.request_id}'
...
@@ -359,17 +363,11 @@ class Request(object):
...
@@ -359,17 +363,11 @@ class Request(object):
self
.
request_id
=
time
.
time
()
self
.
request_id
=
time
.
time
()
self
.
request_time
=
None
self
.
request_time
=
None
self
.
start_time
=
None
self
.
done_time
=
None
self
.
done_time
=
None
# if solvers is None:
# self.solvers = list(self.worker_manager.get_workers().keys())
# else:
# self.solvers = solvers
self
.
solver
=
worker
self
.
solver
=
worker
self
.
response
=
dict
()
# for w in self.solvers:
# self.response[w] = list()
self
.
response
=
list
()
self
.
response
=
list
()
if
self
.
solver
.
partial_mode
:
if
self
.
solver
.
partial_mode
:
...
@@ -379,6 +377,8 @@ class Request(object):
...
@@ -379,6 +377,8 @@ class Request(object):
self
.
part_nums
=
1
self
.
part_nums
=
1
self
.
solved
=
[
0
]
self
.
solved
=
[
0
]
self
.
is_processed
=
False
@
property
@
property
def
request_data
(
self
):
def
request_data
(
self
):
data
=
self
.
data
data
=
self
.
data
...
@@ -392,6 +392,10 @@ class Request(object):
...
@@ -392,6 +392,10 @@ class Request(object):
def
get_dict
(
self
):
def
get_dict
(
self
):
return
self
.
request_data
return
self
.
request_data
def
set_running
(
self
):
self
.
is_processed
=
True
self
.
start_time
=
time
.
time
()
def
store_response
(
self
,
data
):
def
store_response
(
self
,
data
):
# worker = data['worker']
# worker = data['worker']
# self.response[worker].append(data)
# self.response[worker].append(data)
...
@@ -419,35 +423,44 @@ class Request(object):
...
@@ -419,35 +423,44 @@ class Request(object):
status
=
''
status
=
''
if
self
.
solved
[
-
1
]
==
1
:
if
self
.
solved
[
-
1
]
==
1
:
elapsed_time
=
self
.
done_time
-
self
.
request_time
if
self
.
start_time
is
None
:
self
.
start_time
=
time
.
time
()
elapsed_time
=
self
.
done_time
-
self
.
start_time
et_minutes
=
int
(
elapsed_time
//
60
)
et_minutes
=
int
(
elapsed_time
//
60
)
et_seconds
=
int
(
elapsed_time
%
60
)
et_seconds
=
int
(
elapsed_time
%
60
)
status
=
f
'done ({self.solved[-1]}) [{et_minutes}:{et_seconds:02}]'
status
=
f
'done ({self.solved[-1]}) [{et_minutes}:{et_seconds:02}]'
elif
self
.
solved
[
-
1
]
==
-
1
:
elif
self
.
solved
[
-
1
]
==
-
1
:
status
=
'failed'
if
self
.
start_time
is
None
:
self
.
start_time
=
time
.
time
()
elapsed_time
=
self
.
done_time
-
self
.
start_time
et_minutes
=
int
(
elapsed_time
//
60
)
et_seconds
=
int
(
elapsed_time
%
60
)
status
=
f
'failed [{et_minutes}:{et_seconds:02}]'
else
:
else
:
if
self
.
solver
.
status
==
'Not connected'
:
if
self
.
solver
.
status
==
'Not connected'
:
status
=
'Not connected'
status
=
'Not connected'
else
:
else
:
if
self
.
is_processed
:
if
len
(
self
.
solved
)
==
1
:
if
len
(
self
.
solved
)
==
1
:
status_mes
=
'Running'
status_mes
=
'Running'
elif
len
(
self
.
solved
)
>
1
:
elif
len
(
self
.
solved
)
>
1
:
counter
=
sum
([
v
>
0
for
v
in
self
.
solved
])
counter
=
sum
([
v
>
0
for
v
in
self
.
solved
])
status_mes
=
f
'{counter}/{len(self.solved)}'
status_mes
=
f
'{counter}/{len(self.solved)}'
elapsed_time
=
time
.
time
()
-
self
.
request_time
if
self
.
start_time
is
None
:
self
.
start_time
=
time
.
time
()
elapsed_time
=
time
.
time
()
-
self
.
start_time
et_minutes
=
int
(
elapsed_time
//
60
)
et_minutes
=
int
(
elapsed_time
//
60
)
et_seconds
=
int
(
elapsed_time
%
60
)
et_seconds
=
int
(
elapsed_time
%
60
)
elapsed_time_str
=
f
'{et_minutes}:{et_seconds:02}'
elapsed_time_str
=
f
'{et_minutes}:{et_seconds:02}'
status
=
f
'{status_mes} [{elapsed_time_str}]'
status
=
f
'{status_mes} [{elapsed_time_str}]'
else
:
status
=
'Queued'
return
{
return
{
'status'
:
status
,
'status'
:
status
,
'worker'
:
self
.
solver
.
address
,
'worker'
:
self
.
solver
.
address
# 'solutions': response_count,
# 'progress': progress,
# 'worker_status': worker_status
}
}
def
broadcast
(
self
):
def
broadcast
(
self
):
...
...
roles/solver.py
View file @
bffa7d2f
...
@@ -37,9 +37,9 @@ class Solver(object):
...
@@ -37,9 +37,9 @@ class Solver(object):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"Solver"
return
"Solver"
def
set_status
(
self
,
status
):
def
set_status
(
self
,
status
,
params
=
dict
()
):
self
.
status
=
status
self
.
status
=
status
self
.
post
(
'worker/status'
,
{
'address'
:
self
.
address
,
'status'
:
self
.
status
})
self
.
post
(
'worker/status'
,
{
'address'
:
self
.
address
,
'status'
:
self
.
status
,
'params'
:
params
})
def
solver_thread
(
self
):
def
solver_thread
(
self
):
...
@@ -48,7 +48,7 @@ class Solver(object):
...
@@ -48,7 +48,7 @@ class Solver(object):
print
(
"I: Solver started"
)
print
(
"I: Solver started"
)
_
,
params
=
self
.
queue
.
popitem
(
last
=
False
)
_
,
params
=
self
.
queue
.
popitem
(
last
=
False
)
self
.
solving
=
params
self
.
solving
=
params
self
.
set_status
(
f
'Running ({len(self.queue)} in queue)'
)
self
.
set_status
(
f
'Running ({len(self.queue)} in queue)'
,
params
=
{
'request_id'
:
params
[
'request_id'
]}
)
try
:
try
:
self
.
solve
(
params
)
self
.
solve
(
params
)
except
Exception
as
e
:
except
Exception
as
e
:
...
...
static/js/adc2019.js
View file @
bffa7d2f
...
@@ -42,7 +42,7 @@ class StatusView {
...
@@ -42,7 +42,7 @@ class StatusView {
});
});
_this
.
container
.
find
(
'.submit-button'
).
click
(()
=>
{
_this
.
container
.
find
(
'.submit-button'
).
click
(()
=>
{
_this
.
save
_solution
();
_this
.
upload
_solution
();
});
});
_this
.
container
.
find
(
'#chk-solver-all'
).
prop
(
'checked'
,
false
);
_this
.
container
.
find
(
'#chk-solver-all'
).
prop
(
'checked'
,
false
);
...
@@ -162,7 +162,7 @@ class StatusView {
...
@@ -162,7 +162,7 @@ class StatusView {
}),
}),
contentType
:
'application/json'
contentType
:
'application/json'
}).
done
((
d
)
=>
{
}).
done
((
d
)
=>
{
alert
(
d
);
alert
(
d
[
'status'
]
);
});
});
}
}
...
@@ -208,6 +208,8 @@ class StatusView {
...
@@ -208,6 +208,8 @@ class StatusView {
_this
.
container
.
empty
();
_this
.
container
.
empty
();
_this
.
container
.
html
(
d
);
_this
.
container
.
html
(
d
);
clearInterval
(
_this
.
request_refresh_timer
);
var
button_action_with_ajax
=
function
(
$obj
,
url
){
var
button_action_with_ajax
=
function
(
$obj
,
url
){
$obj
.
prop
(
"disabled"
,
"disabled"
);
$obj
.
prop
(
"disabled"
,
"disabled"
);
$
.
ajax
({
$
.
ajax
({
...
@@ -216,7 +218,7 @@ class StatusView {
...
@@ -216,7 +218,7 @@ class StatusView {
dataType
:
"json"
,
dataType
:
"json"
,
}).
done
((
data
)
=>
{
}).
done
((
data
)
=>
{
$obj
.
prop
(
"disabled"
,
false
);
$obj
.
prop
(
"disabled"
,
false
);
alert
(
data
[
'
message
'
]);
alert
(
data
[
'
status
'
]);
});
});
};
};
...
@@ -262,7 +264,7 @@ class StatusView {
...
@@ -262,7 +264,7 @@ class StatusView {
url
:
"/api/adccli/whoami"
,
url
:
"/api/adccli/whoami"
,
dataType
:
"json"
,
dataType
:
"json"
,
}).
done
((
data
)
=>
{
}).
done
((
data
)
=>
{
if
(
data
[
'
status
'
])
if
(
data
[
'
is_logged_in
'
])
$
(
"#adccli-status"
).
text
(
"ログイン中"
);
$
(
"#adccli-status"
).
text
(
"ログイン中"
);
else
else
$
(
"#adccli-status"
).
text
(
"ログアウト"
);
$
(
"#adccli-status"
).
text
(
"ログアウト"
);
...
...
utils/adcclilib.py
View file @
bffa7d2f
...
@@ -8,9 +8,8 @@ ADCCLI = f"{BASEDIR}/../adc2019/client/adccli"
...
@@ -8,9 +8,8 @@ ADCCLI = f"{BASEDIR}/../adc2019/client/adccli"
def
_exec_adccli
(
cmd
):
def
_exec_adccli
(
cmd
):
exec_cmd
=
f
"{PYTHON_BIN} {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
...
@@ -27,7 +26,7 @@ def whoami():
...
@@ -27,7 +26,7 @@ def whoami():
return
_exec_adccli
(
cmd
)
return
_exec_adccli
(
cmd
)
def
put_message
(
message
):
def
put_message
(
message
):
cmd
=
"put-user-ali
v
e '{}'"
cmd
=
"put-user-ali
l
e '{}'"
return
_exec_adccli
(
cmd
)
return
_exec_adccli
(
cmd
)
def
post_user_q
(
qnum
,
filepath
):
def
post_user_q
(
qnum
,
filepath
):
...
@@ -41,10 +40,11 @@ def get_q_all(outpath):
...
@@ -41,10 +40,11 @@ def get_q_all(outpath):
print
(
"--- ADCCLI questions ---"
)
print
(
"--- ADCCLI questions ---"
)
print
(
question_list
)
print
(
question_list
)
for
v
in
question_list
:
for
l
in
question_list
:
if
v
.
startswith
(
"Q"
):
if
l
.
startswith
(
"Q"
):
qnumber
=
int
(
v
.
replace
(
"Q"
,
""
))
v
=
l
.
split
()
out_file_path
=
"{}/NL_Q{:02d}.txt"
.
format
(
outpath
,
qnumber
)
qnumber
=
int
(
v
[
0
]
.
replace
(
"Q"
,
""
))
out_file_path
=
"{}/Q{:02d}.txt"
.
format
(
outpath
,
qnumber
)
cmd
=
"--output {} get-q {}"
.
format
(
out_file_path
,
qnumber
)
cmd
=
"--output {} get-q {}"
.
format
(
out_file_path
,
qnumber
)
r
=
_exec_adccli
(
cmd
)
r
=
_exec_adccli
(
cmd
)
...
...
utils/data.py
View file @
bffa7d2f
...
@@ -525,6 +525,10 @@ class Solution(object):
...
@@ -525,6 +525,10 @@ class Solution(object):
else
:
else
:
return
'-'
return
'-'
@
property
def
nlcheck_str
(
self
):
return
f
'{self.nlcheck:.4f}'
def
is_valid_solution
(
self
):
def
is_valid_solution
(
self
):
return
self
.
status
==
'done'
return
self
.
status
==
'done'
...
...
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