Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
adc2018-system
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
adc2018
adc2018-system
Commits
48485307
Commit
48485307
authored
Aug 14, 2018
by
Kento HASEGAWA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change to decide resolver at host
parent
aadb00db
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
22 deletions
+46
-22
main.py
comm/server/main.py
+43
-17
index.html
comm/server/templates/index.html
+1
-1
part_question_status.html
comm/server/templates/part_question_status.html
+2
-4
No files found.
comm/server/main.py
View file @
48485307
...
...
@@ -117,12 +117,18 @@ def post():
_answer
=
request
.
form
[
"answer"
]
_client
=
request
.
form
[
"client"
]
if
"solver"
in
request
.
form
:
_solver
=
request
.
form
[
"solver"
]
else
:
_solver
=
_client
receive_time
=
datetime
.
datetime
.
now
()
receive_time_str
=
receive_time
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
)
dat
=
{
"req_id"
:
request
.
form
[
'req_id'
],
"client"
:
_client
,
"solver"
:
_solver
,
"answer"
:
_answer
,
"cputime"
:
request
.
form
[
'cputime'
],
"timestamp"
:
receive_time
.
strftime
(
"
%
Y/
%
m/
%
d
%
H:
%
M:
%
S"
)
...
...
@@ -220,10 +226,18 @@ def solve_questions(qname, qstr):
global
questions
global
current_seed
def
worker
(
host
,
qname
,
qstr
,
qseed
,
req_id
):
def
worker
(
host
,
qname
,
qstr
,
qseed
,
req_id
,
resolver
):
_url
=
"http://{}/start"
.
format
(
host
)
data
=
{
"client"
:
host
,
"qname"
:
qname
,
"question"
:
qstr
,
"qseed"
:
qseed
,
"req_id"
:
req_id
,
"resolver"
:
resolver
}
try
:
r
=
requests
.
post
(
_url
,
data
=
{
"client"
:
host
,
"qname"
:
qname
,
"question"
:
qstr
,
"qseed"
:
qseed
,
"req_id"
:
req_id
}
)
r
=
requests
.
post
(
_url
,
data
=
data
)
client_res
=
json
.
loads
(
r
.
text
)
except
Exception
as
e
:
sys
.
stderr
.
write
(
str
(
e
)
+
"
\n
"
)
...
...
@@ -234,11 +248,12 @@ def solve_questions(qname, qstr):
req_id
=
time
.
time
()
questions
[
qname
][
'last_req'
]
=
req_id
for
c
in
clients
:
for
c
in
clients
[
'solver'
]
:
# 問題はSolverに送る
if
c
[
1
]
==
'Solver'
:
client_addr
=
c
[
0
]
_th
=
threading
.
Thread
(
name
=
client_addr
,
target
=
worker
,
args
=
(
client_addr
,
qname
,
qstr
,
current_seed
,
req_id
))
idx_of_resolver
=
current_seed
%
len
(
clients
[
'resolver'
])
resolver
=
clients
[
'resolver'
][
idx_of_resolver
][
0
]
_th
=
threading
.
Thread
(
name
=
client_addr
,
target
=
worker
,
args
=
(
client_addr
,
qname
,
qstr
,
current_seed
,
req_id
,
resolver
))
_th
.
start
()
threads
.
append
(
_th
)
current_seed
+=
1
...
...
@@ -269,7 +284,7 @@ def get_clients():
res
=
OrderedDict
()
for
c
in
clients
:
for
c
in
clients
[
'all'
]
:
client_ip
=
c
[
0
]
res
[
client_ip
]
=
"http://{}"
.
format
(
client_ip
)
...
...
@@ -291,7 +306,7 @@ def client_table():
global
app_args
global
clients
return
render_template
(
"part_client_table.html"
,
clients
=
clients
,
local_mode
=
g
.
local_mode
)
return
render_template
(
"part_client_table.html"
,
clients
=
clients
[
"all"
]
,
local_mode
=
g
.
local_mode
)
@
app
.
route
(
"/get_question_status"
)
def
question_status
():
...
...
@@ -305,20 +320,17 @@ def question_status():
update_answer_list
(
qname
)
qdata
=
questions
[
qname
]
return
render_template
(
"part_question_status.html"
,
qname
=
qname
,
qdata
=
qdata
,
clients
=
clients
)
return
render_template
(
"part_question_status.html"
,
qname
=
qname
,
qdata
=
qdata
,
solvers
=
clients
[
"solver"
]
)
@
app
.
route
(
"/"
)
def
index
():
global
app_args
global
questions
global
clients
question_path
=
os
.
path
.
abspath
(
app_args
[
"question"
])
print
(
g
.
local_mode
)
return
render_template
(
"index.html"
,
questions
=
questions
,
question_path
=
question_path
,
clients
=
clients
)
return
render_template
(
"index.html"
,
questions
=
questions
,
question_path
=
question_path
)
def
main
(
args
):
raise
NotImprementedError
()
...
...
@@ -337,7 +349,21 @@ def init_system():
with
open
(
app_args
[
"client"
],
"r"
)
as
fp
:
_clients
=
fp
.
readlines
()
clients
=
[
v
.
rstrip
()
.
split
()
for
v
in
_clients
]
all_clients
=
[
v
.
rstrip
()
.
split
()
for
v
in
_clients
]
solver
=
[]
resolver
=
[]
for
v
in
all_clients
:
if
v
[
1
]
.
lower
()
==
"solver"
:
solver
.
append
(
v
)
elif
v
[
1
]
.
lower
()
==
"resolver"
:
resolver
.
append
(
v
)
clients
=
{
"all"
:
all_clients
,
"solver"
:
solver
,
"resolver"
:
resolver
}
if
__name__
==
"__main__"
:
...
...
comm/server/templates/index.html
View file @
48485307
...
...
@@ -20,7 +20,7 @@
<div
class=
"row"
>
<div
class=
"col-5"
id=
"question-control-pane"
>
<h3>
問題一覧
</h3>
<span><a
href=
"/#"
id=
"view-server-status-button"
>
クライアント
状況
</a></span>
<span><a
href=
"/#"
id=
"view-server-status-button"
>
システム
状況
</a></span>
<div
id=
"question-table-wrapper"
>
<p>
Loading...
</p>
</div>
...
...
comm/server/templates/part_question_status.html
View file @
48485307
...
...
@@ -12,8 +12,7 @@
<th>
Client (Solver)
</th>
<th>
Status
</th>
</tr>
{% for c in clients %}
{% if c[1] == "Solver" %}
{% for c in solvers %}
<tr>
<td>
{% if c|length > 3 %}
...
...
@@ -26,7 +25,6 @@
</td>
<td></td>
</tr>
{% endif %}
{% endfor %}
</table>
</div>
...
...
@@ -43,7 +41,7 @@
{% for v in qdata.answers %}
<tr>
<td>
{{v.timestamp}}
</td>
<td>
{{v.
client
}}
</td>
<td>
{{v.
solver
}}
</td>
<td>
{{v.nlcheck}}
</td>
</tr>
{% endfor %}
...
...
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