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
e88e9f9c
Commit
e88e9f9c
authored
Jul 19, 2019
by
Kento HASEGAWA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for saving received solutions
parent
bfd3e10c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
8 deletions
+32
-8
host.py
roles/host.py
+5
-5
data.py
utils/data.py
+27
-3
No files found.
roles/host.py
View file @
e88e9f9c
...
@@ -32,7 +32,7 @@ class Host(object):
...
@@ -32,7 +32,7 @@ class Host(object):
for
v
in
problems_path
:
for
v
in
problems_path
:
problem
=
Problem
(
v
)
problem
=
Problem
(
v
,
self
.
config
[
'solution_path'
]
)
_key
=
problem
.
name
_key
=
problem
.
name
self
.
problems
[
_key
]
=
problem
self
.
problems
[
_key
]
=
problem
...
@@ -148,11 +148,11 @@ class Worker(object):
...
@@ -148,11 +148,11 @@ class Worker(object):
self
.
address
=
params
[
'address'
]
self
.
address
=
params
[
'address'
]
self
.
name
=
params
[
'name'
]
self
.
name
=
params
[
'name'
]
self
.
host
=
params
[
'host'
]
self
.
host
=
params
[
'host'
]
self
.
role
=
None
self
.
role
=
params
[
'role'
]
self
.
params
=
params
self
.
params
=
params
self
.
status
=
'Setting up'
self
.
status
=
'Setting up'
self
.
set_role
(
params
[
'role'
]
)
self
.
configure
(
)
def
post
(
self
,
path
,
data
):
def
post
(
self
,
path
,
data
):
try
:
try
:
...
@@ -169,7 +169,7 @@ class Worker(object):
...
@@ -169,7 +169,7 @@ class Worker(object):
response
=
None
response
=
None
return
response
return
response
def
set_role
(
self
,
role
):
def
configure
(
self
):
r
=
self
.
post
(
'role'
,
self
.
params
)
r
=
self
.
post
(
'role'
,
self
.
params
)
class
Request
(
object
):
class
Request
(
object
):
...
@@ -232,7 +232,7 @@ class Request(object):
...
@@ -232,7 +232,7 @@ class Request(object):
worker_status
=
dict
()
worker_status
=
dict
()
for
v
in
all_workers
:
for
v
in
all_workers
:
if
v
in
self
.
response
:
if
v
in
self
.
response
:
worker_status
[
v
]
=
'Processed'
worker_status
[
v
]
=
self
.
response
[
v
][
'status'
]
else
:
else
:
worker_status
[
v
]
=
'Waiting for response'
worker_status
[
v
]
=
'Waiting for response'
...
...
utils/data.py
View file @
e88e9f9c
import
datetime
import
datetime
import
json
import
os
import
os
import
time
import
time
import
uuid
import
uuid
class
Problem
(
object
):
class
Problem
(
object
):
def
__init__
(
self
,
path
):
def
__init__
(
self
,
p
roblem_path
,
solution_p
ath
):
self
.
path
=
path
self
.
path
=
p
roblem_p
ath
self
.
name
=
''
self
.
name
=
''
self
.
size
=
(
0
,
0
)
self
.
size
=
(
0
,
0
)
self
.
block_num
=
0
self
.
block_num
=
0
self
.
problem
=
''
self
.
problem
=
''
self
.
status
=
'Ready'
self
.
status
=
'Ready'
self
.
solutions
=
dict
()
self
.
solutions
=
dict
()
self
.
solution_path
=
solution_path
self
.
_load_problem
(
path
)
self
.
_load_problem
(
p
roblem_p
ath
)
@
property
@
property
def
size_str
(
self
):
def
size_str
(
self
):
...
@@ -61,6 +63,9 @@ class Problem(object):
...
@@ -61,6 +63,9 @@ 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
# Save solution
solution
.
save
(
self
.
solution_path
)
def
get_solutions
(
self
):
def
get_solutions
(
self
):
return
self
.
solutions
return
self
.
solutions
...
@@ -80,6 +85,25 @@ class Solution(object):
...
@@ -80,6 +85,25 @@ class Solution(object):
def
get_id
(
self
):
def
get_id
(
self
):
return
self
.
_id
return
self
.
_id
def
get_dict
(
self
):
return
{
'id'
:
self
.
_id
,
'timestamp'
:
self
.
timestamp
,
'request_id'
:
self
.
request_id
,
'worker'
:
self
.
worker
,
'elapsed_time'
:
self
.
elapsed_time
,
'problem'
:
self
.
problem
,
'solution'
:
self
.
solution
}
def
save
(
self
,
basedir
):
outdir
=
f
"{basedir}/{self.problem}"
if
not
os
.
path
.
exists
(
outdir
):
os
.
mkdir
(
outdir
)
outpath
=
f
"{outdir}/{self.request_id}-{self.worker}.json"
.
replace
(
":"
,
"."
)
with
open
(
outpath
,
'w'
)
as
fp
:
json
.
dump
(
self
.
get_dict
(),
fp
,
indent
=
4
)
@
property
@
property
def
timestamp_str
(
self
):
def
timestamp_str
(
self
):
dt
=
datetime
.
datetime
.
fromtimestamp
(
dt
=
datetime
.
datetime
.
fromtimestamp
(
...
...
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