def __call__(self, activities_to_keep) -> EventLog: f = EventLog() for e in self.log: if e.get_activity_name() in activities_to_keep: f.add_event(e) self.log = f return self.log
def __call__(self, ending_activity) -> EventLog: f = EventLog() for t in self.log.get_traces(): if t[-1].get_activity_name() is ending_activity: for e in t: f.add_event(e) self.log = f return self.log
def __call__(self, name: str, value) -> EventLog: f = EventLog() for e in self.log: if isinstance(value, list): if e[name] in value: f.add_event(e) else: if e[name] is value: f.add_event(e) self.log = f return self.log
def __call__(self, first_activity, second_activity) -> EventLog: f = EventLog() for t in self.log.get_traces(): contains_df = False for e1, e2 in zip(t[:-1], t[1:]): if e1.get_activity_name( ) is first_activity and e2.get_activity_name( ) is second_activity: contains_df = True break if contains_df: for e in t: f.add_event(e) self.log = f return self.log
def __parse_xes_file(context, tree): log = None trace_idx = None event = None trace_count = 0 #for trace_id for action, elem in tqdm(context): if action == __START: # starting to read parent = tree[ elem.getparent()] if elem.getparent() in tree else None if elem.tag.endswith(c.STR): if parent is not None: tree = __parse_attribute(elem, parent, elem.get(c.KEY), elem.get(c.VAL), tree) continue elif elem.tag.endswith(c.DTE): try: date = __parse_date_ciso(elem.get(c.VAL)) tree = __parse_attribute(elem, parent, elem.get(c.KEY), date, tree) except TypeError: logging.info("failed to parse date: " + str(elem.get(c.VAL))) except ValueError: logging.info("failed to parse date: " + str(elem.get(c.VAL))) continue elif elem.tag.endswith(c.BOL): if parent is not None: str_val = str(elem.get(c.VAL)).lower() if str_val == 'true': bool_val = True elif str_val == 'false': bool_val = False else: raise ValueError("failed to parse bool: " + str(elem.get(c.VAL))) tree = __parse_attribute(elem, parent, elem.get(c.KEY), bool_val, tree) continue elif elem.tag.endswith(c.INT): if parent is not None: int_val = int(elem.get(c.VAL)) tree = __parse_attribute(elem, parent, elem.get(c.KEY), int_val, tree) continue elif elem.tag.endswith(c.FLT): if parent is not None: float_val = float(elem.get(c.VAL)) tree = __parse_attribute(elem, parent, elem.get(c.KEY), float_val, tree) continue elif elem.tag.endswith(c.EVE): if event is not None: raise SyntaxError( 'file contains <event> in another <event> tag') if trace_idx is None: raise SyntaxError( 'file contains a <event> element outside of a <trace> element (trace_id is None)' ) event = Event() tree[elem] = event continue elif elem.tag.endswith(c.TRC): if trace_idx is not None: raise SyntaxError( 'file contains <trace> in another <trace> tag') trace_idx = trace_count trace_count += 1 log.add_trace(trace_idx) tree[elem] = log.traces[trace_idx] continue elif elem.tag.endswith(c.EXT): if log is None: raise SyntaxError('extension found outside of <log> tag') if elem.get(c.NME) is not None and elem.get( c.PRX) is not None and elem.get(c.URI) is not None: log.extensions[elem.attrib[c.NME]] = { c.PRX: elem.attrib[c.PRX], c.URI: elem.attrib[c.URI] } continue elif elem.tag.endswith(c.GLB): if log is None: raise SyntaxError('global found outside of <log> tag') if elem.get(c.SCP) is not None: log.globals[elem.attrib[c.SCP]] = {} tree[elem] = log.globals[elem.get(c.SCP)] continue elif elem.tag.endswith(c.CLS): if log is None: raise SyntaxError('classifier found outside of <log> tag') if elem.get(c.KYS) is not None: name, attributes = elem.attrib[c.NME], elem.attrib[c.KYS] # resolve special case; refactor with __parse_classifier if "'" in attributes: attributes = re.findall(r'\'(.*?)\'', attributes) else: attributes = attributes.split() log.classifiers[name] = attributes continue elif elem.tag.endswith(c.LOG): if log is not None: raise SyntaxError('file contains > 1 <log> tags') log = EventLog() tree[elem] = log.attributes continue elif action == __END: __clear_element(elem, tree) if elem.tag.endswith(c.EVE): if trace_idx is not None: log.add_event(event, trace_idx) event = None continue elif elem.tag.endswith(c.TRC): trace_idx = None continue elif elem.tag.endswith(c.LOG): continue return log