def write(processes: dict, file_path: str): """ Write the given process dictionary to a olca-schema zip file with the given path. """ with pack.Writer(file_path) as writer: created_ids = set() for d in processes.values(): process = olca.Process() process.name = _val(d, 'name') category_path = _val(d, 'category', default='') location_code = _val(d, 'location', 'name', default='') process.id = _uid(olca.ModelType.PROCESS, category_path, location_code, process.name) process.category = _category(category_path, olca.ModelType.PROCESS, writer, created_ids) process.description = _val(d, 'description') process.process_type = olca.ProcessType.UNIT_PROCESS process.location = _location(_val(d, 'location'), writer, created_ids) process.process_documentation = _process_doc( _val(d, 'processDocumentation'), writer, created_ids) _process_dq(d, process) process.exchanges = [] last_id = 0 for e in _val(d, 'exchanges', default=[]): exchange = _exchange(e, writer, created_ids) if exchange is not None: last_id += 1 exchange.internal_id = last_id process.exchanges.append(exchange) writer.write(process)
def __init__(self, zip_file: str): log.info("create JSON-LD writer on %s", zip_file) self.__writer = pack.Writer(zip_file) self.__methods = {} self.__indicators = {} self.__flows = {} self.__categories = {}
def write_to(self, path: str): if os.path.exists(path): log.warning("File %s already exists and will be overwritten", path) os.remove(path) pw = pack.Writer(path) self._write_top_categories(pw) self._write_flow_compartments(pw) self._write_flows(pw) self._write_mappings(pw) pw.close()
def write_to(self, path: str): """ Writes json dictionaries to files :param path: string path to file :return: None """ if os.path.exists(path): log.warning("File %s already exists and will be overwritten", path) os.remove(path) pw = pack.Writer(path) self._write_categories(pw) self._write_flows(pw) if self.flow_mapping is not None: self._write_mappings(pw) pw.close()
def write(processes: dict, file_path: str): """Write the given process dictionary to a olca-schema zip file with the given path.""" with pack.Writer(file_path) as writer: list_of_dicts = list() created_ids = set() # for d_vals in processes.values(): for p_key in processes.keys(): d_vals = processes[p_key] process = olca.Process() process.name = _val(d_vals, 'name') process.version = _val(d_vals, 'version') category_path = _val(d_vals, 'category', default='') location_code = _val(d_vals, 'location', 'name', default='') process.id = _uid(olca.ModelType.PROCESS, category_path, location_code, process.name) process.category = _category(category_path, olca.ModelType.PROCESS, writer, created_ids) process.description = _val(d_vals, 'description') if _val(d_vals, 'processType') == "UNIT_PROCESS": process.process_type = olca.ProcessType.UNIT_PROCESS else: process.process_type = olca.ProcessType.LCI_RESULT process.location = _location(_val(d_vals, 'location'), writer, created_ids) process.process_documentation = _process_doc( _val(d_vals, 'processDocumentation'), writer, created_ids) process.last_change = datetime.datetime.now(pytz.utc).isoformat() _process_dq(d_vals, process) process.exchanges = [] last_id = 0 for e in _val(d_vals, 'exchanges', default=[]): exchange = _exchange(e, writer, created_ids) if exchange is not None: last_id += 1 exchange.internal_id = last_id process.exchanges.append(exchange) if exchange.quantitative_reference: processes[p_key]['q_reference_name'] = e['flow'][ 'name'] processes[p_key]['q_reference_id'] = exchange.to_json( )['flow']['@id'] processes[p_key]['q_reference_cat'] = e['flow'][ 'category'] processes[p_key]['q_reference_unit'] = e['unit'][ 'name'] writer.write(process) processes[p_key]['uuid'] = process.id return processes