예제 #1
0
    def from_json(cls, catalog, j):
        db = cls()
        db._compartments = Compartment.from_json(j['compartments'])

        def to_ref(x):
            return CatalogRef(catalog, int(x['index']), x['entity'])

        for f in j['flows']:
            flow_ref = to_ref(f[0])
            db.add_flow(flow_ref)
            if len(f) > 1:
                for i in range(1, len(f)):
                    db.add_ref(f, to_ref(f[i]))
        for q in j['quantities']:
            q_ref = to_ref(q[0])
            db.add_quantity(q_ref)
            if len(q) > 1:
                for i in range(1, len(q)):
                    db.add_ref(q_ref, to_ref([i]))
        return db
예제 #2
0
 def __init__(self):
     self._compartments = Compartment.from_json(load_compartments())
     self._flows = LogicalSet(LogicalFlow)
     self._quantities = LogicalSet(LogicalQuantity)