def data_from_index(index: tuple) -> dict: """Take the given 'Index' tuple and build a complete SUPERSTRUCTURE row from it. """ from_key, to_key = index[0], index[1] from_key, from_data = constuct_ad_data(ActivityDataset.get(database=from_key[0], code=from_key[1])) to_key, to_data = constuct_ad_data(ActivityDataset.get(database=to_key[0], code=to_key[1])) return { "from activity name": from_data[0], "from reference product": from_data[1], "from location": from_data[2], "from categories": from_data[3], "from database": from_data[4], "from key": from_key, "to activity name": to_data[0], "to reference product": to_data[1], "to location": to_data[1], "to categories": to_data[2], "to database": to_data[3], "to key": to_key, "flow type": getattr(index, "flow_type", None), }
def add_input_info_for_external_exchanges(activities, names): """Add details on exchange inputs from other databases""" names = set(names) cache = {} for ds in tqdm(activities): for exc in ds['exchanges']: if 'input' not in exc or exc['input'][0] in names: continue if exc['input'] not in cache: cache[exc['input']] = ActivityDataset.get( ActivityDataset.database == exc['input'][0], ActivityDataset.code == exc['input'][1], ) obj = cache[exc['input']] exc['activity'] = obj.name exc['product'] = obj.product exc['unit'] = obj.data['unit'] exc['location'] = obj.location if exc['type'] == 'biosphere': exc['categories'] = obj.data['categories']
def add_input_info_for_external_exchanges(activities, names): """Add details on exchange inputs from other databases""" names = set(names) cache = {} for ds in tqdm(activities): for exc in ds["exchanges"]: if "input" not in exc or exc["input"][0] in names: continue if exc["input"] not in cache: cache[exc["input"]] = ActivityDataset.get( ActivityDataset.database == exc["input"][0], ActivityDataset.code == exc["input"][1], ) obj = cache[exc["input"]] exc["name"] = obj.name exc["product"] = obj.product exc["unit"] = obj.data.get("unit") exc["location"] = obj.location exc["database"] = obj.database if exc["type"] == "biosphere": exc["categories"] = obj.data.get("categories")
def output_document_id(self) -> int: return ActivityDataset.get( ActivityDataset.code == self.output.code, ActivityDataset.database == self.output.database).id