Skip to content

Commit

Permalink
fix(pm4py): fixed incongruency between filter on EventLog
Browse files Browse the repository at this point in the history
  • Loading branch information
fit-alessandro-berti committed Mar 4, 2024
1 parent ab92a0e commit e8f0b84
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pm4py/algo/filtering/log/between/between_filter.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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])

Expand Down

0 comments on commit e8f0b84

Please sign in to comment.