def _create_process(self, filename): """ Extract dataset object from XML file :param filename: :return: """ o = self._get_objectified_entity(filename) p_meta = o.dataset.metaInformation.processInformation n = p_meta.referenceFunction.get('name') u = self._key_to_nsuuid(n) try_p = self[u] if try_p is not None: p = try_p assert p.entity_type == 'process', "Expected process, found %s" % p.entity_type else: # create new process g = p_meta.geography.get('location') stt = {'begin': str(find_tag(p_meta, 'startDate')), 'end': str(find_tag(p_meta, 'endDate'))} c = p_meta.referenceFunction.get('generalComment') cls = [p_meta.referenceFunction.get('category'), p_meta.referenceFunction.get('subCategory')] p = LcProcess(u, Name=n, Comment=c, SpatialScope=g, TemporalScope=stt, Classifications=cls) p.set_external_ref(n) rf, flowlist = self._extract_exchanges(o) for flow, f_dir, val, cmt in flowlist: self._print('Exch %s [%s] (%g)' % (flow, f_dir, val)) x = p.add_exchange(flow, f_dir, reference=None, value=val, add_dups=True) if cmt is not None: x.comment = cmt for ref in rf: p.add_reference(ref, 'Output') self.add(p) return p
def _create_process_entity(self, o, ns): u = str(find_common(o, 'UUID')) try_p = self[u] if try_p is not None: return try_p n = ', '.join( chain( filter(len, [ str(find_tag(o, k, ns=ns)) for k in ('baseName', 'treatmentStandardsRoutes', 'mixAndLocationTypes', 'functionalUnitFlowProperties') ]))) try: g = find_tag(o, 'locationOfOperationSupplyOrProduction', ns=ns).attrib['location'] except AttributeError: g = 'GLO' stt = { 'begin': str(find_common(o, 'referenceYear')), 'end': str(find_common(o, 'dataSetValidUntil')) } c = str(find_common(o, 'generalComment')) cls = [str(i) for i in find_tags(o, 'class', ns='common')] p = LcProcess(u, Name=n, Comment=c, SpatialScope=g, TemporalScope=stt, Classifications=cls) self.add(p) p.set_external_ref('%s/%s' % (typeDirs['Process'], u)) return p
def _create_process_entity(self, o, ns): u = str(find_common(o, 'UUID')[0]) n = ', '.join(chain(filter(len, [str(find_tag(o, k, ns=ns)[0]) for k in ('baseName', 'treatmentStandardsRoutes', 'mixAndLocationTypes', 'functionalUnitFlowProperties')]))) g = find_tag(o, 'locationOfOperationSupplyOrProduction', ns=ns)[0].attrib['location'] stt = {'begin': str(find_common(o, 'referenceYear')[0]), 'end': str(find_common(o, 'dataSetValidUntil')[0])} c = str(find_common(o, 'generalComment')[0]) cls = [str(i) for i in find_common(o, 'class')] p = LcProcess(u, Name=n, Comment=c, SpatialScope=g, TemporalScope=stt, Classifications=cls) self.add(p) p.set_external_ref('%s/%s' % (typeDirs['Process'], u)) return p
def _create_process(self, filename): """ Extract dataset object from XML file :param filename: :return: """ o = self._get_objectified_entity(filename) rf = None # reference flow flowlist = [] for exch in o.dataset.flowData.getchildren(): f = self._create_flow(exch) if hasattr(exch, 'outputGroup'): d = 'Output' if exch.outputGroup == 0: assert rf is None, "Multiple reference flows found!" rf = f elif hasattr(exch, 'inputGroup'): d = 'Input' else: raise DirectionlessExchangeError local_q = self._create_quantity(exch.get("unit")) v = float(exch.get('meanValue')) # returns none if missing if local_q is not f.reference_entity: v = v / f.cf(local_q) flowlist.append((f, d, v)) p_meta = o.dataset.metaInformation.processInformation n = p_meta.referenceFunction.get('name') u = self._key_to_id(n) try_p = self[u] if try_p is not None: p = try_p assert p.entity_type == 'process', "Expected process, found %s" % p.entity_type else: # create new process g = p_meta.geography.get('location') stt = {'begin': str(find_tag(p_meta, 'startDate')[0]), 'end': str(find_tag(p_meta, 'endDate')[0])} c = p_meta.referenceFunction.get('generalComment') cls = [p_meta.referenceFunction.get('category'), p_meta.referenceFunction.get('subCategory')] p = LcProcess(u, Name=n, Comment=c, SpatialScope=g, TemporalScope=stt, Classifications=cls) p.set_external_ref(n) if rf is None: rx = None else: rx = p.add_reference(rf, 'Output') for flow, f_dir, val in flowlist: self._print('Exch %s [%s] (%g)' % (flow, f_dir, val)) p.add_exchange(flow, f_dir, reference=None, value=val, add_dups=True) self.add(p) return p