Create the Builder

The Builder's puerpose is to build data structures from the data obtained from the DB for both the Watcher and the Responder
This commit is contained in:
Sergi Delgado Segura
2019-10-25 20:30:55 +01:00
parent cf61e6e265
commit 43b749f417

39
pisa/builder.py Normal file
View File

@@ -0,0 +1,39 @@
from pisa.responder import Job
from pisa.appointment import Appointment
class Builder:
@staticmethod
def build_appointments(appointments_data):
appointments = {}
locator_uuid_map = {}
for uuid, appointment_data in appointments_data.items():
appointment = Appointment.from_dict(appointment_data)
appointments[uuid] = appointment
if appointment.locator in locator_uuid_map:
locator_uuid_map[appointment.locator].append(uuid)
else:
locator_uuid_map[appointment.locator] = [uuid]
return appointments, locator_uuid_map
@staticmethod
def build_jobs(jobs_data):
jobs = {}
tx_job_map = {}
for uuid, job_data in jobs_data.items():
job = Job.from_dict(jobs_data)
jobs[uuid] = job
if job.justice_txid in tx_job_map:
tx_job_map[job.justice_txid].append(uuid)
else:
tx_job_map[job.justice_txid] = [uuid]
return jobs, tx_job_map