def _write_categories(self, pw: pack.Writer): root = olca.Category() root.id = "f318fa60-bae9-361f-ad5a-5066a0e2a9d1" root.name = "Elementary flows" root.model_type = olca.ModelType.FLOW self._context_uids[root.name.lower()] = root.id pw.write(root) for _, row in self.flow_list.iterrows(): path = row['Context'] if not isinstance(path, str): continue path = path.strip() if path == '' or path.lower() in self._context_uids: continue parts = path.split("/") parent_id = root.id for i in range(0, len(parts)): lpath = "/".join(parts[0:i+1]).lower() uid = self._context_uids.get(lpath) if uid is not None: parent_id = uid continue uid = make_uuid("Flow", lpath) log.info("create category %s", lpath) c = olca.Category() c.id = uid c.name = parts[i] c.category = olca.ref(olca.Category, parent_id) c.model_type = olca.ModelType.FLOW pw.write(c) self._context_uids[lpath] = uid parent_id = uid
def __category(self, row) -> Optional[olca.Category]: cpath = row[7] # type: str if cpath is None or cpath.strip() == "": return None c = self.__categories.get(cpath) if c is not None: return c p = None parts = cpath.split("/") for i in range(0, len(parts)): if c is not None: p = c cpath = "/".join(parts[0:(i + 1)]) c = self.__categories.get(cpath) if c is not None: continue log.info("init category %s", cpath) c = olca.Category() c.id = make_uuid("category/flow/" + cpath) c.name = parts[i] c.model_type = olca.ModelType.FLOW if p is not None: c.category = olca.ref(olca.Category, p.id) self.__categories[cpath] = c return c
def _write_top_categories(self, pw: pack.Writer): # elementary flows root = olca.Category() root.id = "f318fa60-bae9-361f-ad5a-5066a0e2a9d1" root.name = "Elementary flows" root.model_type = olca.ModelType.FLOW pw.write(root) # resources res = olca.Category() res.id = "3095c63c-7962-4086-a0d7-df4fd38c2e68" res.name = "resource" res.category = olca.ref(olca.Category, root.id) res.model_type = olca.ModelType.FLOW pw.write(res) # emissions emi = olca.Category() emi.id = "c2433915-9ca3-3933-a64d-68d67e3e3281" emi.name = "emission" emi.category = olca.ref(olca.Category, root.id) emi.model_type = olca.ModelType.FLOW pw.write(emi)
def _write_flow_compartments(self, pw: pack.Writer): handled = set() for _, row in self.flow_list.iterrows(): uid = row["Compartment UUID"] if uid in handled: continue handled.add(uid) parent_uid = None direction = row["Directionality"].strip() if direction == "resource": parent_uid = "3095c63c-7962-4086-a0d7-df4fd38c2e68" elif direction == "emission": parent_uid = "c2433915-9ca3-3933-a64d-68d67e3e3281" else: log.error("Unknown directionality: %s", direction) continue comp = olca.Category() comp.id = uid comp.name = row["Compartment"] comp.model_type = olca.ModelType.FLOW comp.category = olca.ref(olca.Category, parent_uid) pw.write(comp)
def _category(path: str, mtype: olca.ModelType, writer: pack.Writer, created_ids: set) -> Optional[olca.Ref]: if not isinstance(path, str): return None if path.strip() == '': return None parts = path.split('/') parent = None # type: olca.Ref for i in range(0, len(parts)): uid_path = [str(mtype.value)] + parts[0:(i + 1)] uid = _uid(*uid_path) name = parts[i].strip() if uid not in created_ids: category = olca.Category() category.id = uid category.model_type = mtype category.name = name category.category = parent writer.write(category) created_ids.add(uid) parent = olca.ref(olca.Category, uid, name) parent.category_path = uid_path[1:] return parent