diff --git a/pm4py/algo/filtering/log/between/between_filter.py b/pm4py/algo/filtering/log/between/between_filter.py index 6db8c2cbd..2872aab88 100644 --- a/pm4py/algo/filtering/log/between/between_filter.py +++ b/pm4py/algo/filtering/log/between/between_filter.py @@ -1,4 +1,5 @@ from enum import Enum +from copy import copy from typing import Optional, Dict, Any, Union from pm4py.objects.log.obj import EventLog, Trace @@ -8,6 +9,17 @@ class Parameters(Enum): ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY + CASE_ID_KEY = constants.PARAMETER_CONSTANT_CASEID_KEY + SUBCASE_CONCAT_STR = "subcase_concat_str" + + +def __fix_trace_attributes(trace_attributes, idx, rel_count, case_id_key, subcase_concat_str): + trace_attributes = copy(trace_attributes) + if case_id_key in trace_attributes: + trace_attributes[case_id_key] = trace_attributes[case_id_key] + subcase_concat_str + str(rel_count) + else: + trace_attributes[case_id_key] = str(idx) + subcase_concat_str + str(rel_count) + return trace_attributes def apply(log: EventLog, act1: str, act2: str, parameters: Optional[Dict[Union[str, Parameters], Any]] = None) -> EventLog: @@ -38,25 +50,31 @@ def apply(log: EventLog, act1: str, act2: str, parameters: Optional[Dict[Union[s log = log_converter.apply(log, variant=log_converter.Variants.TO_EVENT_LOG, parameters=parameters) activity_key = exec_utils.get_param_value(Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY) + case_id_key = exec_utils.get_param_value(Parameters.CASE_ID_KEY, parameters, xes_constants.DEFAULT_TRACEID_KEY) + subcase_concat_str = exec_utils.get_param_value(Parameters.SUBCASE_CONCAT_STR, parameters, "##@@") filtered_log = EventLog(attributes=log.attributes, extensions=log.extensions, omni_present=log.omni_present, classifiers=log.classifiers, properties=log.properties) - for trace in log: + for idx, trace in enumerate(log): act1_encountered = False filt_trace = None + rel_count = 0 i = 0 while i < len(trace): if not act1_encountered and trace[i][activity_key] == act1: act1_encountered = True - filt_trace = Trace(attributes=trace.attributes) + filt_trace = Trace(attributes=__fix_trace_attributes(trace.attributes, idx, rel_count, case_id_key, + subcase_concat_str)) filt_trace.append(trace[i]) elif act1_encountered and trace[i][activity_key] == act2: filt_trace.append(trace[i]) filtered_log.append(filt_trace) + rel_count += 1 act1_encountered = False filt_trace = None + elif filt_trace is not None: filt_trace.append(trace[i])