Loading roles/host.py +5 −5 Changes for roles/host.py: 5 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ class Host(object): for v in problems_path: problem = Problem(v) problem = Problem(v, self.config['solution_path']) _key = problem.name self.problems[_key] = problem Loading Loading @@ -148,11 +148,11 @@ class Worker(object): self.address = params['address'] self.name = params['name'] self.host = params['host'] self.role = None self.role = params['role'] self.params = params self.status = 'Setting up' self.set_role(params['role']) self.configure() def post(self, path, data): try: Loading @@ -169,7 +169,7 @@ class Worker(object): response = None return response def set_role(self, role): def configure(self): r = self.post('role', self.params) class Request(object): Loading Loading @@ -232,7 +232,7 @@ class Request(object): worker_status = dict() for v in all_workers: if v in self.response: worker_status[v] = 'Processed' worker_status[v] = self.response[v]['status'] else: worker_status[v] = 'Waiting for response' Loading utils/data.py +27 −3 Changes for utils/data.py: 27 added lines, 3 removed lines. Original line number Diff line number Diff line import datetime import json import os import time import uuid class Problem(object): def __init__(self, path): def __init__(self, problem_path, solution_path): self.path = path self.path = problem_path self.name = '' self.size = (0, 0) self.block_num = 0 self.problem = '' self.status = 'Ready' self.solutions = dict() self.solution_path = solution_path self._load_problem(path) self._load_problem(problem_path) @property def size_str(self): Loading Loading @@ -61,6 +63,9 @@ class Problem(object): print(f'I: Put a solution: {solution_id}') self.solutions[solution_id] = solution # Save solution solution.save(self.solution_path) def get_solutions(self): return self.solutions Loading @@ -80,6 +85,25 @@ class Solution(object): def get_id(self): 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 def timestamp_str(self): dt = datetime.datetime.fromtimestamp( Loading Loading
roles/host.py +5 −5 Changes for roles/host.py: 5 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ class Host(object): for v in problems_path: problem = Problem(v) problem = Problem(v, self.config['solution_path']) _key = problem.name self.problems[_key] = problem Loading Loading @@ -148,11 +148,11 @@ class Worker(object): self.address = params['address'] self.name = params['name'] self.host = params['host'] self.role = None self.role = params['role'] self.params = params self.status = 'Setting up' self.set_role(params['role']) self.configure() def post(self, path, data): try: Loading @@ -169,7 +169,7 @@ class Worker(object): response = None return response def set_role(self, role): def configure(self): r = self.post('role', self.params) class Request(object): Loading Loading @@ -232,7 +232,7 @@ class Request(object): worker_status = dict() for v in all_workers: if v in self.response: worker_status[v] = 'Processed' worker_status[v] = self.response[v]['status'] else: worker_status[v] = 'Waiting for response' Loading
utils/data.py +27 −3 Changes for utils/data.py: 27 added lines, 3 removed lines. Original line number Diff line number Diff line import datetime import json import os import time import uuid class Problem(object): def __init__(self, path): def __init__(self, problem_path, solution_path): self.path = path self.path = problem_path self.name = '' self.size = (0, 0) self.block_num = 0 self.problem = '' self.status = 'Ready' self.solutions = dict() self.solution_path = solution_path self._load_problem(path) self._load_problem(problem_path) @property def size_str(self): Loading Loading @@ -61,6 +63,9 @@ class Problem(object): print(f'I: Put a solution: {solution_id}') self.solutions[solution_id] = solution # Save solution solution.save(self.solution_path) def get_solutions(self): return self.solutions Loading @@ -80,6 +85,25 @@ class Solution(object): def get_id(self): 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 def timestamp_str(self): dt = datetime.datetime.fromtimestamp( Loading