Datasets:
Add pinned source: pm4py-process (part 3)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/batches/variants/pandas.py +162 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/batches/variants/polars.py +175 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/batches/variants/test.rst +41 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/causal/__init__.py +22 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/causal/algorithm.py +59 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/causal/variants/__init__.py +22 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/causal/variants/alpha.py +45 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/causal/variants/heuristic.py +46 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/__init__.py +22 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/algorithm.py +75 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/util.py +308 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/variants/__init__.py +26 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/variants/classic.py +347 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/variants/classic_split.py +167 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/variants/trace_based.py +359 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/declare/__init__.py +23 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/declare/algorithm.py +58 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/declare/templates.py +40 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/declare/variants/__init__.py +23 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/declare/variants/classic.py +980 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/__init__.py +28 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/__init__.py +27 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/pandas/__init__.py +25 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/pandas/df_statistics.py +455 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/pandas/freq_triples.py +94 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/polars/__init__.py +28 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/polars/df_statistics.py +416 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/polars/freq_triples.py +77 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/algorithm.py +153 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/replacement.py +41 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/utils/__init__.py +22 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/utils/dfg_utils.py +22 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/__init__.py +32 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/case_attributes.py +126 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/clean.py +114 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/clean_polars.py +87 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/clean_time.py +98 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/freq_triples.py +80 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/native.py +93 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/performance.py +190 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/__init__.py +22 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/algorithm.py +123 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/dfg/__init__.py +22 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/dfg/variants/__init__.py +22 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/dfg/variants/dfg.py +76 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/log/__init__.py +22 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/log/variants/__init__.py +31 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/log/variants/entire_dataframe.py +145 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/log/variants/entire_event_log.py +108 -0
- source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/log/variants/polars_lazyframes.py +166 -0
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/batches/variants/pandas.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from enum import Enum
|
| 23 |
+
from typing import Optional, Dict, Any, List, Tuple, Union
|
| 24 |
+
|
| 25 |
+
import pandas as pd
|
| 26 |
+
|
| 27 |
+
from pm4py.algo.discovery.batches.utils import detection
|
| 28 |
+
from pm4py.util import exec_utils, constants, xes_constants, pandas_utils
|
| 29 |
+
import numpy as np
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class Parameters(Enum):
|
| 33 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 34 |
+
RESOURCE_KEY = constants.PARAMETER_CONSTANT_RESOURCE_KEY
|
| 35 |
+
START_TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY
|
| 36 |
+
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
|
| 37 |
+
CASE_ID_KEY = constants.PARAMETER_CONSTANT_CASEID_KEY
|
| 38 |
+
EVENT_ID_KEY = "event_id_key"
|
| 39 |
+
MERGE_DISTANCE = "merge_distance"
|
| 40 |
+
MIN_BATCH_SIZE = "min_batch_size"
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def apply(
|
| 44 |
+
log: pd.DataFrame,
|
| 45 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 46 |
+
) -> List[Tuple[Tuple[str, str], int, Dict[str, Any]]]:
|
| 47 |
+
"""
|
| 48 |
+
Provided a Pandas dataframe, returns.
|
| 49 |
+
|
| 50 |
+
a list having as elements the activity-resources with the batches that are detected, divided in:
|
| 51 |
+
|
| 52 |
+
- Simultaneous (all the events in the batch have identical start and end timestamps)
|
| 53 |
+
- Batching at start (all the events in the batch have identical start timestamp)
|
| 54 |
+
- Batching at end (all the events in the batch have identical end timestamp)
|
| 55 |
+
- Sequential batching (for all the consecutive events, the end of the first is equal to the start of the second)
|
| 56 |
+
- Concurrent batching (for all the consecutive events that are not sequentially matched)
|
| 57 |
+
|
| 58 |
+
The approach has been described in the following paper:
|
| 59 |
+
Martin, N., Swennen, M., Depaire, B., Jans, M., Caris, A., & Vanhoof, K. (2015, December). Batch Processing:
|
| 60 |
+
Definition and Event Log Identification. In SIMPDA (pp. 137-140).
|
| 61 |
+
|
| 62 |
+
Parameters
|
| 63 |
+
----------
|
| 64 |
+
log
|
| 65 |
+
Dataframe
|
| 66 |
+
parameters
|
| 67 |
+
Parameters of the algorithm:
|
| 68 |
+
|
| 69 |
+
- ACTIVITY_KEY => the attribute that should be used as activity
|
| 70 |
+
- RESOURCE_KEY => the attribute that should be used as resource
|
| 71 |
+
- START_TIMESTAMP_KEY => the attribute that should be used as start timestamp
|
| 72 |
+
- TIMESTAMP_KEY => the attribute that should be used as timestamp
|
| 73 |
+
- CASE_ID_KEY => the attribute that should be used as case identifier
|
| 74 |
+
- MERGE_DISTANCE => the maximum time distance between non-overlapping intervals in order for them to be considered belonging to the same batch (default: 15*60 15 minutes)
|
| 75 |
+
- MIN_BATCH_SIZE => the minimum number of events for a batch to be considered (default: 2)
|
| 76 |
+
|
| 77 |
+
Returns
|
| 78 |
+
-----------------
|
| 79 |
+
list_batches
|
| 80 |
+
A (sorted) list containing tuples. Each tuple contain:
|
| 81 |
+
|
| 82 |
+
- Index 0: the activity-resource for which at least one batch has been detected
|
| 83 |
+
- Index 1: the number of batches for the given activity-resource
|
| 84 |
+
- Index 2: a list containing all the batches. Each batch is described by: # The start timestamp of the batch
|
| 85 |
+
|
| 86 |
+
* The start timestamp of the batch
|
| 87 |
+
* The complete timestamp of the batch
|
| 88 |
+
* The list of events that are executed in the batch
|
| 89 |
+
|
| 90 |
+
"""
|
| 91 |
+
if parameters is None:
|
| 92 |
+
parameters = {}
|
| 93 |
+
|
| 94 |
+
activity_key = exec_utils.get_param_value(
|
| 95 |
+
Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY
|
| 96 |
+
)
|
| 97 |
+
resource_key = exec_utils.get_param_value(
|
| 98 |
+
Parameters.RESOURCE_KEY, parameters, xes_constants.DEFAULT_RESOURCE_KEY
|
| 99 |
+
)
|
| 100 |
+
timestamp_key = exec_utils.get_param_value(
|
| 101 |
+
Parameters.TIMESTAMP_KEY,
|
| 102 |
+
parameters,
|
| 103 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 104 |
+
)
|
| 105 |
+
start_timestamp_key = exec_utils.get_param_value(
|
| 106 |
+
Parameters.START_TIMESTAMP_KEY, parameters, timestamp_key
|
| 107 |
+
)
|
| 108 |
+
case_id_key = exec_utils.get_param_value(
|
| 109 |
+
Parameters.CASE_ID_KEY, parameters, constants.CASE_CONCEPT_NAME
|
| 110 |
+
)
|
| 111 |
+
event_id_key = exec_utils.get_param_value(
|
| 112 |
+
Parameters.EVENT_ID_KEY, parameters, constants.DEFAULT_INDEX_KEY
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
attributes_to_consider = {
|
| 116 |
+
activity_key,
|
| 117 |
+
resource_key,
|
| 118 |
+
start_timestamp_key,
|
| 119 |
+
timestamp_key,
|
| 120 |
+
case_id_key,
|
| 121 |
+
}
|
| 122 |
+
log_contains_evidkey = event_id_key in log
|
| 123 |
+
if log_contains_evidkey:
|
| 124 |
+
attributes_to_consider.add(event_id_key)
|
| 125 |
+
|
| 126 |
+
log = log[list(attributes_to_consider)]
|
| 127 |
+
# the timestamp columns are expressed in nanoseconds values
|
| 128 |
+
# here, we want them to have the second granularity, so we divide by 10**9
|
| 129 |
+
# for example 1001000000 nanoseconds (value stored in the column)
|
| 130 |
+
# is equivalent to 1,001 seconds.
|
| 131 |
+
log[timestamp_key] = pandas_utils.convert_to_seconds(log[timestamp_key])
|
| 132 |
+
if start_timestamp_key != timestamp_key:
|
| 133 |
+
# see the aforementioned explanation.
|
| 134 |
+
log[start_timestamp_key] = pandas_utils.convert_to_seconds(
|
| 135 |
+
log[start_timestamp_key]
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
actres_grouping0 = (
|
| 139 |
+
log.groupby([activity_key, resource_key]).agg(list).to_dict()
|
| 140 |
+
)
|
| 141 |
+
start_timestamps = actres_grouping0[start_timestamp_key]
|
| 142 |
+
complete_timestamps = actres_grouping0[timestamp_key]
|
| 143 |
+
cases = actres_grouping0[case_id_key]
|
| 144 |
+
if log_contains_evidkey:
|
| 145 |
+
events_ids = actres_grouping0[event_id_key]
|
| 146 |
+
|
| 147 |
+
actres_grouping = {}
|
| 148 |
+
for k in start_timestamps:
|
| 149 |
+
st = start_timestamps[k]
|
| 150 |
+
et = complete_timestamps[k]
|
| 151 |
+
c = cases[k]
|
| 152 |
+
if log_contains_evidkey:
|
| 153 |
+
eid = events_ids[k]
|
| 154 |
+
actres_grouping_k = []
|
| 155 |
+
for i in range(len(st)):
|
| 156 |
+
if log_contains_evidkey:
|
| 157 |
+
actres_grouping_k.append((st[i], et[i], c[i], eid[i]))
|
| 158 |
+
else:
|
| 159 |
+
actres_grouping_k.append((st[i], et[i], c[i]))
|
| 160 |
+
actres_grouping[k] = actres_grouping_k
|
| 161 |
+
|
| 162 |
+
return detection.detect(actres_grouping, parameters=parameters)
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/batches/variants/polars.py
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from enum import Enum
|
| 23 |
+
from typing import Optional, Dict, Any, List, Tuple, Union
|
| 24 |
+
|
| 25 |
+
import polars as pl
|
| 26 |
+
|
| 27 |
+
from pm4py.algo.discovery.batches.utils import detection
|
| 28 |
+
from pm4py.util import exec_utils, constants, xes_constants, pandas_utils
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Parameters(Enum):
|
| 32 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 33 |
+
RESOURCE_KEY = constants.PARAMETER_CONSTANT_RESOURCE_KEY
|
| 34 |
+
START_TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY
|
| 35 |
+
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
|
| 36 |
+
CASE_ID_KEY = constants.PARAMETER_CONSTANT_CASEID_KEY
|
| 37 |
+
EVENT_ID_KEY = "event_id_key"
|
| 38 |
+
MERGE_DISTANCE = "merge_distance"
|
| 39 |
+
MIN_BATCH_SIZE = "min_batch_size"
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def _to_seconds_expr(column_name: str, schema: Dict[str, Any]) -> pl.Expr:
|
| 43 |
+
expr = pl.col(column_name)
|
| 44 |
+
dtype_repr = str(schema[column_name]).lower()
|
| 45 |
+
if "date" in dtype_repr or "time" in dtype_repr:
|
| 46 |
+
return (
|
| 47 |
+
expr.dt.cast_time_unit("ns")
|
| 48 |
+
.dt.timestamp("ns")
|
| 49 |
+
.cast(pl.Float64)
|
| 50 |
+
/ 1_000_000_000
|
| 51 |
+
)
|
| 52 |
+
if any(token in dtype_repr for token in ("int", "float")):
|
| 53 |
+
return expr.cast(pl.Float64)
|
| 54 |
+
raise Exception(
|
| 55 |
+
f"Column '{column_name}' must be temporal or numeric to evaluate seconds."
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def apply(
|
| 60 |
+
log: pl.LazyFrame,
|
| 61 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 62 |
+
) -> List[Tuple[Tuple[str, str], int, Dict[str, Any]]]:
|
| 63 |
+
if parameters is None:
|
| 64 |
+
parameters = {}
|
| 65 |
+
|
| 66 |
+
activity_key = exec_utils.get_param_value(
|
| 67 |
+
Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY
|
| 68 |
+
)
|
| 69 |
+
resource_key = exec_utils.get_param_value(
|
| 70 |
+
Parameters.RESOURCE_KEY, parameters, xes_constants.DEFAULT_RESOURCE_KEY
|
| 71 |
+
)
|
| 72 |
+
timestamp_key = exec_utils.get_param_value(
|
| 73 |
+
Parameters.TIMESTAMP_KEY,
|
| 74 |
+
parameters,
|
| 75 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 76 |
+
)
|
| 77 |
+
start_timestamp_key = exec_utils.get_param_value(
|
| 78 |
+
Parameters.START_TIMESTAMP_KEY, parameters, timestamp_key
|
| 79 |
+
)
|
| 80 |
+
case_id_key = exec_utils.get_param_value(
|
| 81 |
+
Parameters.CASE_ID_KEY, parameters, constants.CASE_CONCEPT_NAME
|
| 82 |
+
)
|
| 83 |
+
event_id_key = exec_utils.get_param_value(
|
| 84 |
+
Parameters.EVENT_ID_KEY, parameters, constants.DEFAULT_INDEX_KEY
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
pandas_utils.check_pandas_dataframe_columns(
|
| 88 |
+
log,
|
| 89 |
+
activity_key=activity_key,
|
| 90 |
+
case_id_key=case_id_key,
|
| 91 |
+
timestamp_key=timestamp_key,
|
| 92 |
+
start_timestamp_key=start_timestamp_key,
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
schema = log.collect_schema()
|
| 96 |
+
attributes = [
|
| 97 |
+
activity_key,
|
| 98 |
+
resource_key,
|
| 99 |
+
start_timestamp_key,
|
| 100 |
+
timestamp_key,
|
| 101 |
+
case_id_key,
|
| 102 |
+
]
|
| 103 |
+
log_contains_evidkey = event_id_key in schema
|
| 104 |
+
if log_contains_evidkey:
|
| 105 |
+
attributes.append(event_id_key)
|
| 106 |
+
|
| 107 |
+
# ensure attribute order without duplicates
|
| 108 |
+
seen = set()
|
| 109 |
+
ordered_attributes: List[str] = []
|
| 110 |
+
for attr in attributes:
|
| 111 |
+
if attr not in seen:
|
| 112 |
+
seen.add(attr)
|
| 113 |
+
ordered_attributes.append(attr)
|
| 114 |
+
|
| 115 |
+
lf = log.select([pl.col(col) for col in ordered_attributes])
|
| 116 |
+
|
| 117 |
+
lf = lf.with_columns(
|
| 118 |
+
[
|
| 119 |
+
_to_seconds_expr(start_timestamp_key, schema).alias("__pm4py_start_sec__"),
|
| 120 |
+
_to_seconds_expr(timestamp_key, schema).alias("__pm4py_complete_sec__"),
|
| 121 |
+
]
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
lf = lf.with_row_index("__pm4py_order__")
|
| 125 |
+
|
| 126 |
+
aggregation_exprs = [
|
| 127 |
+
pl.col("__pm4py_start_sec__")
|
| 128 |
+
.sort_by("__pm4py_order__")
|
| 129 |
+
.alias("__pm4py_start__"),
|
| 130 |
+
pl.col("__pm4py_complete_sec__")
|
| 131 |
+
.sort_by("__pm4py_order__")
|
| 132 |
+
.alias("__pm4py_complete__"),
|
| 133 |
+
pl.col(case_id_key)
|
| 134 |
+
.sort_by("__pm4py_order__")
|
| 135 |
+
.alias("__pm4py_cases__"),
|
| 136 |
+
]
|
| 137 |
+
|
| 138 |
+
if log_contains_evidkey:
|
| 139 |
+
aggregation_exprs.append(
|
| 140 |
+
pl.col(event_id_key)
|
| 141 |
+
.sort_by("__pm4py_order__")
|
| 142 |
+
.alias("__pm4py_events__")
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
grouped = (
|
| 146 |
+
lf.group_by(activity_key, resource_key, maintain_order=True)
|
| 147 |
+
.agg(aggregation_exprs)
|
| 148 |
+
.collect()
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
actres_grouping: Dict[Tuple[str, str], List[Tuple[Any, ...]]] = {}
|
| 152 |
+
|
| 153 |
+
for row in grouped.iter_rows(named=True):
|
| 154 |
+
key = (row[activity_key], row[resource_key])
|
| 155 |
+
starts = list(row["__pm4py_start__"])
|
| 156 |
+
completes = list(row["__pm4py_complete__"])
|
| 157 |
+
cases = list(row["__pm4py_cases__"])
|
| 158 |
+
events_list = (
|
| 159 |
+
list(row["__pm4py_events__"])
|
| 160 |
+
if log_contains_evidkey
|
| 161 |
+
else None
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
batches = []
|
| 165 |
+
for idx in range(len(starts)):
|
| 166 |
+
entry: Tuple[Any, ...]
|
| 167 |
+
if log_contains_evidkey and events_list is not None:
|
| 168 |
+
entry = (starts[idx], completes[idx], cases[idx], events_list[idx])
|
| 169 |
+
else:
|
| 170 |
+
entry = (starts[idx], completes[idx], cases[idx])
|
| 171 |
+
batches.append(entry)
|
| 172 |
+
|
| 173 |
+
actres_grouping[key] = batches
|
| 174 |
+
|
| 175 |
+
return detection.detect(actres_grouping, parameters=parameters)
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/batches/variants/test.rst
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Discovers an Heuristics Net using Heuristics Miner.
|
| 2 |
+
|
| 3 |
+
Parameters
|
| 4 |
+
----------
|
| 5 |
+
dfg
|
| 6 |
+
Directly-Follows Graph
|
| 7 |
+
activities
|
| 8 |
+
(If provided) list of activities of the log
|
| 9 |
+
activities_occurrences
|
| 10 |
+
(If provided) dictionary of activities occurrences
|
| 11 |
+
start_activities
|
| 12 |
+
(If provided) dictionary of start activities occurrences
|
| 13 |
+
end_activities
|
| 14 |
+
(If provided) dictionary of end activities occurrences
|
| 15 |
+
parameters
|
| 16 |
+
Possible parameters of the algorithm,
|
| 17 |
+
including:
|
| 18 |
+
|
| 19 |
+
- Parameters.ACTIVITY_KEY
|
| 20 |
+
- Parameters.TIMESTAMP_KEY
|
| 21 |
+
- Parameters.CASE_ID_KEY
|
| 22 |
+
- Parameters.DEPENDENCY_THRESH
|
| 23 |
+
- Parameters.AND_MEASURE_THRESH
|
| 24 |
+
- Parameters.MIN_ACT_COUNT
|
| 25 |
+
- Parameters.MIN_DFG_OCCURRENCES
|
| 26 |
+
- Parameters.DFG_PRE_CLEANING_NOISE_THRESH
|
| 27 |
+
- Parameters.LOOP_LENGTH_TWO_THRESH
|
| 28 |
+
|
| 29 |
+
variant
|
| 30 |
+
Variant of the algorithm:
|
| 31 |
+
|
| 32 |
+
- Variants.CLASSIC
|
| 33 |
+
|
| 34 |
+
Returns
|
| 35 |
+
------------
|
| 36 |
+
net
|
| 37 |
+
Petri net
|
| 38 |
+
im
|
| 39 |
+
Initial marking
|
| 40 |
+
fm
|
| 41 |
+
Final marking
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/causal/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.causal import algorithm, variants
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/causal/algorithm.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.causal.variants import alpha, heuristic
|
| 23 |
+
from enum import Enum
|
| 24 |
+
from pm4py.util import exec_utils
|
| 25 |
+
from typing import Dict, Tuple
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class Variants(Enum):
|
| 29 |
+
CAUSAL_ALPHA = alpha
|
| 30 |
+
CAUSAL_HEURISTIC = heuristic
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
CAUSAL_ALPHA = Variants.CAUSAL_ALPHA
|
| 34 |
+
CAUSAL_HEURISTIC = Variants.CAUSAL_HEURISTIC
|
| 35 |
+
|
| 36 |
+
VERSIONS = {CAUSAL_ALPHA, CAUSAL_HEURISTIC}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def apply(
|
| 40 |
+
dfg: Dict[Tuple[str, str], int], variant=CAUSAL_ALPHA
|
| 41 |
+
) -> Dict[Tuple[str, str], int]:
|
| 42 |
+
"""
|
| 43 |
+
Computes the causal relation on the basis of a given directly follows graph.
|
| 44 |
+
|
| 45 |
+
Parameters
|
| 46 |
+
-----------
|
| 47 |
+
dfg
|
| 48 |
+
Directly follows graph
|
| 49 |
+
variant
|
| 50 |
+
Variant of the algorithm to use:
|
| 51 |
+
- Variants.CAUSAL_ALPHA
|
| 52 |
+
- Variants.CAUSAL_HEURISTIC
|
| 53 |
+
|
| 54 |
+
Returns
|
| 55 |
+
-----------
|
| 56 |
+
causal relations
|
| 57 |
+
dict
|
| 58 |
+
"""
|
| 59 |
+
return exec_utils.get_variant(variant).apply(dfg)
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/causal/variants/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.causal.variants import alpha, heuristic
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/causal/variants/alpha.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
|
| 23 |
+
from typing import Dict, Tuple
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def apply(dfg: Dict[Tuple[str, str], int]) -> Dict[Tuple[str, str], int]:
|
| 27 |
+
"""
|
| 28 |
+
Computes a causal graph based on a directly follows graph according to the alpha miner
|
| 29 |
+
|
| 30 |
+
Parameters
|
| 31 |
+
----------
|
| 32 |
+
dfg: :class:`dict` directly follows relation, should be a dict of the form (activity,activity) -> num of occ.
|
| 33 |
+
|
| 34 |
+
Returns
|
| 35 |
+
-------
|
| 36 |
+
causal_relation: :class:`dict` containing all causal relations as keys (with value 1 indicating that it holds)
|
| 37 |
+
"""
|
| 38 |
+
causal_alpha = {}
|
| 39 |
+
for f, t in dfg:
|
| 40 |
+
if dfg[(f, t)] > 0:
|
| 41 |
+
if (t, f) not in dfg:
|
| 42 |
+
causal_alpha[(f, t)] = 1
|
| 43 |
+
elif dfg[(t, f)] == 0:
|
| 44 |
+
causal_alpha[(f, t)] = 1
|
| 45 |
+
return causal_alpha
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/causal/variants/heuristic.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from typing import Dict, Tuple
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def apply(dfg: Dict[Tuple[str, str], int]) -> Dict[Tuple[str, str], float]:
|
| 26 |
+
"""
|
| 27 |
+
Computes a causal graph based on a directly follows graph according to the heuristics miner
|
| 28 |
+
|
| 29 |
+
Parameters
|
| 30 |
+
----------
|
| 31 |
+
dfg: :class:`dict` directly follows relation, should be a dict of the form (activity,activity) -> num of occ.
|
| 32 |
+
|
| 33 |
+
Returns
|
| 34 |
+
-------
|
| 35 |
+
:return: dictionary containing all causal relations as keys (with value inbetween -1 and 1 indicating that
|
| 36 |
+
how strong it holds)
|
| 37 |
+
"""
|
| 38 |
+
causal_heur = {}
|
| 39 |
+
for f, t in dfg:
|
| 40 |
+
if (f, t) not in causal_heur:
|
| 41 |
+
rev = dfg[(t, f)] if (t, f) in dfg else 0
|
| 42 |
+
causal_heur[(f, t)] = float(
|
| 43 |
+
(dfg[(f, t)] - rev) / (dfg[(f, t)] + rev + 1)
|
| 44 |
+
)
|
| 45 |
+
causal_heur[(t, f)] = -1 * causal_heur[(f, t)]
|
| 46 |
+
return causal_heur
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.correlation_mining import variants, algorithm, util
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/algorithm.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.correlation_mining.variants import (
|
| 23 |
+
classic_split,
|
| 24 |
+
classic,
|
| 25 |
+
trace_based,
|
| 26 |
+
)
|
| 27 |
+
from pm4py.util import exec_utils
|
| 28 |
+
from enum import Enum
|
| 29 |
+
from typing import Optional, Dict, Any, Union, Tuple
|
| 30 |
+
from pm4py.objects.log.obj import EventLog, EventStream
|
| 31 |
+
import pandas as pd
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class Variants(Enum):
|
| 35 |
+
CLASSIC_SPLIT = classic_split
|
| 36 |
+
CLASSIC = classic
|
| 37 |
+
TRACE_BASED = trace_based
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
DEFAULT_VARIANT = Variants.CLASSIC
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def apply(
|
| 44 |
+
log: Union[EventLog, EventStream, pd.DataFrame],
|
| 45 |
+
variant=DEFAULT_VARIANT,
|
| 46 |
+
parameters: Optional[Dict[Any, Any]] = None,
|
| 47 |
+
) -> Tuple[Dict[Tuple[str, str], int], Dict[Tuple[str, str], float]]:
|
| 48 |
+
"""
|
| 49 |
+
Applies the Correlation Miner to the event stream (a log is converted to a stream)
|
| 50 |
+
|
| 51 |
+
The approach is described in:
|
| 52 |
+
Pourmirza, Shaya, Remco Dijkman, and Paul Grefen. "Correlation miner: mining business process models and event
|
| 53 |
+
correlations without case identifiers." International Journal of Cooperative Information Systems 26.02 (2017):
|
| 54 |
+
1742002.
|
| 55 |
+
|
| 56 |
+
Parameters
|
| 57 |
+
-------------
|
| 58 |
+
log
|
| 59 |
+
Log object
|
| 60 |
+
variant
|
| 61 |
+
Variant of the algorithm to use
|
| 62 |
+
parameters
|
| 63 |
+
Parameters of the algorithm
|
| 64 |
+
|
| 65 |
+
Returns
|
| 66 |
+
--------------
|
| 67 |
+
dfg
|
| 68 |
+
Directly-follows graph
|
| 69 |
+
performance_dfg
|
| 70 |
+
Performance DFG (containing the estimated performance for the arcs)
|
| 71 |
+
"""
|
| 72 |
+
if parameters is None:
|
| 73 |
+
parameters = {}
|
| 74 |
+
|
| 75 |
+
return exec_utils.get_variant(variant).apply(log, parameters=parameters)
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/util.py
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
import numpy as np
|
| 23 |
+
from pm4py.util.lp import solver
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def get_c_matrix(PS_matrix, duration_matrix, activities, activities_counter):
|
| 27 |
+
"""
|
| 28 |
+
Calculates the C-matrix out of the PS matrix and the duration matrix
|
| 29 |
+
|
| 30 |
+
Parameters
|
| 31 |
+
--------------
|
| 32 |
+
PS_matrix
|
| 33 |
+
PS matrix
|
| 34 |
+
duration_matrix
|
| 35 |
+
Duration matrix
|
| 36 |
+
activities
|
| 37 |
+
Ordered list of activities of the log
|
| 38 |
+
activities_counter
|
| 39 |
+
Counter of activities
|
| 40 |
+
|
| 41 |
+
Returns
|
| 42 |
+
--------------
|
| 43 |
+
c_matrix
|
| 44 |
+
C matrix
|
| 45 |
+
"""
|
| 46 |
+
C_matrix = np.zeros((len(activities), len(activities)))
|
| 47 |
+
for i in range(len(activities)):
|
| 48 |
+
for j in range(len(activities)):
|
| 49 |
+
val = (
|
| 50 |
+
duration_matrix[i, j]
|
| 51 |
+
/ PS_matrix[i, j]
|
| 52 |
+
* 1
|
| 53 |
+
/ (
|
| 54 |
+
min(
|
| 55 |
+
activities_counter[activities[i]],
|
| 56 |
+
activities_counter[activities[j]],
|
| 57 |
+
)
|
| 58 |
+
)
|
| 59 |
+
if PS_matrix[i, j] > 0
|
| 60 |
+
else 0
|
| 61 |
+
)
|
| 62 |
+
if val == 0:
|
| 63 |
+
val = 100000000000
|
| 64 |
+
C_matrix[i, j] = val
|
| 65 |
+
return C_matrix
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def resolve_LP(C_matrix, duration_matrix, activities, activities_counter):
|
| 69 |
+
"""
|
| 70 |
+
Formulates and solve the LP problem
|
| 71 |
+
|
| 72 |
+
Parameters
|
| 73 |
+
--------------
|
| 74 |
+
C_matrix
|
| 75 |
+
C_matrix
|
| 76 |
+
duration_matrix
|
| 77 |
+
Duration matrix
|
| 78 |
+
activities
|
| 79 |
+
Ordered list of activities of the log
|
| 80 |
+
activities_counter
|
| 81 |
+
Counter of activities
|
| 82 |
+
|
| 83 |
+
Returns
|
| 84 |
+
-------------
|
| 85 |
+
dfg
|
| 86 |
+
Directly-Follows Graph
|
| 87 |
+
performance_dfg
|
| 88 |
+
Performance DFG (containing the estimated performance for the arcs)
|
| 89 |
+
"""
|
| 90 |
+
edges = [
|
| 91 |
+
(i, j) for i in range(len(activities)) for j in range(len(activities))
|
| 92 |
+
]
|
| 93 |
+
c = [
|
| 94 |
+
C_matrix[i, j]
|
| 95 |
+
for i in range(len(activities))
|
| 96 |
+
for j in range(len(activities))
|
| 97 |
+
]
|
| 98 |
+
edges_sources = {
|
| 99 |
+
i: [z for z in range(len(edges)) if edges[z][0] == i]
|
| 100 |
+
for i in range(len(activities))
|
| 101 |
+
}
|
| 102 |
+
edges_targets = {
|
| 103 |
+
j: [z for z in range(len(edges)) if edges[z][1] == j]
|
| 104 |
+
for j in range(len(activities))
|
| 105 |
+
}
|
| 106 |
+
activities_occurrences = {
|
| 107 |
+
i: activities_counter[activities[i]] for i in range(len(activities))
|
| 108 |
+
}
|
| 109 |
+
Aeq = []
|
| 110 |
+
beq = []
|
| 111 |
+
for i in range(len(activities)):
|
| 112 |
+
rec = [0] * len(edges)
|
| 113 |
+
for e in edges_sources[i]:
|
| 114 |
+
rec[e] = 1
|
| 115 |
+
Aeq.append(rec)
|
| 116 |
+
beq.append(activities_occurrences[i])
|
| 117 |
+
for j in range(len(activities)):
|
| 118 |
+
rec = [0] * len(edges)
|
| 119 |
+
for e in edges_targets[j]:
|
| 120 |
+
rec[e] = 1
|
| 121 |
+
Aeq.append(rec)
|
| 122 |
+
beq.append(activities_occurrences[j])
|
| 123 |
+
Aeq = np.asmatrix(Aeq).astype(np.float64)
|
| 124 |
+
beq = np.asmatrix(beq).transpose().astype(np.float64)
|
| 125 |
+
Aub = []
|
| 126 |
+
bub = []
|
| 127 |
+
for i in range(len(activities)):
|
| 128 |
+
for e in edges_sources[i]:
|
| 129 |
+
rec = [0] * len(edges)
|
| 130 |
+
rec[e] = 1
|
| 131 |
+
Aub.append(rec)
|
| 132 |
+
bub.append(activities_occurrences[i])
|
| 133 |
+
rec = [-x for x in rec]
|
| 134 |
+
Aub.append(rec)
|
| 135 |
+
bub.append(0)
|
| 136 |
+
for j in range(len(activities)):
|
| 137 |
+
for e in edges_targets[j]:
|
| 138 |
+
rec = [0] * len(edges)
|
| 139 |
+
rec[e] = 1
|
| 140 |
+
Aub.append(rec)
|
| 141 |
+
bub.append(activities_occurrences[j])
|
| 142 |
+
rec = [-x for x in rec]
|
| 143 |
+
Aub.append(rec)
|
| 144 |
+
bub.append(0)
|
| 145 |
+
Aub = np.asmatrix(Aub).astype(np.float64)
|
| 146 |
+
bub = np.asmatrix(bub).transpose().astype(np.float64)
|
| 147 |
+
|
| 148 |
+
use_cvxopt = False
|
| 149 |
+
if (
|
| 150 |
+
solver.DEFAULT_LP_SOLVER_VARIANT == solver.CVXOPT_SOLVER_CUSTOM_ALIGN
|
| 151 |
+
or solver.DEFAULT_LP_SOLVER_VARIANT
|
| 152 |
+
== solver.CVXOPT_SOLVER_CUSTOM_ALIGN_ILP
|
| 153 |
+
):
|
| 154 |
+
use_cvxopt = True
|
| 155 |
+
|
| 156 |
+
if use_cvxopt:
|
| 157 |
+
from cvxopt import matrix
|
| 158 |
+
|
| 159 |
+
c = matrix(c)
|
| 160 |
+
Aub = matrix(Aub)
|
| 161 |
+
bub = matrix(bub)
|
| 162 |
+
Aeq = matrix(Aeq)
|
| 163 |
+
beq = matrix(beq)
|
| 164 |
+
|
| 165 |
+
res = solver.apply(
|
| 166 |
+
c, Aub, bub, Aeq, beq, variant=solver.DEFAULT_LP_SOLVER_VARIANT
|
| 167 |
+
)
|
| 168 |
+
points = solver.get_points_from_sol(
|
| 169 |
+
res, variant=solver.DEFAULT_LP_SOLVER_VARIANT
|
| 170 |
+
)
|
| 171 |
+
points = [round(p) for p in points]
|
| 172 |
+
|
| 173 |
+
dfg = {}
|
| 174 |
+
performance_dfg = {}
|
| 175 |
+
|
| 176 |
+
for idx, p in enumerate(points):
|
| 177 |
+
if p > 0:
|
| 178 |
+
dfg[(activities[edges[idx][0]], activities[edges[idx][1]])] = p
|
| 179 |
+
performance_dfg[
|
| 180 |
+
(activities[edges[idx][0]], activities[edges[idx][1]])
|
| 181 |
+
] = duration_matrix[edges[idx][0], edges[idx][1]]
|
| 182 |
+
return dfg, performance_dfg
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def match_return_avg_time(ai, aj, exact=False):
|
| 186 |
+
"""
|
| 187 |
+
Matches two list of times (exact or greedy)
|
| 188 |
+
and returns the average.
|
| 189 |
+
|
| 190 |
+
Parameters
|
| 191 |
+
--------------
|
| 192 |
+
ai
|
| 193 |
+
First list
|
| 194 |
+
aj
|
| 195 |
+
Second list
|
| 196 |
+
|
| 197 |
+
Returns
|
| 198 |
+
---------------
|
| 199 |
+
times_mean
|
| 200 |
+
Mean of times
|
| 201 |
+
"""
|
| 202 |
+
from statistics import mean
|
| 203 |
+
|
| 204 |
+
if exact:
|
| 205 |
+
from pm4py.statistics.util import times_bipartite_matching
|
| 206 |
+
|
| 207 |
+
matching = times_bipartite_matching.exact_match_minimum_average(ai, aj)
|
| 208 |
+
ret_exact = mean([x[1] - x[0] for x in matching]) if matching else 0
|
| 209 |
+
return ret_exact
|
| 210 |
+
else:
|
| 211 |
+
ret_greedy = greedy_match_return_avg_time(ai, aj)
|
| 212 |
+
return ret_greedy
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def greedy_match_return_avg_time(ai, aj):
|
| 216 |
+
"""
|
| 217 |
+
Matches two list of times with a greedy method
|
| 218 |
+
and returns the average.
|
| 219 |
+
|
| 220 |
+
Parameters
|
| 221 |
+
--------------
|
| 222 |
+
ai
|
| 223 |
+
First list
|
| 224 |
+
aj
|
| 225 |
+
Second list
|
| 226 |
+
parameters
|
| 227 |
+
Parameters of the algorithm
|
| 228 |
+
|
| 229 |
+
Returns
|
| 230 |
+
---------------
|
| 231 |
+
times_mean
|
| 232 |
+
Mean of times
|
| 233 |
+
"""
|
| 234 |
+
from statistics import mean
|
| 235 |
+
|
| 236 |
+
tm0 = calculate_time_match_fifo(ai, aj)
|
| 237 |
+
td0 = mean([x[1] - x[0] for x in tm0]) if tm0 else 0
|
| 238 |
+
tm1 = calculate_time_match_rlifo(ai, aj)
|
| 239 |
+
td1 = mean([x[1] - x[0] for x in tm1]) if tm1 else 0
|
| 240 |
+
return min(td0, td1)
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
def calculate_time_match_fifo(ai, aj, times0=None):
|
| 244 |
+
"""
|
| 245 |
+
Associate the times between
|
| 246 |
+
two lists of timestamps using FIFO
|
| 247 |
+
|
| 248 |
+
Parameters
|
| 249 |
+
--------------
|
| 250 |
+
ai
|
| 251 |
+
First list of timestamps
|
| 252 |
+
aj
|
| 253 |
+
Second list of timestamps
|
| 254 |
+
times0
|
| 255 |
+
Correspondence between execution times
|
| 256 |
+
|
| 257 |
+
Returns
|
| 258 |
+
--------------
|
| 259 |
+
times0
|
| 260 |
+
Correspondence between execution times
|
| 261 |
+
"""
|
| 262 |
+
if times0 is None:
|
| 263 |
+
times0 = []
|
| 264 |
+
k = 0
|
| 265 |
+
z = 0
|
| 266 |
+
while k < len(ai):
|
| 267 |
+
while z < len(aj):
|
| 268 |
+
if ai[k] < aj[z]:
|
| 269 |
+
times0.append((ai[k], aj[z]))
|
| 270 |
+
z = z + 1
|
| 271 |
+
break
|
| 272 |
+
z = z + 1
|
| 273 |
+
k = k + 1
|
| 274 |
+
return times0
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
def calculate_time_match_rlifo(ai, aj, times1=None):
|
| 278 |
+
"""
|
| 279 |
+
Associate the times between
|
| 280 |
+
two lists of timestamps using LIFO (start from end)
|
| 281 |
+
|
| 282 |
+
Parameters
|
| 283 |
+
--------------
|
| 284 |
+
ai
|
| 285 |
+
First list of timestamps
|
| 286 |
+
aj
|
| 287 |
+
Second list of timestamps
|
| 288 |
+
times0
|
| 289 |
+
Correspondence between execution times
|
| 290 |
+
|
| 291 |
+
Returns
|
| 292 |
+
--------------
|
| 293 |
+
times0
|
| 294 |
+
Correspondence between execution times
|
| 295 |
+
"""
|
| 296 |
+
if times1 is None:
|
| 297 |
+
times1 = []
|
| 298 |
+
k = len(ai) - 1
|
| 299 |
+
z = len(aj) - 1
|
| 300 |
+
while z >= 0:
|
| 301 |
+
while k >= 0:
|
| 302 |
+
if ai[k] < aj[z]:
|
| 303 |
+
times1.append((ai[k], aj[z]))
|
| 304 |
+
k = k - 1
|
| 305 |
+
break
|
| 306 |
+
k = k - 1
|
| 307 |
+
z = z - 1
|
| 308 |
+
return times1
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/variants/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.correlation_mining.variants import (
|
| 23 |
+
classic_split,
|
| 24 |
+
classic,
|
| 25 |
+
trace_based,
|
| 26 |
+
)
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/variants/classic.py
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.util import exec_utils
|
| 23 |
+
from enum import Enum
|
| 24 |
+
from pm4py.util import constants, xes_constants, pandas_utils
|
| 25 |
+
from pm4py.objects.conversion.log import converter
|
| 26 |
+
from pm4py.objects.log.obj import Event
|
| 27 |
+
from pm4py.algo.discovery.correlation_mining import util as cm_util
|
| 28 |
+
import numpy as np
|
| 29 |
+
from typing import Optional, Dict, Any, Union, Tuple
|
| 30 |
+
from pm4py.objects.log.obj import EventLog, EventStream
|
| 31 |
+
from pm4py.utils import is_polars_lazyframe
|
| 32 |
+
import pandas as pd
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class Parameters(Enum):
|
| 36 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 37 |
+
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
|
| 38 |
+
START_TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY
|
| 39 |
+
EXACT_TIME_MATCHING = "exact_time_matching"
|
| 40 |
+
INDEX_KEY = "index_key"
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
DEFAULT_INDEX_KEY = "@@@index"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def apply(
|
| 47 |
+
log: Union[EventLog, EventStream, pd.DataFrame],
|
| 48 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 49 |
+
) -> Tuple[Dict[Tuple[str, str], int], Dict[Tuple[str, str], float]]:
|
| 50 |
+
"""
|
| 51 |
+
Apply the correlation miner to an event stream
|
| 52 |
+
(other types of logs are converted to that)
|
| 53 |
+
|
| 54 |
+
The approach is described in:
|
| 55 |
+
Pourmirza, Shaya, Remco Dijkman, and Paul Grefen. "Correlation miner: mining business process models and event
|
| 56 |
+
correlations without case identifiers." International Journal of Cooperative Information Systems 26.02 (2017):
|
| 57 |
+
1742002.
|
| 58 |
+
|
| 59 |
+
Parameters
|
| 60 |
+
---------------
|
| 61 |
+
log
|
| 62 |
+
Log object
|
| 63 |
+
parameters
|
| 64 |
+
Parameters of the algorithm
|
| 65 |
+
|
| 66 |
+
Returns
|
| 67 |
+
---------------
|
| 68 |
+
dfg
|
| 69 |
+
DFG
|
| 70 |
+
performance_dfg
|
| 71 |
+
Performance DFG (containing the estimated performance for the arcs)
|
| 72 |
+
"""
|
| 73 |
+
if parameters is None:
|
| 74 |
+
parameters = {}
|
| 75 |
+
|
| 76 |
+
transf_stream, activities_grouped, activities = preprocess_log(
|
| 77 |
+
log, parameters=parameters
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
PS_matrix, duration_matrix = get_PS_dur_matrix(
|
| 81 |
+
activities_grouped, activities, parameters=parameters
|
| 82 |
+
)
|
| 83 |
+
activities_counter = {x: len(y) for x, y in activities_grouped.items()}
|
| 84 |
+
|
| 85 |
+
return resolve_lp_get_dfg(
|
| 86 |
+
PS_matrix, duration_matrix, activities, activities_counter
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def resolve_lp_get_dfg(
|
| 91 |
+
PS_matrix, duration_matrix, activities, activities_counter
|
| 92 |
+
):
|
| 93 |
+
"""
|
| 94 |
+
Resolves a LP problem to get a DFG
|
| 95 |
+
|
| 96 |
+
Parameters
|
| 97 |
+
--------------
|
| 98 |
+
PS_matrix
|
| 99 |
+
Precede-succeed matrix
|
| 100 |
+
duration_matrix
|
| 101 |
+
Duration matrix
|
| 102 |
+
activities
|
| 103 |
+
List of activities of the log
|
| 104 |
+
activities_counter
|
| 105 |
+
Counter of the activities
|
| 106 |
+
|
| 107 |
+
Returns
|
| 108 |
+
--------------
|
| 109 |
+
dfg
|
| 110 |
+
DFG
|
| 111 |
+
performance_dfg
|
| 112 |
+
Performance DFG (containing the estimated performance for the arcs)
|
| 113 |
+
"""
|
| 114 |
+
C_matrix = cm_util.get_c_matrix(
|
| 115 |
+
PS_matrix, duration_matrix, activities, activities_counter
|
| 116 |
+
)
|
| 117 |
+
dfg, performance_dfg = cm_util.resolve_LP(
|
| 118 |
+
C_matrix, duration_matrix, activities, activities_counter
|
| 119 |
+
)
|
| 120 |
+
return dfg, performance_dfg
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def get_PS_dur_matrix(activities_grouped, activities, parameters=None):
|
| 124 |
+
"""
|
| 125 |
+
Combined methods to get the two matrixes
|
| 126 |
+
|
| 127 |
+
Parameters
|
| 128 |
+
----------------
|
| 129 |
+
activities_grouped
|
| 130 |
+
Grouped activities
|
| 131 |
+
activities
|
| 132 |
+
List of activities of the log
|
| 133 |
+
parameters
|
| 134 |
+
Parameters of the algorithm
|
| 135 |
+
|
| 136 |
+
Returns
|
| 137 |
+
---------------
|
| 138 |
+
PS_matrix
|
| 139 |
+
Precede-succeed matrix
|
| 140 |
+
duration_matrix
|
| 141 |
+
Duration matrix
|
| 142 |
+
"""
|
| 143 |
+
if parameters is None:
|
| 144 |
+
parameters = {}
|
| 145 |
+
|
| 146 |
+
timestamp_key = exec_utils.get_param_value(
|
| 147 |
+
Parameters.TIMESTAMP_KEY,
|
| 148 |
+
parameters,
|
| 149 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 150 |
+
)
|
| 151 |
+
start_timestamp_key = exec_utils.get_param_value(
|
| 152 |
+
Parameters.START_TIMESTAMP_KEY,
|
| 153 |
+
parameters,
|
| 154 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 155 |
+
)
|
| 156 |
+
exact_time_matching = exec_utils.get_param_value(
|
| 157 |
+
Parameters.EXACT_TIME_MATCHING, parameters, False
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
PS_matrix = get_precede_succeed_matrix(
|
| 161 |
+
activities, activities_grouped, timestamp_key, start_timestamp_key
|
| 162 |
+
)
|
| 163 |
+
duration_matrix = get_duration_matrix(
|
| 164 |
+
activities,
|
| 165 |
+
activities_grouped,
|
| 166 |
+
timestamp_key,
|
| 167 |
+
start_timestamp_key,
|
| 168 |
+
exact=exact_time_matching,
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
return PS_matrix, duration_matrix
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def preprocess_log(log, activities=None, parameters=None):
|
| 175 |
+
"""
|
| 176 |
+
Preprocess a log to enable correlation mining
|
| 177 |
+
|
| 178 |
+
Parameters
|
| 179 |
+
--------------
|
| 180 |
+
log
|
| 181 |
+
Log object
|
| 182 |
+
activities
|
| 183 |
+
(if provided) list of activities of the log
|
| 184 |
+
parameters
|
| 185 |
+
Parameters of the algorithm
|
| 186 |
+
|
| 187 |
+
Returns
|
| 188 |
+
--------------
|
| 189 |
+
transf_stream
|
| 190 |
+
Transformed stream
|
| 191 |
+
activities_grouped
|
| 192 |
+
Grouped activities
|
| 193 |
+
activities
|
| 194 |
+
List of activities of the log
|
| 195 |
+
"""
|
| 196 |
+
if parameters is None:
|
| 197 |
+
parameters = {}
|
| 198 |
+
|
| 199 |
+
activity_key = exec_utils.get_param_value(
|
| 200 |
+
Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY
|
| 201 |
+
)
|
| 202 |
+
timestamp_key = exec_utils.get_param_value(
|
| 203 |
+
Parameters.TIMESTAMP_KEY,
|
| 204 |
+
parameters,
|
| 205 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 206 |
+
)
|
| 207 |
+
start_timestamp_key = exec_utils.get_param_value(
|
| 208 |
+
Parameters.START_TIMESTAMP_KEY,
|
| 209 |
+
parameters,
|
| 210 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 211 |
+
)
|
| 212 |
+
index_key = exec_utils.get_param_value(
|
| 213 |
+
Parameters.INDEX_KEY, parameters, DEFAULT_INDEX_KEY
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
if pandas_utils.check_is_pandas_dataframe(log):
|
| 217 |
+
if not is_polars_lazyframe(log):
|
| 218 |
+
# keep only the two columns before conversion
|
| 219 |
+
log = log[
|
| 220 |
+
list(set([activity_key, timestamp_key, start_timestamp_key]))
|
| 221 |
+
]
|
| 222 |
+
|
| 223 |
+
parameters["deepcopy"] = False
|
| 224 |
+
parameters["include_case_attributes"] = False
|
| 225 |
+
log = converter.apply(
|
| 226 |
+
log, variant=converter.TO_EVENT_STREAM, parameters=parameters
|
| 227 |
+
)
|
| 228 |
+
transf_stream = EventStream()
|
| 229 |
+
for idx, ev in enumerate(log):
|
| 230 |
+
transf_stream.append(
|
| 231 |
+
Event(
|
| 232 |
+
{
|
| 233 |
+
activity_key: ev[activity_key],
|
| 234 |
+
timestamp_key: ev[timestamp_key].timestamp(),
|
| 235 |
+
start_timestamp_key: ev[start_timestamp_key].timestamp(),
|
| 236 |
+
index_key: idx,
|
| 237 |
+
}
|
| 238 |
+
)
|
| 239 |
+
)
|
| 240 |
+
transf_stream = sorted(
|
| 241 |
+
transf_stream,
|
| 242 |
+
key=lambda x: (x[start_timestamp_key], x[timestamp_key], x[index_key]),
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
if activities is None:
|
| 246 |
+
activities = sorted(list(set(x[activity_key] for x in transf_stream)))
|
| 247 |
+
|
| 248 |
+
activities_grouped = {
|
| 249 |
+
x: [y for y in transf_stream if y[activity_key] == x]
|
| 250 |
+
for x in activities
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
return transf_stream, activities_grouped, activities
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def get_precede_succeed_matrix(
|
| 257 |
+
activities, activities_grouped, timestamp_key, start_timestamp_key
|
| 258 |
+
):
|
| 259 |
+
"""
|
| 260 |
+
Calculates the precede succeed matrix
|
| 261 |
+
|
| 262 |
+
Parameters
|
| 263 |
+
---------------
|
| 264 |
+
activities
|
| 265 |
+
Ordered list of activities of the log
|
| 266 |
+
activities_grouped
|
| 267 |
+
Grouped list of activities
|
| 268 |
+
timestamp_key
|
| 269 |
+
Timestamp key
|
| 270 |
+
start_timestamp_key
|
| 271 |
+
Start timestamp key (events start)
|
| 272 |
+
|
| 273 |
+
Returns
|
| 274 |
+
---------------
|
| 275 |
+
precede_succeed_matrix
|
| 276 |
+
Precede succeed matrix
|
| 277 |
+
"""
|
| 278 |
+
ret = np.zeros((len(activities), len(activities)))
|
| 279 |
+
for i in range(len(activities)):
|
| 280 |
+
ai = [x[timestamp_key] for x in activities_grouped[activities[i]]]
|
| 281 |
+
if ai:
|
| 282 |
+
for j in range(len(activities)):
|
| 283 |
+
if not i == j:
|
| 284 |
+
aj = [
|
| 285 |
+
x[start_timestamp_key]
|
| 286 |
+
for x in activities_grouped[activities[j]]
|
| 287 |
+
]
|
| 288 |
+
if aj:
|
| 289 |
+
k = 0
|
| 290 |
+
z = 0
|
| 291 |
+
count = 0
|
| 292 |
+
while k < len(ai):
|
| 293 |
+
while z < len(aj):
|
| 294 |
+
if ai[k] < aj[z]:
|
| 295 |
+
break
|
| 296 |
+
z = z + 1
|
| 297 |
+
count = count + (len(aj) - z)
|
| 298 |
+
k = k + 1
|
| 299 |
+
ret[i, j] = count / float(len(ai) * len(aj))
|
| 300 |
+
|
| 301 |
+
return ret
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
def get_duration_matrix(
|
| 305 |
+
activities,
|
| 306 |
+
activities_grouped,
|
| 307 |
+
timestamp_key,
|
| 308 |
+
start_timestamp_key,
|
| 309 |
+
exact=False,
|
| 310 |
+
):
|
| 311 |
+
"""
|
| 312 |
+
Calculates the duration matrix
|
| 313 |
+
|
| 314 |
+
Parameters
|
| 315 |
+
---------------
|
| 316 |
+
activities
|
| 317 |
+
Ordered list of activities of the log
|
| 318 |
+
activities_grouped
|
| 319 |
+
Grouped list of activities
|
| 320 |
+
timestamp_key
|
| 321 |
+
Timestamp key
|
| 322 |
+
start_timestamp_key
|
| 323 |
+
Start timestamp key (events start)
|
| 324 |
+
exact
|
| 325 |
+
Performs an exact matching of the times (True/False)
|
| 326 |
+
|
| 327 |
+
Returns
|
| 328 |
+
---------------
|
| 329 |
+
duration_matrix
|
| 330 |
+
Duration matrix
|
| 331 |
+
"""
|
| 332 |
+
# greedy algorithm
|
| 333 |
+
ret = np.zeros((len(activities), len(activities)))
|
| 334 |
+
for i in range(len(activities)):
|
| 335 |
+
ai = [x[timestamp_key] for x in activities_grouped[activities[i]]]
|
| 336 |
+
if ai:
|
| 337 |
+
for j in range(len(activities)):
|
| 338 |
+
if not i == j:
|
| 339 |
+
aj = [
|
| 340 |
+
x[start_timestamp_key]
|
| 341 |
+
for x in activities_grouped[activities[j]]
|
| 342 |
+
]
|
| 343 |
+
if aj:
|
| 344 |
+
ret[i, j] = cm_util.match_return_avg_time(
|
| 345 |
+
ai, aj, exact=exact
|
| 346 |
+
)
|
| 347 |
+
return ret
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/variants/classic_split.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.util import exec_utils
|
| 23 |
+
from enum import Enum
|
| 24 |
+
from pm4py.util import constants, xes_constants, pandas_utils
|
| 25 |
+
from pm4py.objects.conversion.log import converter
|
| 26 |
+
from pm4py.algo.discovery.correlation_mining.variants import classic
|
| 27 |
+
from collections import Counter
|
| 28 |
+
import numpy as np
|
| 29 |
+
from typing import Optional, Dict, Any, Union, Tuple
|
| 30 |
+
from pm4py.objects.log.obj import EventLog, EventStream
|
| 31 |
+
from pm4py.utils import is_polars_lazyframe
|
| 32 |
+
import pandas as pd
|
| 33 |
+
import importlib.util
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class Parameters(Enum):
|
| 37 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 38 |
+
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
|
| 39 |
+
START_TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY
|
| 40 |
+
SAMPLE_SIZE = "sample_size"
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def apply(
|
| 44 |
+
log: Union[EventLog, EventStream, pd.DataFrame],
|
| 45 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 46 |
+
) -> Tuple[Dict[Tuple[str, str], int], Dict[Tuple[str, str], float]]:
|
| 47 |
+
"""
|
| 48 |
+
Applies the correlation miner (splits the log in smaller chunks)
|
| 49 |
+
|
| 50 |
+
Parameters
|
| 51 |
+
---------------
|
| 52 |
+
log
|
| 53 |
+
Log object
|
| 54 |
+
parameters
|
| 55 |
+
Parameters of the algorithm
|
| 56 |
+
|
| 57 |
+
Returns
|
| 58 |
+
---------------
|
| 59 |
+
dfg
|
| 60 |
+
Frequency DFG
|
| 61 |
+
performance_dfg
|
| 62 |
+
Performance DFG
|
| 63 |
+
"""
|
| 64 |
+
if parameters is None:
|
| 65 |
+
parameters = {}
|
| 66 |
+
|
| 67 |
+
activity_key = exec_utils.get_param_value(
|
| 68 |
+
Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY
|
| 69 |
+
)
|
| 70 |
+
timestamp_key = exec_utils.get_param_value(
|
| 71 |
+
Parameters.TIMESTAMP_KEY,
|
| 72 |
+
parameters,
|
| 73 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 74 |
+
)
|
| 75 |
+
start_timestamp_key = exec_utils.get_param_value(
|
| 76 |
+
Parameters.START_TIMESTAMP_KEY,
|
| 77 |
+
parameters,
|
| 78 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 79 |
+
)
|
| 80 |
+
sample_size = exec_utils.get_param_value(
|
| 81 |
+
Parameters.SAMPLE_SIZE, parameters, 100000
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
PS_matrixes = []
|
| 85 |
+
duration_matrixes = []
|
| 86 |
+
|
| 87 |
+
if pandas_utils.check_is_pandas_dataframe(log):
|
| 88 |
+
if is_polars_lazyframe(log):
|
| 89 |
+
if importlib.util.find_spec("polars") is None:
|
| 90 |
+
raise RuntimeError(
|
| 91 |
+
"Polars LazyFrame provided but 'polars' package is not installed."
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
import polars as pl # type: ignore[import-untyped]
|
| 95 |
+
|
| 96 |
+
required_columns = list(
|
| 97 |
+
{activity_key, timestamp_key, start_timestamp_key}
|
| 98 |
+
)
|
| 99 |
+
missing_columns = [
|
| 100 |
+
col for col in required_columns if col not in log.columns
|
| 101 |
+
]
|
| 102 |
+
if missing_columns:
|
| 103 |
+
raise Exception(
|
| 104 |
+
"The provided Polars LazyFrame does not contain the following required columns: "
|
| 105 |
+
+ ", ".join(sorted(missing_columns))
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
activities_counter = (
|
| 109 |
+
log.group_by(activity_key)
|
| 110 |
+
.agg(pl.len().alias("__pm4py_count__"))
|
| 111 |
+
.collect()
|
| 112 |
+
)
|
| 113 |
+
activities_counter = {
|
| 114 |
+
row[activity_key]: row["__pm4py_count__"]
|
| 115 |
+
for row in activities_counter.iter_rows(named=True)
|
| 116 |
+
}
|
| 117 |
+
activities = sorted(list(activities_counter.keys()))
|
| 118 |
+
|
| 119 |
+
log = (
|
| 120 |
+
log.select(required_columns)
|
| 121 |
+
.sort([timestamp_key, start_timestamp_key], maintain_order=True)
|
| 122 |
+
.collect()
|
| 123 |
+
.to_pandas()
|
| 124 |
+
)
|
| 125 |
+
else:
|
| 126 |
+
# code for Pandas dataframes
|
| 127 |
+
log = log[
|
| 128 |
+
list(set([activity_key, timestamp_key, start_timestamp_key]))
|
| 129 |
+
]
|
| 130 |
+
log = log.sort_values([timestamp_key, start_timestamp_key])
|
| 131 |
+
activities_counter = log[activity_key].value_counts().to_dict()
|
| 132 |
+
activities = sorted(list(activities_counter.keys()))
|
| 133 |
+
else:
|
| 134 |
+
log = converter.apply(
|
| 135 |
+
log,
|
| 136 |
+
variant=converter.Variants.TO_EVENT_STREAM,
|
| 137 |
+
parameters={"deepcopy": False, "include_case_attributes": False},
|
| 138 |
+
)
|
| 139 |
+
activities_counter = Counter(x[activity_key] for x in log)
|
| 140 |
+
activities = sorted(list(activities_counter.keys()))
|
| 141 |
+
|
| 142 |
+
prev = 0
|
| 143 |
+
while prev < len(log):
|
| 144 |
+
sample = log[prev: min(len(log), prev + sample_size)]
|
| 145 |
+
transf_stream, activities_grouped, activities = classic.preprocess_log(
|
| 146 |
+
sample, activities=activities, parameters=parameters
|
| 147 |
+
)
|
| 148 |
+
PS_matrix, duration_matrix = classic.get_PS_dur_matrix(
|
| 149 |
+
activities_grouped, activities, parameters=parameters
|
| 150 |
+
)
|
| 151 |
+
PS_matrixes.append(PS_matrix)
|
| 152 |
+
duration_matrixes.append(duration_matrix)
|
| 153 |
+
|
| 154 |
+
prev = prev + sample_size
|
| 155 |
+
|
| 156 |
+
PS_matrix = np.zeros((len(activities), len(activities)))
|
| 157 |
+
duration_matrix = np.zeros((len(activities), len(activities)))
|
| 158 |
+
z = 0
|
| 159 |
+
while z < len(PS_matrixes):
|
| 160 |
+
PS_matrix = PS_matrix + PS_matrixes[z]
|
| 161 |
+
duration_matrix = np.maximum(duration_matrix, duration_matrixes[z])
|
| 162 |
+
z = z + 1
|
| 163 |
+
PS_matrix = PS_matrix / float(len(PS_matrixes))
|
| 164 |
+
|
| 165 |
+
return classic.resolve_lp_get_dfg(
|
| 166 |
+
PS_matrix, duration_matrix, activities, activities_counter
|
| 167 |
+
)
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/correlation_mining/variants/trace_based.py
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.util import exec_utils
|
| 23 |
+
from enum import Enum
|
| 24 |
+
from pm4py.util import constants, xes_constants, pandas_utils
|
| 25 |
+
from pm4py.objects.conversion.log import converter
|
| 26 |
+
from pm4py.algo.discovery.correlation_mining import util as cm_util
|
| 27 |
+
import numpy as np
|
| 28 |
+
from collections import Counter
|
| 29 |
+
from typing import Optional, Dict, Any, Union, Tuple
|
| 30 |
+
from pm4py.objects.log.obj import EventLog, EventStream
|
| 31 |
+
import pandas as pd
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class Parameters(Enum):
|
| 35 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 36 |
+
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
|
| 37 |
+
START_TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY
|
| 38 |
+
CASE_ID_KEY = constants.PARAMETER_CONSTANT_CASEID_KEY
|
| 39 |
+
INDEX_KEY = "index_key"
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
DEFAULT_INDEX_KEY = "@@@index"
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def apply(
|
| 46 |
+
log: Union[EventLog, EventStream, pd.DataFrame],
|
| 47 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 48 |
+
) -> Tuple[Dict[Tuple[str, str], int], Dict[Tuple[str, str], float]]:
|
| 49 |
+
"""
|
| 50 |
+
Novel approach of correlation mining, that creates the PS-matrix and the duration matrix
|
| 51 |
+
using the order list of events of each trace of the log
|
| 52 |
+
|
| 53 |
+
Parameters
|
| 54 |
+
-------------
|
| 55 |
+
log
|
| 56 |
+
Event log
|
| 57 |
+
parameters
|
| 58 |
+
Parameters
|
| 59 |
+
|
| 60 |
+
Returns
|
| 61 |
+
---------------
|
| 62 |
+
dfg
|
| 63 |
+
DFG
|
| 64 |
+
performance_dfg
|
| 65 |
+
Performance DFG (containing the estimated performance for the arcs)
|
| 66 |
+
"""
|
| 67 |
+
traces_list, trace_grouped_list, activities, activities_counter = (
|
| 68 |
+
preprocess_log(log, activities=None, activities_counter=None)
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
PS_matrix, duration_matrix = get_PS_duration_matrix(
|
| 72 |
+
activities, trace_grouped_list, parameters=parameters
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
return resolve_lp_get_dfg(
|
| 76 |
+
PS_matrix, duration_matrix, activities, activities_counter
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def resolve_lp_get_dfg(
|
| 81 |
+
PS_matrix, duration_matrix, activities, activities_counter
|
| 82 |
+
):
|
| 83 |
+
"""
|
| 84 |
+
Resolves a LP problem to get a DFG
|
| 85 |
+
|
| 86 |
+
Parameters
|
| 87 |
+
---------------
|
| 88 |
+
PS_matrix
|
| 89 |
+
Precede-succeed matrix
|
| 90 |
+
duration_matrix
|
| 91 |
+
Duration matrix
|
| 92 |
+
activities
|
| 93 |
+
List of activities of the log
|
| 94 |
+
activities_counter
|
| 95 |
+
Counter for the activities of the log
|
| 96 |
+
|
| 97 |
+
Returns
|
| 98 |
+
---------------
|
| 99 |
+
dfg
|
| 100 |
+
Frequency DFG
|
| 101 |
+
performance_dfg
|
| 102 |
+
Performance DFG
|
| 103 |
+
"""
|
| 104 |
+
C_matrix = cm_util.get_c_matrix(
|
| 105 |
+
PS_matrix, duration_matrix, activities, activities_counter
|
| 106 |
+
)
|
| 107 |
+
dfg, performance_dfg = cm_util.resolve_LP(
|
| 108 |
+
C_matrix, duration_matrix, activities, activities_counter
|
| 109 |
+
)
|
| 110 |
+
return dfg, performance_dfg
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def get_PS_duration_matrix(activities, trace_grouped_list, parameters=None):
|
| 114 |
+
"""
|
| 115 |
+
Gets the precede-succeed matrix
|
| 116 |
+
|
| 117 |
+
Parameters
|
| 118 |
+
--------------
|
| 119 |
+
activities
|
| 120 |
+
Activities
|
| 121 |
+
trace_grouped_list
|
| 122 |
+
Grouped list of simplified traces (per activity)
|
| 123 |
+
parameters
|
| 124 |
+
Parameters of the algorithm
|
| 125 |
+
|
| 126 |
+
Returns
|
| 127 |
+
--------------
|
| 128 |
+
PS_matrix
|
| 129 |
+
precede-succeed matrix
|
| 130 |
+
duration_matrix
|
| 131 |
+
Duration matrix
|
| 132 |
+
"""
|
| 133 |
+
if parameters is None:
|
| 134 |
+
parameters = {}
|
| 135 |
+
|
| 136 |
+
timestamp_key = exec_utils.get_param_value(
|
| 137 |
+
Parameters.TIMESTAMP_KEY,
|
| 138 |
+
parameters,
|
| 139 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 140 |
+
)
|
| 141 |
+
start_timestamp_key = exec_utils.get_param_value(
|
| 142 |
+
Parameters.START_TIMESTAMP_KEY,
|
| 143 |
+
parameters,
|
| 144 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
PS_matrix = get_precede_succeed_matrix(
|
| 148 |
+
activities, trace_grouped_list, timestamp_key, start_timestamp_key
|
| 149 |
+
)
|
| 150 |
+
duration_matrix = get_duration_matrix(
|
| 151 |
+
activities, trace_grouped_list, timestamp_key, start_timestamp_key
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
return PS_matrix, duration_matrix
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def preprocess_log(
|
| 158 |
+
log, activities=None, activities_counter=None, parameters=None
|
| 159 |
+
):
|
| 160 |
+
"""
|
| 161 |
+
Preprocess the log to get a grouped list of simplified traces (per activity)
|
| 162 |
+
|
| 163 |
+
Parameters
|
| 164 |
+
--------------
|
| 165 |
+
log
|
| 166 |
+
Log object
|
| 167 |
+
activities
|
| 168 |
+
(if provided) activities of the log
|
| 169 |
+
activities_counter
|
| 170 |
+
(if provided) counter of the activities of the log
|
| 171 |
+
parameters
|
| 172 |
+
Parameters of the algorithm
|
| 173 |
+
|
| 174 |
+
Returns
|
| 175 |
+
--------------
|
| 176 |
+
traces_list
|
| 177 |
+
List of simplified traces of the log
|
| 178 |
+
trace_grouped_list
|
| 179 |
+
Grouped list of simplified traces (per activity)
|
| 180 |
+
activities
|
| 181 |
+
Activities of the log
|
| 182 |
+
activities_counter
|
| 183 |
+
Activities counter
|
| 184 |
+
"""
|
| 185 |
+
if parameters is None:
|
| 186 |
+
parameters = {}
|
| 187 |
+
|
| 188 |
+
activity_key = exec_utils.get_param_value(
|
| 189 |
+
Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY
|
| 190 |
+
)
|
| 191 |
+
timestamp_key = exec_utils.get_param_value(
|
| 192 |
+
Parameters.TIMESTAMP_KEY,
|
| 193 |
+
parameters,
|
| 194 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 195 |
+
)
|
| 196 |
+
start_timestamp_key = exec_utils.get_param_value(
|
| 197 |
+
Parameters.START_TIMESTAMP_KEY,
|
| 198 |
+
parameters,
|
| 199 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 200 |
+
)
|
| 201 |
+
caseid_key = exec_utils.get_param_value(
|
| 202 |
+
Parameters.CASE_ID_KEY, parameters, constants.CASE_CONCEPT_NAME
|
| 203 |
+
)
|
| 204 |
+
index_key = exec_utils.get_param_value(
|
| 205 |
+
Parameters.INDEX_KEY, parameters, DEFAULT_INDEX_KEY
|
| 206 |
+
)
|
| 207 |
+
|
| 208 |
+
if pandas_utils.check_is_pandas_dataframe(log):
|
| 209 |
+
# keep only the two columns before conversion
|
| 210 |
+
log = log[
|
| 211 |
+
list(
|
| 212 |
+
set(
|
| 213 |
+
[
|
| 214 |
+
activity_key,
|
| 215 |
+
timestamp_key,
|
| 216 |
+
start_timestamp_key,
|
| 217 |
+
caseid_key,
|
| 218 |
+
]
|
| 219 |
+
)
|
| 220 |
+
)
|
| 221 |
+
]
|
| 222 |
+
|
| 223 |
+
log = converter.apply(
|
| 224 |
+
log, variant=converter.Variants.TO_EVENT_LOG, parameters=parameters
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
traces_list = []
|
| 228 |
+
for trace in log:
|
| 229 |
+
trace_stream = [
|
| 230 |
+
{
|
| 231 |
+
activity_key: trace[i][activity_key],
|
| 232 |
+
timestamp_key: trace[i][timestamp_key].timestamp(),
|
| 233 |
+
start_timestamp_key: trace[i][start_timestamp_key].timestamp(),
|
| 234 |
+
index_key: i,
|
| 235 |
+
}
|
| 236 |
+
for i in range(len(trace))
|
| 237 |
+
]
|
| 238 |
+
trace_stream = sorted(
|
| 239 |
+
trace_stream,
|
| 240 |
+
key=lambda x: (
|
| 241 |
+
x[start_timestamp_key],
|
| 242 |
+
x[timestamp_key],
|
| 243 |
+
x[index_key],
|
| 244 |
+
),
|
| 245 |
+
)
|
| 246 |
+
traces_list.append(trace_stream)
|
| 247 |
+
|
| 248 |
+
if activities is None:
|
| 249 |
+
activities = sorted(
|
| 250 |
+
list(set(y[activity_key] for x in traces_list for y in x))
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
trace_grouped_list = []
|
| 254 |
+
for trace in traces_list:
|
| 255 |
+
gr = []
|
| 256 |
+
for act in activities:
|
| 257 |
+
act_gr = [x for x in trace if x[activity_key] == act]
|
| 258 |
+
gr.append(act_gr)
|
| 259 |
+
trace_grouped_list.append(gr)
|
| 260 |
+
|
| 261 |
+
if activities_counter is None:
|
| 262 |
+
activities_counter = Counter(
|
| 263 |
+
y[activity_key] for x in traces_list for y in x
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
return traces_list, trace_grouped_list, activities, activities_counter
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def get_precede_succeed_matrix(
|
| 270 |
+
activities, trace_grouped_list, timestamp_key, start_timestamp_key
|
| 271 |
+
):
|
| 272 |
+
"""
|
| 273 |
+
Calculates the precede succeed matrix
|
| 274 |
+
|
| 275 |
+
Parameters
|
| 276 |
+
---------------
|
| 277 |
+
activities
|
| 278 |
+
Sorted list of activities of the log
|
| 279 |
+
trace_grouped_list
|
| 280 |
+
A list of lists of lists, containing for each trace and each activity the events having such activity
|
| 281 |
+
timestamp_key
|
| 282 |
+
The key to be used as timestamp
|
| 283 |
+
start_timestamp_key
|
| 284 |
+
The key to be used as start timestamp
|
| 285 |
+
|
| 286 |
+
Returns
|
| 287 |
+
---------------
|
| 288 |
+
mat
|
| 289 |
+
The precede succeed matrix
|
| 290 |
+
"""
|
| 291 |
+
ret = np.zeros((len(activities), len(activities)))
|
| 292 |
+
for i in range(len(activities)):
|
| 293 |
+
for j in range(len(activities)):
|
| 294 |
+
if not i == j:
|
| 295 |
+
count = 0
|
| 296 |
+
total = 0
|
| 297 |
+
for tr in trace_grouped_list:
|
| 298 |
+
ai = [x[timestamp_key] for x in tr[i]]
|
| 299 |
+
aj = [x[start_timestamp_key] for x in tr[j]]
|
| 300 |
+
if ai and aj:
|
| 301 |
+
total += len(ai) * len(aj)
|
| 302 |
+
k = 0
|
| 303 |
+
z = 0
|
| 304 |
+
while k < len(ai):
|
| 305 |
+
while z < len(aj):
|
| 306 |
+
if ai[k] < aj[z]:
|
| 307 |
+
break
|
| 308 |
+
z = z + 1
|
| 309 |
+
count = count + (len(aj) - z)
|
| 310 |
+
k = k + 1
|
| 311 |
+
if total > 0:
|
| 312 |
+
ret[i, j] = count / float(total)
|
| 313 |
+
return ret
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def get_duration_matrix(
|
| 317 |
+
activities, trace_grouped_list, timestamp_key, start_timestamp_key
|
| 318 |
+
):
|
| 319 |
+
"""
|
| 320 |
+
Calculates the duration matrix
|
| 321 |
+
|
| 322 |
+
Parameters
|
| 323 |
+
--------------
|
| 324 |
+
activities
|
| 325 |
+
Sorted list of activities of the log
|
| 326 |
+
trace_grouped_list
|
| 327 |
+
A list of lists of lists, containing for each trace and each activity the events having such activity
|
| 328 |
+
timestamp_key
|
| 329 |
+
The key to be used as timestamp
|
| 330 |
+
start_timestamp_key
|
| 331 |
+
The key to be used as start timestamp
|
| 332 |
+
|
| 333 |
+
Returns
|
| 334 |
+
--------------
|
| 335 |
+
mat
|
| 336 |
+
The duration matrix
|
| 337 |
+
"""
|
| 338 |
+
from statistics import mean
|
| 339 |
+
|
| 340 |
+
ret = np.zeros((len(activities), len(activities)))
|
| 341 |
+
for i in range(len(activities)):
|
| 342 |
+
for j in range(len(activities)):
|
| 343 |
+
if not i == j:
|
| 344 |
+
tm0 = []
|
| 345 |
+
tm1 = []
|
| 346 |
+
for tr in trace_grouped_list:
|
| 347 |
+
ai = [x[timestamp_key] for x in tr[i]]
|
| 348 |
+
aj = [x[start_timestamp_key] for x in tr[j]]
|
| 349 |
+
if ai and aj:
|
| 350 |
+
tm0 = cm_util.calculate_time_match_fifo(
|
| 351 |
+
ai, aj, times0=tm0
|
| 352 |
+
)
|
| 353 |
+
tm1 = cm_util.calculate_time_match_rlifo(
|
| 354 |
+
ai, aj, times1=tm1
|
| 355 |
+
)
|
| 356 |
+
td0 = mean([x[1] - x[0] for x in tm0]) if tm0 else 0
|
| 357 |
+
td1 = mean([x[1] - x[0] for x in tm1]) if tm1 else 0
|
| 358 |
+
ret[i, j] = min(td0, td1)
|
| 359 |
+
return ret
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/declare/__init__.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
|
| 23 |
+
from pm4py.algo.discovery.declare import algorithm, variants
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/declare/algorithm.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
|
| 23 |
+
from pm4py.util import exec_utils
|
| 24 |
+
from enum import Enum
|
| 25 |
+
from pm4py.algo.discovery.declare.variants import classic
|
| 26 |
+
from pm4py.objects.log.obj import EventLog
|
| 27 |
+
import pandas as pd
|
| 28 |
+
from typing import Union, Dict, Optional, Any
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Variants(Enum):
|
| 32 |
+
CLASSIC = classic
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def apply(
|
| 36 |
+
log: Union[EventLog, pd.DataFrame],
|
| 37 |
+
variant=Variants.CLASSIC,
|
| 38 |
+
parameters: Optional[Dict[Any, Any]] = None,
|
| 39 |
+
) -> Dict[str, Dict[Any, Dict[str, int]]]:
|
| 40 |
+
"""
|
| 41 |
+
Discovers a DECLARE model from the provided event log
|
| 42 |
+
|
| 43 |
+
Parameters
|
| 44 |
+
---------------
|
| 45 |
+
log
|
| 46 |
+
Log object (EventLog, Pandas dataframe)
|
| 47 |
+
variant
|
| 48 |
+
Variant of the algorithm to be used, including:
|
| 49 |
+
- Variants.CLASSIC
|
| 50 |
+
parameters
|
| 51 |
+
Variant-specific parameters
|
| 52 |
+
|
| 53 |
+
Returns
|
| 54 |
+
---------------
|
| 55 |
+
declare_model
|
| 56 |
+
DECLARE model (as Python dictionary), where each template is associated with its own rules
|
| 57 |
+
"""
|
| 58 |
+
return exec_utils.get_variant(variant).apply(log, parameters)
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/declare/templates.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
|
| 23 |
+
EXISTENCE = "existence"
|
| 24 |
+
EXACTLY_ONE = "exactly_one"
|
| 25 |
+
INIT = "init"
|
| 26 |
+
RESPONDED_EXISTENCE = "responded_existence"
|
| 27 |
+
RESPONSE = "response"
|
| 28 |
+
PRECEDENCE = "precedence"
|
| 29 |
+
SUCCESSION = "succession"
|
| 30 |
+
ALTRESPONSE = "altresponse"
|
| 31 |
+
ALTPRECEDENCE = "altprecedence"
|
| 32 |
+
ALTSUCCESSION = "altsuccession"
|
| 33 |
+
CHAINRESPONSE = "chainresponse"
|
| 34 |
+
CHAINPRECEDENCE = "chainprecedence"
|
| 35 |
+
CHAINSUCCESSION = "chainsuccession"
|
| 36 |
+
ABSENCE = "absence"
|
| 37 |
+
COEXISTENCE = "coexistence"
|
| 38 |
+
NONCOEXISTENCE = "noncoexistence"
|
| 39 |
+
NONSUCCESSION = "nonsuccession"
|
| 40 |
+
NONCHAINSUCCESSION = "nonchainsuccession"
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/declare/variants/__init__.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
|
| 23 |
+
from pm4py.algo.discovery.declare.variants import classic
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/declare/variants/classic.py
ADDED
|
@@ -0,0 +1,980 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
|
| 23 |
+
from enum import Enum
|
| 24 |
+
from pm4py.objects.log.obj import EventLog
|
| 25 |
+
from pm4py.algo.discovery.declare.templates import *
|
| 26 |
+
import pandas as pd
|
| 27 |
+
from typing import Union, Dict, Optional, Any, Tuple, Collection, Set, List
|
| 28 |
+
from typing import Counter as TCounter
|
| 29 |
+
from pm4py.util import exec_utils, constants, xes_constants, pandas_utils
|
| 30 |
+
from collections import Counter
|
| 31 |
+
import numpy as np
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class Parameters(Enum):
|
| 35 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 36 |
+
CASE_ID_KEY = constants.PARAMETER_CONSTANT_CASEID_KEY
|
| 37 |
+
CONSIDERED_ACTIVITIES = "considered_activities"
|
| 38 |
+
MIN_SUPPORT_RATIO = "min_support_ratio"
|
| 39 |
+
MIN_CONFIDENCE_RATIO = "min_confidence_ratio"
|
| 40 |
+
AUTO_SELECTION_MULTIPLIER = "auto_selection_multiplier"
|
| 41 |
+
ALLOWED_TEMPLATES = "allowed_templates"
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def __rule_existence_column(act: str) -> Tuple[str, str]:
|
| 45 |
+
return (EXISTENCE, act)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def __rule_exactly_one_column(act: str) -> Tuple[str, str]:
|
| 49 |
+
return (EXACTLY_ONE, act)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def __rule_init_column(act: str) -> Tuple[str, str]:
|
| 53 |
+
return (INIT, act)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def __rule_responded_existence_column(act: str, act2: str) -> Tuple[str, str, str]:
|
| 57 |
+
return (RESPONDED_EXISTENCE, act, act2)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def __rule_response(act: str, act2: str) -> Tuple[str, str, str]:
|
| 61 |
+
return (RESPONSE, act, act2)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def __rule_precedence(act: str, act2: str) -> Tuple[str, str, str]:
|
| 65 |
+
return (PRECEDENCE, act, act2)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def __rule_succession(act: str, act2: str) -> Tuple[str, str, str]:
|
| 69 |
+
return (SUCCESSION, act, act2)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def __rule_alternate_response(act: str, act2: str) -> Tuple[str, str, str]:
|
| 73 |
+
return (ALTRESPONSE, act, act2)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def __rule_alternate_precedence(act: str, act2: str) -> Tuple[str, str, str]:
|
| 77 |
+
return (ALTPRECEDENCE, act, act2)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def __rule_alternate_succession(act: str, act2: str) -> Tuple[str, str, str]:
|
| 81 |
+
return (ALTSUCCESSION, act, act2)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def __rule_chain_response(act: str, act2: str) -> Tuple[str, str, str]:
|
| 85 |
+
return (CHAINRESPONSE, act, act2)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def __rule_chain_precedence(act: str, act2: str) -> Tuple[str, str, str]:
|
| 89 |
+
return (CHAINPRECEDENCE, act, act2)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def __rule_chain_succession(act: str, act2: str) -> Tuple[str, str, str]:
|
| 93 |
+
return (CHAINSUCCESSION, act, act2)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def __rule_absence_act(act: str) -> Tuple[str, str]:
|
| 97 |
+
return (ABSENCE, act)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def __rule_coexistence(act: str, act2: str) -> Tuple[str, str, str]:
|
| 101 |
+
return (COEXISTENCE, act, act2)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def __rule_non_coexistence(act: str, act2: str) -> Tuple[str, str, str]:
|
| 105 |
+
return (NONCOEXISTENCE, act, act2)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def __rule_non_succession(act: str, act2: str) -> Tuple[str, str, str]:
|
| 109 |
+
return (NONSUCCESSION, act, act2)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def __rule_non_chain_succession(act: str, act2: str) -> Tuple[str, str, str]:
|
| 113 |
+
return (NONCHAINSUCCESSION, act, act2)
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def __col_to_dict_rule(
|
| 117 |
+
col_name: Union[Tuple[str, str], Tuple[str, str, str]]
|
| 118 |
+
) -> Tuple[str, Any]:
|
| 119 |
+
if len(col_name) == 2:
|
| 120 |
+
return col_name[0], col_name[1]
|
| 121 |
+
else:
|
| 122 |
+
if col_name[2] is None or pd.isna(col_name[2]) or not col_name[2]:
|
| 123 |
+
return col_name[0], col_name[1]
|
| 124 |
+
return col_name[0], (col_name[1], col_name[2])
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def __table_nrows(table: Dict[Any, Any]) -> int:
|
| 128 |
+
if not table:
|
| 129 |
+
return 0
|
| 130 |
+
return int(len(next(iter(table.values()))))
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def __is_alternate_response_satisfied(
|
| 134 |
+
trace_len: int, act_idxs: Dict[str, List[int]], act: str, act2: str
|
| 135 |
+
) -> bool:
|
| 136 |
+
"""
|
| 137 |
+
Alternate response(act, act2):
|
| 138 |
+
for each occurrence of act, there exists an occurrence of act2 AFTER it,
|
| 139 |
+
and BEFORE the next occurrence of act (if any).
|
| 140 |
+
Extra act2 occurrences are allowed.
|
| 141 |
+
"""
|
| 142 |
+
a_idxs = act_idxs.get(act, [])
|
| 143 |
+
if not a_idxs:
|
| 144 |
+
return True # vacuous (not activated)
|
| 145 |
+
b_idxs = act_idxs.get(act2, [])
|
| 146 |
+
if not b_idxs:
|
| 147 |
+
return False
|
| 148 |
+
|
| 149 |
+
b_ptr = 0
|
| 150 |
+
for i, a in enumerate(a_idxs):
|
| 151 |
+
next_a = a_idxs[i + 1] if i + 1 < len(a_idxs) else trace_len
|
| 152 |
+
while b_ptr < len(b_idxs) and b_idxs[b_ptr] <= a:
|
| 153 |
+
b_ptr += 1
|
| 154 |
+
if b_ptr >= len(b_idxs) or b_idxs[b_ptr] >= next_a:
|
| 155 |
+
return False
|
| 156 |
+
return True
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def __is_chain_response_satisfied(
|
| 160 |
+
trace: Collection[str], act_idxs: Dict[str, List[int]], act: str, act2: str
|
| 161 |
+
) -> bool:
|
| 162 |
+
"""
|
| 163 |
+
Chain response(act, act2):
|
| 164 |
+
for each occurrence of act, act2 occurs IMMEDIATELY after.
|
| 165 |
+
Extra act2 occurrences are allowed.
|
| 166 |
+
"""
|
| 167 |
+
a_idxs = act_idxs.get(act, [])
|
| 168 |
+
if not a_idxs:
|
| 169 |
+
return True # vacuous (not activated)
|
| 170 |
+
|
| 171 |
+
trace_list = list(trace)
|
| 172 |
+
n = len(trace_list)
|
| 173 |
+
for a in a_idxs:
|
| 174 |
+
if a + 1 >= n or trace_list[a + 1] != act2:
|
| 175 |
+
return False
|
| 176 |
+
return True
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def __is_alternate_precedence_satisfied(
|
| 180 |
+
act_idxs: Dict[str, List[int]], act: str, act2: str
|
| 181 |
+
) -> bool:
|
| 182 |
+
"""
|
| 183 |
+
Alternate precedence(act, act2):
|
| 184 |
+
for each occurrence of act2, there exists an occurrence of act BEFORE it,
|
| 185 |
+
and AFTER the previous occurrence of act2 (if any).
|
| 186 |
+
Extra act occurrences are allowed.
|
| 187 |
+
"""
|
| 188 |
+
b_idxs = act_idxs.get(act2, [])
|
| 189 |
+
if not b_idxs:
|
| 190 |
+
return True # vacuous (not activated)
|
| 191 |
+
a_idxs = act_idxs.get(act, [])
|
| 192 |
+
if not a_idxs:
|
| 193 |
+
return False
|
| 194 |
+
|
| 195 |
+
a_ptr = 0
|
| 196 |
+
prev_b = -1
|
| 197 |
+
for b in b_idxs:
|
| 198 |
+
while a_ptr < len(a_idxs) and a_idxs[a_ptr] <= prev_b:
|
| 199 |
+
a_ptr += 1
|
| 200 |
+
if a_ptr >= len(a_idxs) or a_idxs[a_ptr] >= b:
|
| 201 |
+
return False
|
| 202 |
+
prev_b = b
|
| 203 |
+
return True
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def __is_chain_precedence_satisfied(
|
| 207 |
+
trace: Collection[str], act_idxs: Dict[str, List[int]], act: str, act2: str
|
| 208 |
+
) -> bool:
|
| 209 |
+
"""
|
| 210 |
+
Chain precedence(act, act2):
|
| 211 |
+
for each occurrence of act2, act occurs IMMEDIATELY before.
|
| 212 |
+
Extra act occurrences are allowed.
|
| 213 |
+
"""
|
| 214 |
+
b_idxs = act_idxs.get(act2, [])
|
| 215 |
+
if not b_idxs:
|
| 216 |
+
return True # vacuous (not activated)
|
| 217 |
+
|
| 218 |
+
trace_list = list(trace)
|
| 219 |
+
for b in b_idxs:
|
| 220 |
+
if b == 0 or trace_list[b - 1] != act:
|
| 221 |
+
return False
|
| 222 |
+
return True
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
def existence_template_step1(
|
| 226 |
+
rules: Dict[Union[Tuple[str, str], Tuple[str, str, str]], int],
|
| 227 |
+
trace: Collection[str],
|
| 228 |
+
activities: Set[str],
|
| 229 |
+
act_counter: TCounter[str],
|
| 230 |
+
act_idxs: Dict[str, List[int]],
|
| 231 |
+
allowed_templates: Collection[str],
|
| 232 |
+
):
|
| 233 |
+
if EXISTENCE in allowed_templates:
|
| 234 |
+
for act in activities:
|
| 235 |
+
if act in act_counter:
|
| 236 |
+
rules[__rule_existence_column(act)] = 1
|
| 237 |
+
else:
|
| 238 |
+
rules[__rule_existence_column(act)] = -1
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def exactly_one_template_step1(
|
| 242 |
+
rules: Dict[Union[Tuple[str, str], Tuple[str, str, str]], int],
|
| 243 |
+
trace: Collection[str],
|
| 244 |
+
activities: Set[str],
|
| 245 |
+
act_counter: TCounter[str],
|
| 246 |
+
act_idxs: Dict[str, List[int]],
|
| 247 |
+
allowed_templates: Collection[str],
|
| 248 |
+
):
|
| 249 |
+
# BUGFIX: previously did not mark absence as a violation and could leave 0 values
|
| 250 |
+
# (i.e., "not activated"), which is wrong for a unary constraint like EXACTLY_ONE.
|
| 251 |
+
if EXACTLY_ONE in allowed_templates:
|
| 252 |
+
for act in activities:
|
| 253 |
+
if act_counter.get(act, 0) == 1:
|
| 254 |
+
rules[__rule_exactly_one_column(act)] = 1
|
| 255 |
+
else:
|
| 256 |
+
rules[__rule_exactly_one_column(act)] = -1
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def init_template_step1(
|
| 260 |
+
rules: Dict[Union[Tuple[str, str], Tuple[str, str, str]], int],
|
| 261 |
+
trace: Collection[str],
|
| 262 |
+
activities: Set[str],
|
| 263 |
+
act_counter: TCounter[str],
|
| 264 |
+
act_idxs: Dict[str, List[int]],
|
| 265 |
+
allowed_templates: Collection[str],
|
| 266 |
+
):
|
| 267 |
+
# BUGFIX: handle empty traces safely
|
| 268 |
+
if INIT in allowed_templates:
|
| 269 |
+
trace_list = list(trace)
|
| 270 |
+
first = trace_list[0] if trace_list else None
|
| 271 |
+
for act in activities:
|
| 272 |
+
if first is not None and act == first:
|
| 273 |
+
rules[__rule_init_column(act)] = 1
|
| 274 |
+
else:
|
| 275 |
+
rules[__rule_init_column(act)] = -1
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
def responded_existence_template_step1(
|
| 279 |
+
rules: Dict[Union[Tuple[str, str], Tuple[str, str, str]], int],
|
| 280 |
+
trace: Collection[str],
|
| 281 |
+
activities: Set[str],
|
| 282 |
+
act_counter: TCounter[str],
|
| 283 |
+
act_idxs: Dict[str, List[int]],
|
| 284 |
+
allowed_templates: Collection[str],
|
| 285 |
+
):
|
| 286 |
+
if RESPONDED_EXISTENCE in allowed_templates:
|
| 287 |
+
for act in act_counter:
|
| 288 |
+
for act2 in activities:
|
| 289 |
+
if act2 != act:
|
| 290 |
+
if act2 not in act_counter:
|
| 291 |
+
rules[__rule_responded_existence_column(act, act2)] = -1
|
| 292 |
+
else:
|
| 293 |
+
rules[__rule_responded_existence_column(act, act2)] = 1
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
def response_template_step1(
|
| 297 |
+
rules: Dict[Union[Tuple[str, str], Tuple[str, str, str]], int],
|
| 298 |
+
trace: Collection[str],
|
| 299 |
+
activities: Set[str],
|
| 300 |
+
act_counter: TCounter[str],
|
| 301 |
+
act_idxs: Dict[str, List[int]],
|
| 302 |
+
allowed_templates: Collection[str],
|
| 303 |
+
):
|
| 304 |
+
if RESPONSE in allowed_templates:
|
| 305 |
+
for act in act_counter:
|
| 306 |
+
for act2 in activities:
|
| 307 |
+
if act2 != act:
|
| 308 |
+
if act2 not in act_counter:
|
| 309 |
+
rules[__rule_response(act, act2)] = -1
|
| 310 |
+
else:
|
| 311 |
+
if act_idxs[act][-1] < act_idxs[act2][-1]:
|
| 312 |
+
rules[__rule_response(act, act2)] = 1
|
| 313 |
+
else:
|
| 314 |
+
rules[__rule_response(act, act2)] = -1
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
def precedence_template_step1(
|
| 318 |
+
rules: Dict[Union[Tuple[str, str], Tuple[str, str, str]], int],
|
| 319 |
+
trace: Collection[str],
|
| 320 |
+
activities: Set[str],
|
| 321 |
+
act_counter: TCounter[str],
|
| 322 |
+
act_idxs: Dict[str, List[int]],
|
| 323 |
+
allowed_templates: Collection[str],
|
| 324 |
+
):
|
| 325 |
+
# BUGFIX: previously "pass" when the precedent activity was missing, producing 0
|
| 326 |
+
# and inflating confidence/support in discovery. If B occurs and A is missing,
|
| 327 |
+
# precedence(A,B) is violated.
|
| 328 |
+
if PRECEDENCE in allowed_templates:
|
| 329 |
+
for b in act_counter: # activation on the consequent (B)
|
| 330 |
+
for a in activities:
|
| 331 |
+
if a != b:
|
| 332 |
+
if a not in act_counter:
|
| 333 |
+
rules[__rule_precedence(a, b)] = -1
|
| 334 |
+
else:
|
| 335 |
+
rules[__rule_precedence(a, b)] = (
|
| 336 |
+
1 if act_idxs[a][0] < act_idxs[b][0] else -1
|
| 337 |
+
)
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
def altresponse_template_step1(
|
| 341 |
+
rules: Dict[Union[Tuple[str, str], Tuple[str, str, str]], int],
|
| 342 |
+
trace: Collection[str],
|
| 343 |
+
activities: Set[str],
|
| 344 |
+
act_counter: TCounter[str],
|
| 345 |
+
act_idxs: Dict[str, List[int]],
|
| 346 |
+
allowed_templates: Collection[str],
|
| 347 |
+
):
|
| 348 |
+
# BUGFIX: previous implementation wrongly required |A| == |B| and penalized extra B's
|
| 349 |
+
if ALTRESPONSE in allowed_templates:
|
| 350 |
+
trace_len = len(list(trace))
|
| 351 |
+
for act in act_counter: # activation on A
|
| 352 |
+
for act2 in activities:
|
| 353 |
+
if act2 != act:
|
| 354 |
+
ok = __is_alternate_response_satisfied(trace_len, act_idxs, act, act2)
|
| 355 |
+
rules[__rule_alternate_response(act, act2)] = 1 if ok else -1
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
def chainresponse_template_step1(
|
| 359 |
+
rules: Dict[Union[Tuple[str, str], Tuple[str, str, str]], int],
|
| 360 |
+
trace: Collection[str],
|
| 361 |
+
activities: Set[str],
|
| 362 |
+
act_counter: TCounter[str],
|
| 363 |
+
act_idxs: Dict[str, List[int]],
|
| 364 |
+
allowed_templates: Collection[str],
|
| 365 |
+
):
|
| 366 |
+
# BUGFIX: previous implementation wrongly required |A| == |B| and penalized extra B's
|
| 367 |
+
if CHAINRESPONSE in allowed_templates:
|
| 368 |
+
trace_list = list(trace)
|
| 369 |
+
for act in act_counter: # activation on A
|
| 370 |
+
for act2 in activities:
|
| 371 |
+
if act2 != act:
|
| 372 |
+
ok = __is_chain_response_satisfied(trace_list, act_idxs, act, act2)
|
| 373 |
+
rules[__rule_chain_response(act, act2)] = 1 if ok else -1
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
def altprecedence_template_step1(
|
| 377 |
+
rules: Dict[Union[Tuple[str, str], Tuple[str, str, str]], int],
|
| 378 |
+
trace: Collection[str],
|
| 379 |
+
activities: Set[str],
|
| 380 |
+
act_counter: TCounter[str],
|
| 381 |
+
act_idxs: Dict[str, List[int]],
|
| 382 |
+
allowed_templates: Collection[str],
|
| 383 |
+
):
|
| 384 |
+
# BUGFIX: previous implementation wrongly required |A| == |B| and penalized extra A's
|
| 385 |
+
# (e.g., A after last B). Alternate precedence is activated by B and only constrains B's.
|
| 386 |
+
if ALTPRECEDENCE in allowed_templates:
|
| 387 |
+
for b in act_counter: # activation on B
|
| 388 |
+
for a in activities:
|
| 389 |
+
if a != b:
|
| 390 |
+
ok = __is_alternate_precedence_satisfied(act_idxs, a, b)
|
| 391 |
+
rules[__rule_alternate_precedence(a, b)] = 1 if ok else -1
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
def chainprecedence_template_step1(
|
| 395 |
+
rules: Dict[Union[Tuple[str, str], Tuple[str, str, str]], int],
|
| 396 |
+
trace: Collection[str],
|
| 397 |
+
activities: Set[str],
|
| 398 |
+
act_counter: TCounter[str],
|
| 399 |
+
act_idxs: Dict[str, List[int]],
|
| 400 |
+
allowed_templates: Collection[str],
|
| 401 |
+
):
|
| 402 |
+
# BUGFIX: previous implementation penalized extra A's (e.g., A after last B).
|
| 403 |
+
# Chain precedence is activated by B and only constrains B's.
|
| 404 |
+
if CHAINPRECEDENCE in allowed_templates:
|
| 405 |
+
trace_list = list(trace)
|
| 406 |
+
for b in act_counter: # activation on B
|
| 407 |
+
for a in activities:
|
| 408 |
+
if a != b:
|
| 409 |
+
ok = __is_chain_precedence_satisfied(trace_list, act_idxs, a, b)
|
| 410 |
+
rules[__rule_chain_precedence(a, b)] = 1 if ok else -1
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def absence_template(
|
| 414 |
+
table,
|
| 415 |
+
columns: Collection[str],
|
| 416 |
+
activities: Set[str],
|
| 417 |
+
allowed_templates: Collection[str],
|
| 418 |
+
) -> pd.DataFrame:
|
| 419 |
+
if not table:
|
| 420 |
+
return table
|
| 421 |
+
if ABSENCE in allowed_templates and EXISTENCE in allowed_templates:
|
| 422 |
+
for act in activities:
|
| 423 |
+
if __rule_existence_column(act) in table:
|
| 424 |
+
table[__rule_absence_act(act)] = -1 * table[__rule_existence_column(act)]
|
| 425 |
+
return table
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
def exactly_one_template_step2(
|
| 429 |
+
table,
|
| 430 |
+
columns: Collection[str],
|
| 431 |
+
activities: Set[str],
|
| 432 |
+
allowed_templates: Collection[str],
|
| 433 |
+
) -> pd.DataFrame:
|
| 434 |
+
if EXACTLY_ONE in allowed_templates:
|
| 435 |
+
n = __table_nrows(table)
|
| 436 |
+
for act in activities:
|
| 437 |
+
if __rule_exactly_one_column(act) not in table:
|
| 438 |
+
table[__rule_exactly_one_column(act)] = np.zeros(n, dtype=int)
|
| 439 |
+
return table
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
def responded_existence_template_step2(
|
| 443 |
+
table,
|
| 444 |
+
columns: Collection[str],
|
| 445 |
+
activities: Set[str],
|
| 446 |
+
allowed_templates: Collection[str],
|
| 447 |
+
) -> pd.DataFrame:
|
| 448 |
+
if RESPONDED_EXISTENCE in allowed_templates:
|
| 449 |
+
n = __table_nrows(table)
|
| 450 |
+
for act in activities:
|
| 451 |
+
for act2 in activities:
|
| 452 |
+
if act2 != act:
|
| 453 |
+
if __rule_responded_existence_column(act, act2) not in table:
|
| 454 |
+
table[__rule_responded_existence_column(act, act2)] = np.zeros(
|
| 455 |
+
n, dtype=int
|
| 456 |
+
)
|
| 457 |
+
return table
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
def response_template_step2(
|
| 461 |
+
table,
|
| 462 |
+
columns: Collection[str],
|
| 463 |
+
activities: Set[str],
|
| 464 |
+
allowed_templates: Collection[str],
|
| 465 |
+
) -> pd.DataFrame:
|
| 466 |
+
if RESPONSE in allowed_templates:
|
| 467 |
+
n = __table_nrows(table)
|
| 468 |
+
for act in activities:
|
| 469 |
+
for act2 in activities:
|
| 470 |
+
if act2 != act:
|
| 471 |
+
if __rule_response(act, act2) not in table:
|
| 472 |
+
table[__rule_response(act, act2)] = np.zeros(n, dtype=int)
|
| 473 |
+
return table
|
| 474 |
+
|
| 475 |
+
|
| 476 |
+
def precedence_template_step2(
|
| 477 |
+
table,
|
| 478 |
+
columns: Collection[str],
|
| 479 |
+
activities: Set[str],
|
| 480 |
+
allowed_templates: Collection[str],
|
| 481 |
+
) -> pd.DataFrame:
|
| 482 |
+
if PRECEDENCE in allowed_templates:
|
| 483 |
+
n = __table_nrows(table)
|
| 484 |
+
for act in activities:
|
| 485 |
+
for act2 in activities:
|
| 486 |
+
if act2 != act:
|
| 487 |
+
if __rule_precedence(act, act2) not in table:
|
| 488 |
+
table[__rule_precedence(act, act2)] = np.zeros(n, dtype=int)
|
| 489 |
+
return table
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
def altresponse_template_step2(
|
| 493 |
+
table,
|
| 494 |
+
columns: Collection[str],
|
| 495 |
+
activities: Set[str],
|
| 496 |
+
allowed_templates: Collection[str],
|
| 497 |
+
) -> pd.DataFrame:
|
| 498 |
+
if ALTRESPONSE in allowed_templates:
|
| 499 |
+
n = __table_nrows(table)
|
| 500 |
+
for act in activities:
|
| 501 |
+
for act2 in activities:
|
| 502 |
+
if act2 != act:
|
| 503 |
+
if __rule_alternate_response(act, act2) not in table:
|
| 504 |
+
table[__rule_alternate_response(act, act2)] = np.zeros(
|
| 505 |
+
n, dtype=int
|
| 506 |
+
)
|
| 507 |
+
return table
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
def chainresponse_template_step2(
|
| 511 |
+
table,
|
| 512 |
+
columns: Collection[str],
|
| 513 |
+
activities: Set[str],
|
| 514 |
+
allowed_templates: Collection[str],
|
| 515 |
+
) -> pd.DataFrame:
|
| 516 |
+
if CHAINRESPONSE in allowed_templates:
|
| 517 |
+
n = __table_nrows(table)
|
| 518 |
+
for act in activities:
|
| 519 |
+
for act2 in activities:
|
| 520 |
+
if act2 != act:
|
| 521 |
+
if __rule_chain_response(act, act2) not in table:
|
| 522 |
+
table[__rule_chain_response(act, act2)] = np.zeros(n, dtype=int)
|
| 523 |
+
return table
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
def altprecedence_template_step2(
|
| 527 |
+
table,
|
| 528 |
+
columns: Collection[str],
|
| 529 |
+
activities: Set[str],
|
| 530 |
+
allowed_templates: Collection[str],
|
| 531 |
+
) -> pd.DataFrame:
|
| 532 |
+
if ALTPRECEDENCE in allowed_templates:
|
| 533 |
+
n = __table_nrows(table)
|
| 534 |
+
for act in activities:
|
| 535 |
+
for act2 in activities:
|
| 536 |
+
if act2 != act:
|
| 537 |
+
if __rule_alternate_precedence(act, act2) not in table:
|
| 538 |
+
table[__rule_alternate_precedence(act, act2)] = np.zeros(
|
| 539 |
+
n, dtype=int
|
| 540 |
+
)
|
| 541 |
+
return table
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
def chainprecedence_template_step2(
|
| 545 |
+
table,
|
| 546 |
+
columns: Collection[str],
|
| 547 |
+
activities: Set[str],
|
| 548 |
+
allowed_templates: Collection[str],
|
| 549 |
+
) -> pd.DataFrame:
|
| 550 |
+
if CHAINPRECEDENCE in allowed_templates:
|
| 551 |
+
n = __table_nrows(table)
|
| 552 |
+
for act in activities:
|
| 553 |
+
for act2 in activities:
|
| 554 |
+
if act2 != act:
|
| 555 |
+
if __rule_chain_precedence(act, act2) not in table:
|
| 556 |
+
table[__rule_chain_precedence(act, act2)] = np.zeros(
|
| 557 |
+
n, dtype=int
|
| 558 |
+
)
|
| 559 |
+
return table
|
| 560 |
+
|
| 561 |
+
|
| 562 |
+
def succession_template(
|
| 563 |
+
table,
|
| 564 |
+
columns: Collection[str],
|
| 565 |
+
activities: Set[str],
|
| 566 |
+
allowed_templates: Collection[str],
|
| 567 |
+
) -> pd.DataFrame:
|
| 568 |
+
if not table:
|
| 569 |
+
return table
|
| 570 |
+
if (
|
| 571 |
+
SUCCESSION in allowed_templates
|
| 572 |
+
and RESPONSE in allowed_templates
|
| 573 |
+
and PRECEDENCE in allowed_templates
|
| 574 |
+
):
|
| 575 |
+
for act in activities:
|
| 576 |
+
for act2 in activities:
|
| 577 |
+
if act2 != act:
|
| 578 |
+
table[__rule_succession(act, act2)] = np.minimum(
|
| 579 |
+
table[__rule_response(act, act2)],
|
| 580 |
+
table[__rule_precedence(act, act2)],
|
| 581 |
+
)
|
| 582 |
+
return table
|
| 583 |
+
|
| 584 |
+
|
| 585 |
+
def altsuccession_template(
|
| 586 |
+
table,
|
| 587 |
+
columns: Collection[str],
|
| 588 |
+
activities: Set[str],
|
| 589 |
+
allowed_templates: Collection[str],
|
| 590 |
+
) -> pd.DataFrame:
|
| 591 |
+
if not table:
|
| 592 |
+
return table
|
| 593 |
+
if (
|
| 594 |
+
ALTSUCCESSION in allowed_templates
|
| 595 |
+
and ALTRESPONSE in allowed_templates
|
| 596 |
+
and ALTPRECEDENCE in allowed_templates
|
| 597 |
+
):
|
| 598 |
+
for act in activities:
|
| 599 |
+
for act2 in activities:
|
| 600 |
+
if act2 != act:
|
| 601 |
+
table[__rule_alternate_succession(act, act2)] = np.minimum(
|
| 602 |
+
table[__rule_alternate_response(act, act2)],
|
| 603 |
+
table[__rule_alternate_precedence(act, act2)],
|
| 604 |
+
)
|
| 605 |
+
return table
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
def chainsuccession_template(
|
| 609 |
+
table,
|
| 610 |
+
columns: Collection[str],
|
| 611 |
+
activities: Set[str],
|
| 612 |
+
allowed_templates: Collection[str],
|
| 613 |
+
) -> pd.DataFrame:
|
| 614 |
+
if not table:
|
| 615 |
+
return table
|
| 616 |
+
if (
|
| 617 |
+
CHAINSUCCESSION in allowed_templates
|
| 618 |
+
and CHAINRESPONSE in allowed_templates
|
| 619 |
+
and CHAINPRECEDENCE in allowed_templates
|
| 620 |
+
):
|
| 621 |
+
for act in activities:
|
| 622 |
+
for act2 in activities:
|
| 623 |
+
if act2 != act:
|
| 624 |
+
table[__rule_chain_succession(act, act2)] = np.minimum(
|
| 625 |
+
table[__rule_chain_response(act, act2)],
|
| 626 |
+
table[__rule_chain_precedence(act, act2)],
|
| 627 |
+
)
|
| 628 |
+
return table
|
| 629 |
+
|
| 630 |
+
|
| 631 |
+
def coexistence_template(
|
| 632 |
+
table,
|
| 633 |
+
columns: Collection[str],
|
| 634 |
+
activities: Set[str],
|
| 635 |
+
allowed_templates: Collection[str],
|
| 636 |
+
) -> pd.DataFrame:
|
| 637 |
+
if not table:
|
| 638 |
+
return table
|
| 639 |
+
if COEXISTENCE in allowed_templates and RESPONDED_EXISTENCE in allowed_templates:
|
| 640 |
+
for act in activities:
|
| 641 |
+
for act2 in activities:
|
| 642 |
+
if act2 != act:
|
| 643 |
+
table[__rule_coexistence(act, act2)] = np.minimum(
|
| 644 |
+
table[__rule_responded_existence_column(act, act2)],
|
| 645 |
+
table[__rule_responded_existence_column(act2, act)],
|
| 646 |
+
)
|
| 647 |
+
return table
|
| 648 |
+
|
| 649 |
+
|
| 650 |
+
def noncoexistence_template(
|
| 651 |
+
table,
|
| 652 |
+
columns: Collection[str],
|
| 653 |
+
activities: Set[str],
|
| 654 |
+
allowed_templates: Collection[str],
|
| 655 |
+
) -> pd.DataFrame:
|
| 656 |
+
if not table:
|
| 657 |
+
return table
|
| 658 |
+
if (
|
| 659 |
+
NONCOEXISTENCE in allowed_templates
|
| 660 |
+
and COEXISTENCE in allowed_templates
|
| 661 |
+
and RESPONDED_EXISTENCE in allowed_templates
|
| 662 |
+
):
|
| 663 |
+
for act in activities:
|
| 664 |
+
for act2 in activities:
|
| 665 |
+
if act2 != act:
|
| 666 |
+
table[__rule_non_coexistence(act, act2)] = -1 * table[
|
| 667 |
+
__rule_coexistence(act, act2)
|
| 668 |
+
]
|
| 669 |
+
return table
|
| 670 |
+
|
| 671 |
+
|
| 672 |
+
def nonsuccession_template(
|
| 673 |
+
table,
|
| 674 |
+
columns: Collection[str],
|
| 675 |
+
activities: Set[str],
|
| 676 |
+
allowed_templates: Collection[str],
|
| 677 |
+
) -> pd.DataFrame:
|
| 678 |
+
if not table:
|
| 679 |
+
return table
|
| 680 |
+
if (
|
| 681 |
+
NONSUCCESSION in allowed_templates
|
| 682 |
+
and SUCCESSION in allowed_templates
|
| 683 |
+
and RESPONSE in allowed_templates
|
| 684 |
+
and PRECEDENCE in allowed_templates
|
| 685 |
+
):
|
| 686 |
+
for act in activities:
|
| 687 |
+
for act2 in activities:
|
| 688 |
+
if act2 != act:
|
| 689 |
+
table[__rule_non_succession(act, act2)] = -1 * table[
|
| 690 |
+
__rule_succession(act, act2)
|
| 691 |
+
]
|
| 692 |
+
return table
|
| 693 |
+
|
| 694 |
+
|
| 695 |
+
def nonchainsuccession_template(
|
| 696 |
+
table,
|
| 697 |
+
columns: Collection[str],
|
| 698 |
+
activities: Set[str],
|
| 699 |
+
allowed_templates: Collection[str],
|
| 700 |
+
) -> pd.DataFrame:
|
| 701 |
+
if not table:
|
| 702 |
+
return table
|
| 703 |
+
if (
|
| 704 |
+
NONCHAINSUCCESSION in allowed_templates
|
| 705 |
+
and CHAINSUCCESSION in allowed_templates
|
| 706 |
+
and CHAINRESPONSE in allowed_templates
|
| 707 |
+
and CHAINPRECEDENCE in allowed_templates
|
| 708 |
+
):
|
| 709 |
+
for act in activities:
|
| 710 |
+
for act2 in activities:
|
| 711 |
+
if act2 != act:
|
| 712 |
+
table[__rule_non_chain_succession(act, act2)] = -1 * table[
|
| 713 |
+
__rule_chain_succession(act, act2)
|
| 714 |
+
]
|
| 715 |
+
return table
|
| 716 |
+
|
| 717 |
+
|
| 718 |
+
def form_rules_table(
|
| 719 |
+
log: Union[EventLog, pd.DataFrame],
|
| 720 |
+
parameters: Optional[Dict[Any, Any]] = None,
|
| 721 |
+
) -> pd.DataFrame:
|
| 722 |
+
if parameters is None:
|
| 723 |
+
parameters = {}
|
| 724 |
+
|
| 725 |
+
activity_key = exec_utils.get_param_value(
|
| 726 |
+
Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY
|
| 727 |
+
)
|
| 728 |
+
case_id_key = exec_utils.get_param_value(
|
| 729 |
+
Parameters.CASE_ID_KEY, parameters, constants.CASE_CONCEPT_NAME
|
| 730 |
+
)
|
| 731 |
+
|
| 732 |
+
allowed_templates = exec_utils.get_param_value(
|
| 733 |
+
Parameters.ALLOWED_TEMPLATES, parameters, None
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
if allowed_templates is None:
|
| 737 |
+
# BUGFIX: include negative templates as documented/implemented
|
| 738 |
+
allowed_templates = {
|
| 739 |
+
EXISTENCE,
|
| 740 |
+
EXACTLY_ONE,
|
| 741 |
+
INIT,
|
| 742 |
+
RESPONDED_EXISTENCE,
|
| 743 |
+
RESPONSE,
|
| 744 |
+
PRECEDENCE,
|
| 745 |
+
SUCCESSION,
|
| 746 |
+
ALTRESPONSE,
|
| 747 |
+
ALTPRECEDENCE,
|
| 748 |
+
ALTSUCCESSION,
|
| 749 |
+
CHAINRESPONSE,
|
| 750 |
+
CHAINPRECEDENCE,
|
| 751 |
+
CHAINSUCCESSION,
|
| 752 |
+
ABSENCE,
|
| 753 |
+
COEXISTENCE,
|
| 754 |
+
NONCOEXISTENCE,
|
| 755 |
+
NONSUCCESSION,
|
| 756 |
+
NONCHAINSUCCESSION,
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
import pm4py
|
| 760 |
+
|
| 761 |
+
projected_log = pm4py.project_on_event_attribute(
|
| 762 |
+
log, activity_key, case_id_key=case_id_key
|
| 763 |
+
)
|
| 764 |
+
activities = exec_utils.get_param_value(
|
| 765 |
+
Parameters.CONSIDERED_ACTIVITIES, parameters, None
|
| 766 |
+
)
|
| 767 |
+
|
| 768 |
+
if activities is None:
|
| 769 |
+
activities = set(y for x in projected_log for y in x)
|
| 770 |
+
|
| 771 |
+
allowed_templates = set(allowed_templates)
|
| 772 |
+
activities = set(activities)
|
| 773 |
+
|
| 774 |
+
# If there are no considered activities or no traces, return an empty dataframe safely.
|
| 775 |
+
if not activities or projected_log is None or len(projected_log) == 0:
|
| 776 |
+
return pandas_utils.instantiate_dataframe({})
|
| 777 |
+
|
| 778 |
+
vars = Counter([tuple([y for y in x if y in activities]) for x in projected_log])
|
| 779 |
+
table = []
|
| 780 |
+
|
| 781 |
+
for trace, occs in vars.items():
|
| 782 |
+
act_counter = Counter(trace)
|
| 783 |
+
act_idxs = {x: [] for x in set(trace)}
|
| 784 |
+
|
| 785 |
+
for idx, act in enumerate(trace):
|
| 786 |
+
act_idxs[act].append(idx)
|
| 787 |
+
|
| 788 |
+
rules = {}
|
| 789 |
+
|
| 790 |
+
existence_template_step1(
|
| 791 |
+
rules, trace, activities, act_counter, act_idxs, allowed_templates
|
| 792 |
+
)
|
| 793 |
+
exactly_one_template_step1(
|
| 794 |
+
rules, trace, activities, act_counter, act_idxs, allowed_templates
|
| 795 |
+
)
|
| 796 |
+
init_template_step1(rules, trace, activities, act_counter, act_idxs, allowed_templates)
|
| 797 |
+
responded_existence_template_step1(
|
| 798 |
+
rules, trace, activities, act_counter, act_idxs, allowed_templates
|
| 799 |
+
)
|
| 800 |
+
response_template_step1(
|
| 801 |
+
rules, trace, activities, act_counter, act_idxs, allowed_templates
|
| 802 |
+
)
|
| 803 |
+
precedence_template_step1(
|
| 804 |
+
rules, trace, activities, act_counter, act_idxs, allowed_templates
|
| 805 |
+
)
|
| 806 |
+
altresponse_template_step1(
|
| 807 |
+
rules, trace, activities, act_counter, act_idxs, allowed_templates
|
| 808 |
+
)
|
| 809 |
+
chainresponse_template_step1(
|
| 810 |
+
rules, trace, activities, act_counter, act_idxs, allowed_templates
|
| 811 |
+
)
|
| 812 |
+
altprecedence_template_step1(
|
| 813 |
+
rules, trace, activities, act_counter, act_idxs, allowed_templates
|
| 814 |
+
)
|
| 815 |
+
chainprecedence_template_step1(
|
| 816 |
+
rules, trace, activities, act_counter, act_idxs, allowed_templates
|
| 817 |
+
)
|
| 818 |
+
|
| 819 |
+
for _ in range(occs):
|
| 820 |
+
table.append(rules)
|
| 821 |
+
|
| 822 |
+
if not table:
|
| 823 |
+
return pandas_utils.instantiate_dataframe({})
|
| 824 |
+
|
| 825 |
+
columns = set(y for x in table for y in x.keys())
|
| 826 |
+
table2 = {c: [] for c in columns}
|
| 827 |
+
for i in range(len(table)):
|
| 828 |
+
trace = table[i]
|
| 829 |
+
for c in columns:
|
| 830 |
+
table2[c].append(trace.get(c, 0))
|
| 831 |
+
|
| 832 |
+
for c in table2:
|
| 833 |
+
table2[c] = np.array(table2[c], dtype=int)
|
| 834 |
+
|
| 835 |
+
table2 = absence_template(table2, columns, activities, allowed_templates)
|
| 836 |
+
table2 = exactly_one_template_step2(table2, columns, activities, allowed_templates)
|
| 837 |
+
table2 = responded_existence_template_step2(
|
| 838 |
+
table2, columns, activities, allowed_templates
|
| 839 |
+
)
|
| 840 |
+
table2 = response_template_step2(table2, columns, activities, allowed_templates)
|
| 841 |
+
table2 = precedence_template_step2(table2, columns, activities, allowed_templates)
|
| 842 |
+
table2 = altresponse_template_step2(table2, columns, activities, allowed_templates)
|
| 843 |
+
table2 = chainresponse_template_step2(table2, columns, activities, allowed_templates)
|
| 844 |
+
table2 = altprecedence_template_step2(table2, columns, activities, allowed_templates)
|
| 845 |
+
table2 = chainprecedence_template_step2(table2, columns, activities, allowed_templates)
|
| 846 |
+
|
| 847 |
+
table2 = succession_template(table2, columns, activities, allowed_templates)
|
| 848 |
+
table2 = altsuccession_template(table2, columns, activities, allowed_templates)
|
| 849 |
+
table2 = chainsuccession_template(table2, columns, activities, allowed_templates)
|
| 850 |
+
table2 = coexistence_template(table2, columns, activities, allowed_templates)
|
| 851 |
+
table2 = noncoexistence_template(table2, columns, activities, allowed_templates)
|
| 852 |
+
table2 = nonsuccession_template(table2, columns, activities, allowed_templates)
|
| 853 |
+
table2 = nonchainsuccession_template(table2, columns, activities, allowed_templates)
|
| 854 |
+
|
| 855 |
+
return pandas_utils.instantiate_dataframe(table2)
|
| 856 |
+
|
| 857 |
+
|
| 858 |
+
def get_rules_from_rules_df(
|
| 859 |
+
rules_df, parameters: Optional[Dict[Any, Any]] = None
|
| 860 |
+
) -> Dict[str, Dict[Any, Dict[str, int]]]:
|
| 861 |
+
if parameters is None:
|
| 862 |
+
parameters = {}
|
| 863 |
+
|
| 864 |
+
# BUGFIX: handle empty / None dataframes safely and handle partial threshold specification
|
| 865 |
+
if rules_df is None or len(rules_df) == 0:
|
| 866 |
+
return {}
|
| 867 |
+
|
| 868 |
+
min_support_ratio = exec_utils.get_param_value(
|
| 869 |
+
Parameters.MIN_SUPPORT_RATIO, parameters, None
|
| 870 |
+
)
|
| 871 |
+
min_confidence_ratio = exec_utils.get_param_value(
|
| 872 |
+
Parameters.MIN_CONFIDENCE_RATIO, parameters, None
|
| 873 |
+
)
|
| 874 |
+
rules = {}
|
| 875 |
+
|
| 876 |
+
if min_support_ratio is None and min_confidence_ratio is None:
|
| 877 |
+
# auto determine the minimum support and confidence ratio by
|
| 878 |
+
# identifying the values for the best feature
|
| 879 |
+
auto_selection_multiplier = exec_utils.get_param_value(
|
| 880 |
+
Parameters.AUTO_SELECTION_MULTIPLIER, parameters, 0.8
|
| 881 |
+
)
|
| 882 |
+
cols_prod = []
|
| 883 |
+
for col_name in rules_df:
|
| 884 |
+
col = rules_df[col_name]
|
| 885 |
+
supp = len(col[col != 0])
|
| 886 |
+
supp_ratio = float(supp) / float(len(rules_df)) if len(rules_df) > 0 else 0.0
|
| 887 |
+
if supp_ratio > 0:
|
| 888 |
+
conf_ratio = float(len(col[col == 1])) / float(supp)
|
| 889 |
+
prod = supp_ratio * conf_ratio
|
| 890 |
+
cols_prod.append((col_name, prod))
|
| 891 |
+
if not cols_prod:
|
| 892 |
+
return {}
|
| 893 |
+
cols_prod = sorted(cols_prod, key=lambda x: (x[1], x[0]), reverse=True)
|
| 894 |
+
col = rules_df[cols_prod[0][0]]
|
| 895 |
+
supp = len(col[col != 0])
|
| 896 |
+
min_support_ratio = float(supp) / float(len(rules_df)) * auto_selection_multiplier
|
| 897 |
+
min_confidence_ratio = (
|
| 898 |
+
float(len(col[col == 1])) / float(supp) * auto_selection_multiplier
|
| 899 |
+
if supp > 0
|
| 900 |
+
else 1.0
|
| 901 |
+
)
|
| 902 |
+
|
| 903 |
+
# If one of the two is provided and the other is not, interpret missing as "no filter"
|
| 904 |
+
if min_support_ratio is None:
|
| 905 |
+
min_support_ratio = 0.0
|
| 906 |
+
if min_confidence_ratio is None:
|
| 907 |
+
min_confidence_ratio = 0.0
|
| 908 |
+
|
| 909 |
+
for col_name in rules_df:
|
| 910 |
+
col = rules_df[col_name]
|
| 911 |
+
supp = len(col[col != 0])
|
| 912 |
+
|
| 913 |
+
if supp >= len(rules_df) * float(min_support_ratio):
|
| 914 |
+
conf = len(col[col == 1])
|
| 915 |
+
|
| 916 |
+
if supp == 0:
|
| 917 |
+
continue
|
| 918 |
+
if conf >= supp * float(min_confidence_ratio):
|
| 919 |
+
rule, key = __col_to_dict_rule(col_name)
|
| 920 |
+
if rule not in rules:
|
| 921 |
+
rules[rule] = {}
|
| 922 |
+
rules[rule][key] = {"support": supp, "confidence": conf}
|
| 923 |
+
|
| 924 |
+
return rules
|
| 925 |
+
|
| 926 |
+
|
| 927 |
+
def apply(
|
| 928 |
+
log: Union[EventLog, pd.DataFrame],
|
| 929 |
+
parameters: Optional[Dict[Any, Any]] = None,
|
| 930 |
+
) -> Dict[str, Dict[Any, Dict[str, int]]]:
|
| 931 |
+
"""
|
| 932 |
+
Discovers a DECLARE model from the provided event log.
|
| 933 |
+
|
| 934 |
+
Paper:
|
| 935 |
+
F. M. Maggi, A. J. Mooij and W. M. P. van der Aalst, "User-guided discovery of declarative process models," 2011 IEEE Symposium on Computational Intelligence and Data Mining (CIDM), Paris, France, 2011, pp. 192-199, doi: 10.1109/CIDM.2011.5949297.
|
| 936 |
+
|
| 937 |
+
Parameters
|
| 938 |
+
----------
|
| 939 |
+
log
|
| 940 |
+
Log object (EventLog, Pandas table)
|
| 941 |
+
parameters
|
| 942 |
+
Possible parameters of the algorithm, including:
|
| 943 |
+
|
| 944 |
+
- Parameters.ACTIVITY_KEY
|
| 945 |
+
- Parameters.CONSIDERED_ACTIVITIES
|
| 946 |
+
- Parameters.MIN_SUPPORT_RATIO
|
| 947 |
+
- Parameters.MIN_CONFIDENCE_RATIO
|
| 948 |
+
- Parameters.AUTO_SELECTION_MULTIPLIER
|
| 949 |
+
- Parameters.ALLOWED_TEMPLATES: collection of templates to consider, including:
|
| 950 |
+
|
| 951 |
+
* existence
|
| 952 |
+
* exactly_one
|
| 953 |
+
* init
|
| 954 |
+
* responded_existence
|
| 955 |
+
* response
|
| 956 |
+
* precedence
|
| 957 |
+
* succession
|
| 958 |
+
* altresponse
|
| 959 |
+
* altprecedence
|
| 960 |
+
* altsuccession
|
| 961 |
+
* chainresponse
|
| 962 |
+
* chainprecedence
|
| 963 |
+
* chainsuccession
|
| 964 |
+
* absence
|
| 965 |
+
* coexistence
|
| 966 |
+
* noncoexistence
|
| 967 |
+
* nonsuccession
|
| 968 |
+
* nonchainsuccession
|
| 969 |
+
|
| 970 |
+
Returns
|
| 971 |
+
-------
|
| 972 |
+
declare_model
|
| 973 |
+
DECLARE model (as Python dictionary), where each template is associated with its own rules
|
| 974 |
+
"""
|
| 975 |
+
if parameters is None:
|
| 976 |
+
parameters = {}
|
| 977 |
+
|
| 978 |
+
rules_df = form_rules_table(log, parameters=parameters)
|
| 979 |
+
rules = get_rules_from_rules_df(rules_df, parameters=parameters)
|
| 980 |
+
return rules
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.dfg import (
|
| 23 |
+
adapters,
|
| 24 |
+
variants,
|
| 25 |
+
algorithm,
|
| 26 |
+
replacement,
|
| 27 |
+
utils,
|
| 28 |
+
)
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.dfg.adapters import pandas
|
| 23 |
+
|
| 24 |
+
import importlib.util
|
| 25 |
+
|
| 26 |
+
if importlib.util.find_spec("polars"):
|
| 27 |
+
from pm4py.algo.discovery.dfg.adapters import polars
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/pandas/__init__.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.dfg.adapters.pandas import (
|
| 23 |
+
df_statistics,
|
| 24 |
+
freq_triples,
|
| 25 |
+
)
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/pandas/df_statistics.py
ADDED
|
@@ -0,0 +1,455 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
import numpy as np
|
| 23 |
+
|
| 24 |
+
from pm4py.util import xes_constants, pandas_utils, constants
|
| 25 |
+
from pm4py.util.business_hours import soj_time_business_hours_diff
|
| 26 |
+
import pandas as pd
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def get_dfg_graph(
|
| 30 |
+
df,
|
| 31 |
+
measure="frequency",
|
| 32 |
+
activity_key="concept:name",
|
| 33 |
+
case_id_glue="case:concept:name",
|
| 34 |
+
start_timestamp_key=None,
|
| 35 |
+
timestamp_key="time:timestamp",
|
| 36 |
+
perf_aggregation_key="mean",
|
| 37 |
+
sort_caseid_required=True,
|
| 38 |
+
sort_timestamp_along_case_id=True,
|
| 39 |
+
keep_once_per_case=False,
|
| 40 |
+
window=1,
|
| 41 |
+
business_hours=False,
|
| 42 |
+
business_hours_slot=None,
|
| 43 |
+
workcalendar=constants.DEFAULT_BUSINESS_HOURS_WORKCALENDAR,
|
| 44 |
+
target_activity_key=None,
|
| 45 |
+
reduce_columns=True,
|
| 46 |
+
cost_attribute=None,
|
| 47 |
+
):
|
| 48 |
+
"""
|
| 49 |
+
Get DFG graph from Pandas dataframe - optimized version
|
| 50 |
+
|
| 51 |
+
Parameters
|
| 52 |
+
-----------
|
| 53 |
+
df
|
| 54 |
+
Dataframe
|
| 55 |
+
measure
|
| 56 |
+
Measure to use (frequency/performance/both)
|
| 57 |
+
activity_key
|
| 58 |
+
Activity key to use in the grouping
|
| 59 |
+
case_id_glue
|
| 60 |
+
Case ID identifier
|
| 61 |
+
start_timestamp_key
|
| 62 |
+
Start timestamp key
|
| 63 |
+
timestamp_key
|
| 64 |
+
Timestamp key
|
| 65 |
+
perf_aggregation_key
|
| 66 |
+
Performance aggregation key (mean, median, min, max)
|
| 67 |
+
sort_caseid_required
|
| 68 |
+
Specify if a sort on the Case ID is required
|
| 69 |
+
sort_timestamp_along_case_id
|
| 70 |
+
Specifying if sorting by timestamp along the CaseID is required
|
| 71 |
+
keep_once_per_case
|
| 72 |
+
In the counts, keep only one occurrence of the path per case (the first)
|
| 73 |
+
window
|
| 74 |
+
Window of the DFG (default 1)
|
| 75 |
+
|
| 76 |
+
Returns
|
| 77 |
+
-------
|
| 78 |
+
dfg : dict
|
| 79 |
+
DFG in the chosen measure (may be only the frequency, only the performance, or both)
|
| 80 |
+
|
| 81 |
+
"""
|
| 82 |
+
# added support to specify an activity key for the target event which is different
|
| 83 |
+
# from the activity key of the source event.
|
| 84 |
+
if target_activity_key is None:
|
| 85 |
+
target_activity_key = activity_key
|
| 86 |
+
|
| 87 |
+
# if not differently specified, set the start timestamp key to the timestamp key
|
| 88 |
+
# to avoid retro-compatibility problems
|
| 89 |
+
st_eq_ct = start_timestamp_key == timestamp_key
|
| 90 |
+
if start_timestamp_key is None:
|
| 91 |
+
start_timestamp_key = xes_constants.DEFAULT_START_TIMESTAMP_KEY
|
| 92 |
+
if start_timestamp_key not in df.columns:
|
| 93 |
+
df[start_timestamp_key] = df[timestamp_key]
|
| 94 |
+
st_eq_ct = True
|
| 95 |
+
|
| 96 |
+
# Determine which columns we need to keep before reducing
|
| 97 |
+
needed_columns = {case_id_glue, activity_key, target_activity_key}
|
| 98 |
+
if measure != "frequency" or sort_timestamp_along_case_id:
|
| 99 |
+
needed_columns.update({start_timestamp_key, timestamp_key})
|
| 100 |
+
if measure == "cost":
|
| 101 |
+
needed_columns.add(cost_attribute)
|
| 102 |
+
|
| 103 |
+
# Reduce dataframe to necessary columns (more efficient than previous implementation)
|
| 104 |
+
if reduce_columns:
|
| 105 |
+
df = df[list(needed_columns)]
|
| 106 |
+
|
| 107 |
+
if measure == "cost":
|
| 108 |
+
df[cost_attribute] = df[cost_attribute].fillna(0) # Using 0 directly is more efficient
|
| 109 |
+
|
| 110 |
+
# Create a view with the needed sorting for more efficient memory usage
|
| 111 |
+
if sort_caseid_required:
|
| 112 |
+
if sort_timestamp_along_case_id:
|
| 113 |
+
df = df.sort_values([case_id_glue, start_timestamp_key, timestamp_key])
|
| 114 |
+
else:
|
| 115 |
+
df = df.sort_values(case_id_glue)
|
| 116 |
+
|
| 117 |
+
# Pre-create the suffixed column names for more efficient joining
|
| 118 |
+
suffix = "_2"
|
| 119 |
+
# Get a list of column names before shift to avoid recreating them
|
| 120 |
+
orig_cols = df.columns.tolist()
|
| 121 |
+
shifted_cols = [str(col) + suffix for col in orig_cols]
|
| 122 |
+
|
| 123 |
+
# Shift the dataframe by window
|
| 124 |
+
df_shifted = df.shift(-window)
|
| 125 |
+
df_shifted.columns = shifted_cols
|
| 126 |
+
|
| 127 |
+
# Concatenate the dataframes efficiently
|
| 128 |
+
df_successive_rows = pandas_utils.DATAFRAME.concat([df, df_shifted], axis=1)
|
| 129 |
+
|
| 130 |
+
# Filter for matching case IDs (more efficient with direct access)
|
| 131 |
+
case_id_col = case_id_glue
|
| 132 |
+
case_id_col_shifted = case_id_glue + suffix
|
| 133 |
+
df_successive_rows = df_successive_rows[df_successive_rows[case_id_col] == df_successive_rows[case_id_col_shifted]]
|
| 134 |
+
|
| 135 |
+
# Handle keep_once_per_case more efficiently
|
| 136 |
+
if keep_once_per_case:
|
| 137 |
+
# Use drop_duplicates which is more efficient than groupby + first for this operation
|
| 138 |
+
df_successive_rows = df_successive_rows.drop_duplicates(
|
| 139 |
+
subset=[case_id_glue, activity_key, target_activity_key + suffix]
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
# Calculate performance metrics if needed
|
| 143 |
+
if measure in ["performance", "both"]:
|
| 144 |
+
if not st_eq_ct:
|
| 145 |
+
# Calculate max more efficiently using numpy
|
| 146 |
+
df_successive_rows[start_timestamp_key + suffix] = np.maximum(
|
| 147 |
+
df_successive_rows[start_timestamp_key + suffix],
|
| 148 |
+
df_successive_rows[timestamp_key]
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
# Calculate the time difference
|
| 152 |
+
if business_hours:
|
| 153 |
+
if business_hours_slot is None:
|
| 154 |
+
business_hours_slot = constants.DEFAULT_BUSINESS_HOUR_SLOTS
|
| 155 |
+
|
| 156 |
+
# Business hours calculation requires Python datetime objects
|
| 157 |
+
# Use a more efficient approach than apply, but ensure we're working with correct datetime types
|
| 158 |
+
|
| 159 |
+
# Convert timestamps - we need to use to_pydatetime() to get Python datetime objects
|
| 160 |
+
# that are compatible with the business hours function
|
| 161 |
+
if hasattr(df_successive_rows[timestamp_key], 'dt'):
|
| 162 |
+
# If timestamps are already pandas datetime, convert to Python datetime
|
| 163 |
+
ts_values = np.array(df_successive_rows[timestamp_key].dt.to_pydatetime())
|
| 164 |
+
start_ts_values = np.array(df_successive_rows[start_timestamp_key + suffix].dt.to_pydatetime())
|
| 165 |
+
else:
|
| 166 |
+
# If timestamps are pandas Timestamp objects or strings, convert properly
|
| 167 |
+
ts_values = np.array(pandas_utils.DATAFRAME.to_datetime(df_successive_rows[timestamp_key]).dt.to_pydatetime())
|
| 168 |
+
start_ts_values = np.array(pandas_utils.DATAFRAME.to_datetime(df_successive_rows[start_timestamp_key + suffix]).dt.to_pydatetime())
|
| 169 |
+
|
| 170 |
+
# Use list comprehension which is faster than apply but handles datetime objects correctly
|
| 171 |
+
flow_times = [
|
| 172 |
+
soj_time_business_hours_diff(ts, start_ts, business_hours_slot, workcalendar)
|
| 173 |
+
for ts, start_ts in zip(ts_values, start_ts_values)
|
| 174 |
+
]
|
| 175 |
+
|
| 176 |
+
df_successive_rows[constants.DEFAULT_FLOW_TIME] = flow_times
|
| 177 |
+
else:
|
| 178 |
+
# Vectorized timestamp difference calculation (already efficient)
|
| 179 |
+
difference = df_successive_rows[start_timestamp_key + suffix] - df_successive_rows[timestamp_key]
|
| 180 |
+
df_successive_rows[constants.DEFAULT_FLOW_TIME] = pandas_utils.get_total_seconds(difference)
|
| 181 |
+
|
| 182 |
+
# Set up grouping based on measure
|
| 183 |
+
group_cols = [activity_key, target_activity_key + suffix]
|
| 184 |
+
|
| 185 |
+
if measure == "performance" or measure == "both":
|
| 186 |
+
agg_col = constants.DEFAULT_FLOW_TIME
|
| 187 |
+
elif measure == "cost":
|
| 188 |
+
agg_col = cost_attribute + suffix
|
| 189 |
+
else:
|
| 190 |
+
# For frequency, find the first non-grouping column to use (more efficient)
|
| 191 |
+
remaining_cols = set(df_successive_rows.columns) - set(group_cols)
|
| 192 |
+
agg_col = next(iter(remaining_cols)) if remaining_cols else case_id_col
|
| 193 |
+
|
| 194 |
+
# Create dictionary directly rather than creating a Series object first (more efficient)
|
| 195 |
+
if measure == "frequency" or measure == "both":
|
| 196 |
+
# Use value_counts which is more efficient than groupby+size for frequency
|
| 197 |
+
if type(df) is pd.DataFrame and len(group_cols) == 2: # Most common case
|
| 198 |
+
temp_df = df_successive_rows[group_cols].copy()
|
| 199 |
+
temp_df['dummy'] = 1 # Add a column to count
|
| 200 |
+
pivot = temp_df.pivot_table(
|
| 201 |
+
index=group_cols[0],
|
| 202 |
+
columns=group_cols[1],
|
| 203 |
+
values='dummy',
|
| 204 |
+
aggfunc='count',
|
| 205 |
+
fill_value=0
|
| 206 |
+
)
|
| 207 |
+
dfg_frequency = {(idx, col): val for idx, row in pivot.iterrows() for col, val in row.items() if val > 0}
|
| 208 |
+
else:
|
| 209 |
+
# Fallback to groupby
|
| 210 |
+
dfg_frequency = df_successive_rows.groupby(group_cols).size().to_dict()
|
| 211 |
+
|
| 212 |
+
# Performance metrics calculation
|
| 213 |
+
dfg_performance = {}
|
| 214 |
+
if measure in ["performance", "cost", "both"]:
|
| 215 |
+
grouped = df_successive_rows.groupby(group_cols)[agg_col]
|
| 216 |
+
|
| 217 |
+
if perf_aggregation_key == "all":
|
| 218 |
+
# Calculate all metrics at once (more efficient than separate calls)
|
| 219 |
+
metrics = grouped.agg(['mean', 'median', 'max', 'min', 'sum', 'std'])
|
| 220 |
+
|
| 221 |
+
if type(metrics) is pd.DataFrame:
|
| 222 |
+
metrics = metrics.iterrows()
|
| 223 |
+
else:
|
| 224 |
+
metrics = metrics.to_pandas().iterrows()
|
| 225 |
+
|
| 226 |
+
# Convert to the expected dictionary structure
|
| 227 |
+
dfg_performance = {
|
| 228 |
+
group: {
|
| 229 |
+
'mean': row['mean'],
|
| 230 |
+
'median': row['median'],
|
| 231 |
+
'max': row['max'],
|
| 232 |
+
'min': row['min'],
|
| 233 |
+
'sum': row['sum'],
|
| 234 |
+
'stdev': row['std']
|
| 235 |
+
}
|
| 236 |
+
for group, row in metrics
|
| 237 |
+
}
|
| 238 |
+
elif perf_aggregation_key == "raw_values":
|
| 239 |
+
dfg_performance = grouped.agg(list).to_dict()
|
| 240 |
+
else:
|
| 241 |
+
dfg_performance = grouped.agg(perf_aggregation_key).to_dict()
|
| 242 |
+
|
| 243 |
+
# Return appropriate results based on measure
|
| 244 |
+
if measure == "frequency":
|
| 245 |
+
return dfg_frequency
|
| 246 |
+
elif measure == "performance" or measure == "cost":
|
| 247 |
+
return dfg_performance
|
| 248 |
+
else: # measure == "both"
|
| 249 |
+
return [dfg_frequency, dfg_performance]
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def get_partial_order_dataframe(
|
| 253 |
+
df,
|
| 254 |
+
start_timestamp_key=None,
|
| 255 |
+
timestamp_key="time:timestamp",
|
| 256 |
+
case_id_glue="case:concept:name",
|
| 257 |
+
activity_key="concept:name",
|
| 258 |
+
sort_caseid_required=True,
|
| 259 |
+
sort_timestamp_along_case_id=True,
|
| 260 |
+
reduce_dataframe=True,
|
| 261 |
+
keep_first_following=True,
|
| 262 |
+
business_hours=False,
|
| 263 |
+
business_hours_slot=None,
|
| 264 |
+
workcalendar=constants.DEFAULT_BUSINESS_HOURS_WORKCALENDAR,
|
| 265 |
+
event_index=constants.DEFAULT_INDEX_KEY,
|
| 266 |
+
):
|
| 267 |
+
"""
|
| 268 |
+
Gets the partial order between events (of the same case) in a Pandas dataframe
|
| 269 |
+
|
| 270 |
+
Parameters
|
| 271 |
+
--------------
|
| 272 |
+
df
|
| 273 |
+
Dataframe
|
| 274 |
+
start_timestamp_key
|
| 275 |
+
Start timestamp key (if not provided, defaulted to the timestamp_key)
|
| 276 |
+
timestamp_key
|
| 277 |
+
Complete timestamp
|
| 278 |
+
case_id_glue
|
| 279 |
+
Column of the dataframe to use as case ID
|
| 280 |
+
activity_key
|
| 281 |
+
Activity key
|
| 282 |
+
sort_caseid_required
|
| 283 |
+
Tells if a sort by case ID is required (default: True)
|
| 284 |
+
sort_timestamp_along_case_id
|
| 285 |
+
Tells if a sort by timestamp is required along the case ID (default: True)
|
| 286 |
+
reduce_dataframe
|
| 287 |
+
To fasten operation, keep only essential columns in the dataframe
|
| 288 |
+
keep_first_following
|
| 289 |
+
Keep only the first event following the given event
|
| 290 |
+
Returns
|
| 291 |
+
---------------
|
| 292 |
+
part_ord_dataframe
|
| 293 |
+
Partial order dataframe (with @@flow_time between events)
|
| 294 |
+
"""
|
| 295 |
+
# if not differently specified, set the start timestamp key to the timestamp key
|
| 296 |
+
# to avoid retro-compatibility problems
|
| 297 |
+
if start_timestamp_key is None:
|
| 298 |
+
start_timestamp_key = xes_constants.DEFAULT_START_TIMESTAMP_KEY
|
| 299 |
+
|
| 300 |
+
if start_timestamp_key not in df:
|
| 301 |
+
df[start_timestamp_key] = df[timestamp_key]
|
| 302 |
+
|
| 303 |
+
# to increase the speed of the approaches reduce dataframe to case, activity (and possibly complete timestamp)
|
| 304 |
+
# columns
|
| 305 |
+
if reduce_dataframe:
|
| 306 |
+
needed_columns = {
|
| 307 |
+
case_id_glue,
|
| 308 |
+
activity_key,
|
| 309 |
+
start_timestamp_key,
|
| 310 |
+
timestamp_key,
|
| 311 |
+
}
|
| 312 |
+
if event_index in df.columns:
|
| 313 |
+
needed_columns.add(event_index)
|
| 314 |
+
needed_columns = list(needed_columns)
|
| 315 |
+
df = df[needed_columns]
|
| 316 |
+
|
| 317 |
+
# to get rows belonging to same case ID together, we need to sort on case
|
| 318 |
+
# ID
|
| 319 |
+
if sort_caseid_required:
|
| 320 |
+
if sort_timestamp_along_case_id:
|
| 321 |
+
df = df.sort_values(
|
| 322 |
+
[case_id_glue, start_timestamp_key, timestamp_key]
|
| 323 |
+
)
|
| 324 |
+
else:
|
| 325 |
+
df = df.sort_values(case_id_glue)
|
| 326 |
+
df = df.reset_index(drop=True)
|
| 327 |
+
|
| 328 |
+
if event_index not in df.columns:
|
| 329 |
+
df = pandas_utils.insert_index(
|
| 330 |
+
df, event_index, copy_dataframe=False, reset_index=False
|
| 331 |
+
)
|
| 332 |
+
|
| 333 |
+
df = df.set_index(case_id_glue)
|
| 334 |
+
|
| 335 |
+
df = df.join(df, rsuffix="_2")
|
| 336 |
+
df = df[df[event_index] < df[event_index + "_2"]]
|
| 337 |
+
df = df[df[timestamp_key] <= df[start_timestamp_key + "_2"]]
|
| 338 |
+
|
| 339 |
+
df = df.reset_index()
|
| 340 |
+
|
| 341 |
+
if business_hours:
|
| 342 |
+
if business_hours_slot is None:
|
| 343 |
+
business_hours_slot = constants.DEFAULT_BUSINESS_HOUR_SLOTS
|
| 344 |
+
df[constants.DEFAULT_FLOW_TIME] = df.apply(
|
| 345 |
+
lambda x: soj_time_business_hours_diff(
|
| 346 |
+
x[timestamp_key],
|
| 347 |
+
x[start_timestamp_key + "_2"],
|
| 348 |
+
business_hours_slot,
|
| 349 |
+
workcalendar,
|
| 350 |
+
),
|
| 351 |
+
axis=1,
|
| 352 |
+
)
|
| 353 |
+
else:
|
| 354 |
+
df[constants.DEFAULT_FLOW_TIME] = pandas_utils.get_total_seconds(
|
| 355 |
+
df[start_timestamp_key + "_2"] - df[timestamp_key]
|
| 356 |
+
)
|
| 357 |
+
|
| 358 |
+
if keep_first_following:
|
| 359 |
+
df = df.groupby(constants.DEFAULT_INDEX_KEY).first().reset_index()
|
| 360 |
+
|
| 361 |
+
return df
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def get_concurrent_events_dataframe(
|
| 365 |
+
df,
|
| 366 |
+
start_timestamp_key=None,
|
| 367 |
+
timestamp_key="time:timestamp",
|
| 368 |
+
case_id_glue="case:concept:name",
|
| 369 |
+
activity_key="concept:name",
|
| 370 |
+
sort_caseid_required=True,
|
| 371 |
+
sort_timestamp_along_case_id=True,
|
| 372 |
+
reduce_dataframe=True,
|
| 373 |
+
max_start_column="@@max_start_column",
|
| 374 |
+
min_complete_column="@@min_complete_column",
|
| 375 |
+
diff_maxs_minc="@@diff_maxs_minc",
|
| 376 |
+
strict=False,
|
| 377 |
+
):
|
| 378 |
+
"""
|
| 379 |
+
Gets the concurrent events (of the same case) in a Pandas dataframe
|
| 380 |
+
|
| 381 |
+
Parameters
|
| 382 |
+
--------------
|
| 383 |
+
df
|
| 384 |
+
Dataframe
|
| 385 |
+
start_timestamp_key
|
| 386 |
+
Start timestamp key (if not provided, defaulted to the timestamp_key)
|
| 387 |
+
timestamp_key
|
| 388 |
+
Complete timestamp
|
| 389 |
+
case_id_glue
|
| 390 |
+
Column of the dataframe to use as case ID
|
| 391 |
+
activity_key
|
| 392 |
+
Activity key
|
| 393 |
+
sort_caseid_required
|
| 394 |
+
Tells if a sort by case ID is required (default: True)
|
| 395 |
+
sort_timestamp_along_case_id
|
| 396 |
+
Tells if a sort by timestamp is required along the case ID (default: True)
|
| 397 |
+
reduce_dataframe
|
| 398 |
+
To fasten operation, keep only essential columns in the dataframe
|
| 399 |
+
strict
|
| 400 |
+
Gets only entries that are strictly concurrent (i.e. the length of the intersection as real interval is > 0)
|
| 401 |
+
|
| 402 |
+
Returns
|
| 403 |
+
---------------
|
| 404 |
+
conc_ev_dataframe
|
| 405 |
+
Concurrent events dataframe (with @@diff_maxs_minc as the size of the intersection of the intervals)
|
| 406 |
+
"""
|
| 407 |
+
# if not differently specified, set the start timestamp key to the timestamp key
|
| 408 |
+
# to avoid retro-compatibility problems
|
| 409 |
+
if start_timestamp_key is None:
|
| 410 |
+
start_timestamp_key = xes_constants.DEFAULT_START_TIMESTAMP_KEY
|
| 411 |
+
df[start_timestamp_key] = df[timestamp_key]
|
| 412 |
+
|
| 413 |
+
# to get rows belonging to same case ID together, we need to sort on case
|
| 414 |
+
# ID
|
| 415 |
+
if sort_caseid_required:
|
| 416 |
+
if sort_timestamp_along_case_id:
|
| 417 |
+
df = df.sort_values(
|
| 418 |
+
[case_id_glue, start_timestamp_key, timestamp_key]
|
| 419 |
+
)
|
| 420 |
+
else:
|
| 421 |
+
df = df.sort_values(case_id_glue)
|
| 422 |
+
|
| 423 |
+
# to increase the speed of the approaches reduce dataframe to case, activity (and possibly complete timestamp)
|
| 424 |
+
# columns
|
| 425 |
+
if reduce_dataframe:
|
| 426 |
+
df = df[
|
| 427 |
+
[case_id_glue, activity_key, start_timestamp_key, timestamp_key]
|
| 428 |
+
]
|
| 429 |
+
|
| 430 |
+
df = pandas_utils.insert_index(df)
|
| 431 |
+
df = df.set_index(case_id_glue)
|
| 432 |
+
df_copy = df.copy()
|
| 433 |
+
|
| 434 |
+
df = df.join(df_copy, rsuffix="_2").dropna()
|
| 435 |
+
df = df[
|
| 436 |
+
df[constants.DEFAULT_INDEX_KEY]
|
| 437 |
+
< df[constants.DEFAULT_INDEX_KEY + "_2"]
|
| 438 |
+
]
|
| 439 |
+
df[max_start_column] = df[
|
| 440 |
+
[start_timestamp_key, start_timestamp_key + "_2"]
|
| 441 |
+
].max(axis=1)
|
| 442 |
+
df[min_complete_column] = df[[timestamp_key, timestamp_key + "_2"]].min(
|
| 443 |
+
axis=1
|
| 444 |
+
)
|
| 445 |
+
df[max_start_column] = df[max_start_column].apply(lambda x: x.timestamp())
|
| 446 |
+
df[min_complete_column] = df[min_complete_column].apply(
|
| 447 |
+
lambda x: x.timestamp()
|
| 448 |
+
)
|
| 449 |
+
df[diff_maxs_minc] = df[min_complete_column] - df[max_start_column]
|
| 450 |
+
if strict:
|
| 451 |
+
df = df[df[diff_maxs_minc] > 0]
|
| 452 |
+
else:
|
| 453 |
+
df = df[df[diff_maxs_minc] >= 0]
|
| 454 |
+
|
| 455 |
+
return df
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/pandas/freq_triples.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.util import constants, pandas_utils
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def get_freq_triples(
|
| 26 |
+
df,
|
| 27 |
+
activity_key="concept:name",
|
| 28 |
+
case_id_glue="case:concept:name",
|
| 29 |
+
timestamp_key="time:timestamp",
|
| 30 |
+
sort_caseid_required=True,
|
| 31 |
+
sort_timestamp_along_case_id=True,
|
| 32 |
+
):
|
| 33 |
+
"""
|
| 34 |
+
Gets the frequency triples out of a dataframe
|
| 35 |
+
|
| 36 |
+
Parameters
|
| 37 |
+
------------
|
| 38 |
+
df
|
| 39 |
+
Dataframe
|
| 40 |
+
activity_key
|
| 41 |
+
Activity key
|
| 42 |
+
case_id_glue
|
| 43 |
+
Case ID glue
|
| 44 |
+
timestamp_key
|
| 45 |
+
Timestamp key
|
| 46 |
+
sort_caseid_required
|
| 47 |
+
Determine if sort by case ID is required (default: True)
|
| 48 |
+
sort_timestamp_along_case_id
|
| 49 |
+
Determine if sort by timestamp is required (default: True)
|
| 50 |
+
|
| 51 |
+
Returns
|
| 52 |
+
-------------
|
| 53 |
+
freq_triples
|
| 54 |
+
Frequency triples from the dataframe
|
| 55 |
+
"""
|
| 56 |
+
import pandas as pd
|
| 57 |
+
|
| 58 |
+
if sort_caseid_required:
|
| 59 |
+
if sort_timestamp_along_case_id:
|
| 60 |
+
df = df.sort_values([case_id_glue, timestamp_key])
|
| 61 |
+
else:
|
| 62 |
+
df = df.sort_values(case_id_glue)
|
| 63 |
+
df_reduced = df[[case_id_glue, activity_key]]
|
| 64 |
+
# shift the dataframe by 1
|
| 65 |
+
df_reduced_1 = df_reduced.shift(-1)
|
| 66 |
+
# shift the dataframe by 2
|
| 67 |
+
df_reduced_2 = df_reduced.shift(-2)
|
| 68 |
+
# change column names to shifted dataframe
|
| 69 |
+
df_reduced_1.columns = [str(col) + "_2" for col in df_reduced_1.columns]
|
| 70 |
+
df_reduced_2.columns = [str(col) + "_3" for col in df_reduced_2.columns]
|
| 71 |
+
|
| 72 |
+
df_successive_rows = pandas_utils.concat(
|
| 73 |
+
[df_reduced, df_reduced_1, df_reduced_2], axis=1
|
| 74 |
+
)
|
| 75 |
+
df_successive_rows = df_successive_rows[
|
| 76 |
+
df_successive_rows[case_id_glue]
|
| 77 |
+
== df_successive_rows[case_id_glue + "_2"]
|
| 78 |
+
]
|
| 79 |
+
df_successive_rows = df_successive_rows[
|
| 80 |
+
df_successive_rows[case_id_glue]
|
| 81 |
+
== df_successive_rows[case_id_glue + "_3"]
|
| 82 |
+
]
|
| 83 |
+
all_columns = set(df_successive_rows.columns)
|
| 84 |
+
all_columns = list(
|
| 85 |
+
all_columns
|
| 86 |
+
- set([activity_key, activity_key + "_2", activity_key + "_3"])
|
| 87 |
+
)
|
| 88 |
+
directly_follows_grouping = df_successive_rows.groupby(
|
| 89 |
+
[activity_key, activity_key + "_2", activity_key + "_3"]
|
| 90 |
+
)
|
| 91 |
+
if all_columns:
|
| 92 |
+
directly_follows_grouping = directly_follows_grouping[all_columns[0]]
|
| 93 |
+
freq_triples = directly_follows_grouping.size().to_dict()
|
| 94 |
+
return freq_triples
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/polars/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
|
| 23 |
+
from . import df_statistics, freq_triples
|
| 24 |
+
|
| 25 |
+
__all__ = [
|
| 26 |
+
"df_statistics",
|
| 27 |
+
"freq_triples",
|
| 28 |
+
]
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/polars/df_statistics.py
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
|
| 23 |
+
from typing import Dict, List, Optional, Tuple, Union
|
| 24 |
+
|
| 25 |
+
import polars as pl
|
| 26 |
+
|
| 27 |
+
from pm4py.util import constants, xes_constants
|
| 28 |
+
from pm4py.util.business_hours import soj_time_business_hours_diff
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _ensure_start_timestamp(
|
| 32 |
+
lf: pl.LazyFrame, start_timestamp_key: str, timestamp_key: str
|
| 33 |
+
) -> pl.LazyFrame:
|
| 34 |
+
schema_names = lf.collect_schema().names()
|
| 35 |
+
if start_timestamp_key not in schema_names:
|
| 36 |
+
lf = lf.with_columns(pl.col(timestamp_key).alias(start_timestamp_key))
|
| 37 |
+
return lf
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def _ensure_row_index(lf: pl.LazyFrame, column_name: str) -> pl.LazyFrame:
|
| 41 |
+
schema_names = lf.collect_schema().names()
|
| 42 |
+
if column_name in schema_names:
|
| 43 |
+
return lf
|
| 44 |
+
return lf.with_row_index(column_name)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def get_dfg_graph(
|
| 48 |
+
df: pl.LazyFrame,
|
| 49 |
+
measure: str = "frequency",
|
| 50 |
+
activity_key: str = "concept:name",
|
| 51 |
+
case_id_glue: str = "case:concept:name",
|
| 52 |
+
start_timestamp_key: Optional[str] = None,
|
| 53 |
+
timestamp_key: str = "time:timestamp",
|
| 54 |
+
perf_aggregation_key: str = "mean",
|
| 55 |
+
sort_caseid_required: bool = True,
|
| 56 |
+
sort_timestamp_along_case_id: bool = True,
|
| 57 |
+
keep_once_per_case: bool = False,
|
| 58 |
+
window: int = 1,
|
| 59 |
+
business_hours: bool = False,
|
| 60 |
+
business_hours_slot=None,
|
| 61 |
+
workcalendar=constants.DEFAULT_BUSINESS_HOURS_WORKCALENDAR,
|
| 62 |
+
target_activity_key: Optional[str] = None,
|
| 63 |
+
reduce_columns: bool = True,
|
| 64 |
+
cost_attribute: Optional[str] = None,
|
| 65 |
+
) -> Union[Dict[Tuple[str, str], int], Dict[Tuple[str, str], float], List[Dict]]:
|
| 66 |
+
"""Compute DFG statistics on a Polars LazyFrame."""
|
| 67 |
+
|
| 68 |
+
if target_activity_key is None:
|
| 69 |
+
target_activity_key = activity_key
|
| 70 |
+
|
| 71 |
+
if start_timestamp_key is None:
|
| 72 |
+
start_timestamp_key = xes_constants.DEFAULT_START_TIMESTAMP_KEY
|
| 73 |
+
|
| 74 |
+
schema_names = df.collect_schema().names()
|
| 75 |
+
st_eq_ct = start_timestamp_key == timestamp_key
|
| 76 |
+
|
| 77 |
+
if start_timestamp_key not in schema_names:
|
| 78 |
+
df = df.with_columns(pl.col(timestamp_key).alias(start_timestamp_key))
|
| 79 |
+
schema_names = df.collect_schema().names()
|
| 80 |
+
st_eq_ct = True
|
| 81 |
+
|
| 82 |
+
needed_columns = {case_id_glue, activity_key, target_activity_key}
|
| 83 |
+
if measure != "frequency" or sort_timestamp_along_case_id:
|
| 84 |
+
needed_columns.update({start_timestamp_key, timestamp_key})
|
| 85 |
+
if measure == "cost" and cost_attribute:
|
| 86 |
+
needed_columns.add(cost_attribute)
|
| 87 |
+
|
| 88 |
+
if reduce_columns:
|
| 89 |
+
available = [col for col in schema_names if col in needed_columns]
|
| 90 |
+
df = df.select([pl.col(col) for col in available])
|
| 91 |
+
schema_names = df.collect_schema().names()
|
| 92 |
+
|
| 93 |
+
if measure == "cost" and cost_attribute:
|
| 94 |
+
df = df.with_columns(pl.col(cost_attribute).fill_null(0))
|
| 95 |
+
schema_names = df.collect_schema().names()
|
| 96 |
+
|
| 97 |
+
if sort_caseid_required:
|
| 98 |
+
if sort_timestamp_along_case_id:
|
| 99 |
+
sort_cols = [case_id_glue]
|
| 100 |
+
if start_timestamp_key in schema_names:
|
| 101 |
+
sort_cols.append(start_timestamp_key)
|
| 102 |
+
if timestamp_key in schema_names:
|
| 103 |
+
sort_cols.append(timestamp_key)
|
| 104 |
+
df = df.sort(sort_cols, maintain_order=True)
|
| 105 |
+
else:
|
| 106 |
+
df = df.sort(case_id_glue, maintain_order=True)
|
| 107 |
+
|
| 108 |
+
suffix = "_2"
|
| 109 |
+
shift_exprs = [
|
| 110 |
+
pl.col(case_id_glue)
|
| 111 |
+
.shift(-window)
|
| 112 |
+
.over(case_id_glue)
|
| 113 |
+
.alias(case_id_glue + suffix),
|
| 114 |
+
pl.col(target_activity_key)
|
| 115 |
+
.shift(-window)
|
| 116 |
+
.over(case_id_glue)
|
| 117 |
+
.alias(target_activity_key + suffix),
|
| 118 |
+
]
|
| 119 |
+
|
| 120 |
+
if start_timestamp_key in schema_names or start_timestamp_key == timestamp_key:
|
| 121 |
+
shift_exprs.append(
|
| 122 |
+
pl.col(start_timestamp_key)
|
| 123 |
+
.shift(-window)
|
| 124 |
+
.over(case_id_glue)
|
| 125 |
+
.alias(start_timestamp_key + suffix)
|
| 126 |
+
)
|
| 127 |
+
if timestamp_key in schema_names:
|
| 128 |
+
shift_exprs.append(
|
| 129 |
+
pl.col(timestamp_key)
|
| 130 |
+
.shift(-window)
|
| 131 |
+
.over(case_id_glue)
|
| 132 |
+
.alias(timestamp_key + suffix)
|
| 133 |
+
)
|
| 134 |
+
if measure == "cost" and cost_attribute:
|
| 135 |
+
shift_exprs.append(
|
| 136 |
+
pl.col(cost_attribute)
|
| 137 |
+
.shift(-window)
|
| 138 |
+
.over(case_id_glue)
|
| 139 |
+
.alias(cost_attribute + suffix)
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
pairs = df.with_columns(shift_exprs)
|
| 143 |
+
pairs = pairs.filter(pl.col(case_id_glue + suffix).is_not_null())
|
| 144 |
+
pairs = pairs.filter(pl.col(target_activity_key + suffix).is_not_null())
|
| 145 |
+
|
| 146 |
+
if keep_once_per_case:
|
| 147 |
+
pairs = pairs.unique(
|
| 148 |
+
subset=[case_id_glue, activity_key, target_activity_key + suffix],
|
| 149 |
+
keep="first",
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
if measure in {"performance", "both", "cost"}:
|
| 153 |
+
if not st_eq_ct:
|
| 154 |
+
pairs = pairs.with_columns(
|
| 155 |
+
pl.max_horizontal(
|
| 156 |
+
[pl.col(start_timestamp_key + suffix), pl.col(timestamp_key)]
|
| 157 |
+
).alias(start_timestamp_key + suffix)
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
if business_hours:
|
| 161 |
+
if business_hours_slot is None:
|
| 162 |
+
business_hours_slot = constants.DEFAULT_BUSINESS_HOUR_SLOTS
|
| 163 |
+
pairs = pairs.with_columns(
|
| 164 |
+
pl.struct(
|
| 165 |
+
[pl.col(timestamp_key), pl.col(start_timestamp_key + suffix)]
|
| 166 |
+
)
|
| 167 |
+
.map_elements(
|
| 168 |
+
lambda row: soj_time_business_hours_diff(
|
| 169 |
+
row[timestamp_key],
|
| 170 |
+
row[start_timestamp_key + suffix],
|
| 171 |
+
business_hours_slot,
|
| 172 |
+
workcalendar,
|
| 173 |
+
),
|
| 174 |
+
return_dtype=pl.Float64,
|
| 175 |
+
)
|
| 176 |
+
.alias(constants.DEFAULT_FLOW_TIME)
|
| 177 |
+
)
|
| 178 |
+
else:
|
| 179 |
+
pairs = pairs.with_columns(
|
| 180 |
+
(
|
| 181 |
+
pl.col(start_timestamp_key + suffix) - pl.col(timestamp_key)
|
| 182 |
+
)
|
| 183 |
+
.dt.total_seconds()
|
| 184 |
+
.alias(constants.DEFAULT_FLOW_TIME)
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
group_cols = [activity_key, target_activity_key + suffix]
|
| 188 |
+
|
| 189 |
+
freq_dict: Dict[Tuple[str, str], int] = {}
|
| 190 |
+
perf_dict: Dict[Tuple[str, str], Union[float, Dict[str, float], List[float]]] = {}
|
| 191 |
+
|
| 192 |
+
if measure in {"frequency", "both"}:
|
| 193 |
+
freq_df = (
|
| 194 |
+
pairs.group_by(group_cols)
|
| 195 |
+
.agg(pl.len().alias("count"))
|
| 196 |
+
.collect()
|
| 197 |
+
)
|
| 198 |
+
freq_dict = {
|
| 199 |
+
(row[group_cols[0]], row[group_cols[1]]): row["count"]
|
| 200 |
+
for row in freq_df.iter_rows(named=True)
|
| 201 |
+
if row[group_cols[0]] is not None and row[group_cols[1]] is not None
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
if measure in {"performance", "both", "cost"}:
|
| 205 |
+
if measure == "cost" and cost_attribute:
|
| 206 |
+
value_expr = pl.col(cost_attribute + suffix)
|
| 207 |
+
else:
|
| 208 |
+
value_expr = pl.col(constants.DEFAULT_FLOW_TIME)
|
| 209 |
+
|
| 210 |
+
if perf_aggregation_key == "all":
|
| 211 |
+
agg_exprs = [
|
| 212 |
+
value_expr.mean().alias("mean"),
|
| 213 |
+
value_expr.median().alias("median"),
|
| 214 |
+
value_expr.max().alias("max"),
|
| 215 |
+
value_expr.min().alias("min"),
|
| 216 |
+
value_expr.sum().alias("sum"),
|
| 217 |
+
value_expr.std().alias("stdev"),
|
| 218 |
+
]
|
| 219 |
+
perf_df = pairs.group_by(group_cols).agg(agg_exprs).collect()
|
| 220 |
+
perf_dict = {
|
| 221 |
+
(row[group_cols[0]], row[group_cols[1]]): {
|
| 222 |
+
"mean": row["mean"],
|
| 223 |
+
"median": row["median"],
|
| 224 |
+
"max": row["max"],
|
| 225 |
+
"min": row["min"],
|
| 226 |
+
"sum": row["sum"],
|
| 227 |
+
"stdev": row["stdev"],
|
| 228 |
+
}
|
| 229 |
+
for row in perf_df.iter_rows(named=True)
|
| 230 |
+
}
|
| 231 |
+
elif perf_aggregation_key == "raw_values":
|
| 232 |
+
perf_df = (
|
| 233 |
+
pairs.group_by(group_cols)
|
| 234 |
+
.agg(value_expr.implode().alias("raw_values"))
|
| 235 |
+
.collect()
|
| 236 |
+
)
|
| 237 |
+
perf_dict = {
|
| 238 |
+
(row[group_cols[0]], row[group_cols[1]]): row["raw_values"]
|
| 239 |
+
for row in perf_df.iter_rows(named=True)
|
| 240 |
+
}
|
| 241 |
+
else:
|
| 242 |
+
if not hasattr(pl.Expr, perf_aggregation_key):
|
| 243 |
+
raise ValueError(
|
| 244 |
+
f"Unsupported aggregation key: {perf_aggregation_key}"
|
| 245 |
+
)
|
| 246 |
+
agg_expr = getattr(value_expr, perf_aggregation_key)().alias(
|
| 247 |
+
perf_aggregation_key
|
| 248 |
+
)
|
| 249 |
+
perf_df = (
|
| 250 |
+
pairs.group_by(group_cols).agg(agg_expr).collect()
|
| 251 |
+
)
|
| 252 |
+
perf_dict = {
|
| 253 |
+
(row[group_cols[0]], row[group_cols[1]]): row[perf_aggregation_key]
|
| 254 |
+
for row in perf_df.iter_rows(named=True)
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
if measure == "frequency":
|
| 258 |
+
return freq_dict
|
| 259 |
+
if measure in {"performance", "cost"}:
|
| 260 |
+
return perf_dict
|
| 261 |
+
return [freq_dict, perf_dict]
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
def get_partial_order_dataframe(
|
| 265 |
+
df: pl.LazyFrame,
|
| 266 |
+
start_timestamp_key: Optional[str] = None,
|
| 267 |
+
timestamp_key: str = "time:timestamp",
|
| 268 |
+
case_id_glue: str = "case:concept:name",
|
| 269 |
+
activity_key: str = "concept:name",
|
| 270 |
+
sort_caseid_required: bool = True,
|
| 271 |
+
sort_timestamp_along_case_id: bool = True,
|
| 272 |
+
reduce_dataframe: bool = True,
|
| 273 |
+
keep_first_following: bool = True,
|
| 274 |
+
business_hours: bool = False,
|
| 275 |
+
business_hours_slot=None,
|
| 276 |
+
workcalendar=constants.DEFAULT_BUSINESS_HOURS_WORKCALENDAR,
|
| 277 |
+
event_index: str = constants.DEFAULT_INDEX_KEY,
|
| 278 |
+
) -> pl.LazyFrame:
|
| 279 |
+
"""Compute partial order dataframe using Polars."""
|
| 280 |
+
|
| 281 |
+
if start_timestamp_key is None:
|
| 282 |
+
start_timestamp_key = xes_constants.DEFAULT_START_TIMESTAMP_KEY
|
| 283 |
+
|
| 284 |
+
df = _ensure_start_timestamp(df, start_timestamp_key, timestamp_key)
|
| 285 |
+
|
| 286 |
+
if reduce_dataframe:
|
| 287 |
+
schema_names = df.collect_schema().names()
|
| 288 |
+
columns = {
|
| 289 |
+
case_id_glue,
|
| 290 |
+
activity_key,
|
| 291 |
+
start_timestamp_key,
|
| 292 |
+
timestamp_key,
|
| 293 |
+
}
|
| 294 |
+
if event_index in schema_names:
|
| 295 |
+
columns.add(event_index)
|
| 296 |
+
df = df.select([pl.col(col) for col in schema_names if col in columns])
|
| 297 |
+
|
| 298 |
+
if sort_caseid_required:
|
| 299 |
+
if sort_timestamp_along_case_id:
|
| 300 |
+
df = df.sort([case_id_glue, start_timestamp_key, timestamp_key], maintain_order=True)
|
| 301 |
+
else:
|
| 302 |
+
df = df.sort(case_id_glue, maintain_order=True)
|
| 303 |
+
|
| 304 |
+
df = _ensure_row_index(df, event_index)
|
| 305 |
+
|
| 306 |
+
joined = df.join(df, on=case_id_glue, how="inner", suffix="_2", maintain_order="left")
|
| 307 |
+
joined = joined.filter(
|
| 308 |
+
pl.col(event_index) < pl.col(event_index + "_2")
|
| 309 |
+
)
|
| 310 |
+
joined = joined.filter(
|
| 311 |
+
pl.col(timestamp_key) <= pl.col(start_timestamp_key + "_2")
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
if business_hours:
|
| 315 |
+
if business_hours_slot is None:
|
| 316 |
+
business_hours_slot = constants.DEFAULT_BUSINESS_HOUR_SLOTS
|
| 317 |
+
joined = joined.with_columns(
|
| 318 |
+
pl.struct(
|
| 319 |
+
[pl.col(timestamp_key), pl.col(start_timestamp_key + "_2")]
|
| 320 |
+
)
|
| 321 |
+
.map_elements(
|
| 322 |
+
lambda row: soj_time_business_hours_diff(
|
| 323 |
+
row[timestamp_key],
|
| 324 |
+
row[start_timestamp_key + "_2"],
|
| 325 |
+
business_hours_slot,
|
| 326 |
+
workcalendar,
|
| 327 |
+
),
|
| 328 |
+
return_dtype=pl.Float64,
|
| 329 |
+
)
|
| 330 |
+
.alias(constants.DEFAULT_FLOW_TIME)
|
| 331 |
+
)
|
| 332 |
+
else:
|
| 333 |
+
joined = joined.with_columns(
|
| 334 |
+
(
|
| 335 |
+
pl.col(start_timestamp_key + "_2") - pl.col(timestamp_key)
|
| 336 |
+
)
|
| 337 |
+
.dt.total_seconds()
|
| 338 |
+
.alias(constants.DEFAULT_FLOW_TIME)
|
| 339 |
+
)
|
| 340 |
+
|
| 341 |
+
if keep_first_following:
|
| 342 |
+
joined = joined.sort([case_id_glue, event_index, event_index + "_2"], maintain_order=True)
|
| 343 |
+
joined = joined.unique(
|
| 344 |
+
subset=[event_index], keep="first", maintain_order=True
|
| 345 |
+
)
|
| 346 |
+
|
| 347 |
+
return joined
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
def get_concurrent_events_dataframe(
|
| 351 |
+
df: pl.LazyFrame,
|
| 352 |
+
start_timestamp_key: Optional[str] = None,
|
| 353 |
+
timestamp_key: str = "time:timestamp",
|
| 354 |
+
case_id_glue: str = "case:concept:name",
|
| 355 |
+
activity_key: str = "concept:name",
|
| 356 |
+
sort_caseid_required: bool = True,
|
| 357 |
+
sort_timestamp_along_case_id: bool = True,
|
| 358 |
+
reduce_dataframe: bool = True,
|
| 359 |
+
max_start_column: str = "@@max_start_column",
|
| 360 |
+
min_complete_column: str = "@@min_complete_column",
|
| 361 |
+
diff_maxs_minc: str = "@@diff_maxs_minc",
|
| 362 |
+
strict: bool = False,
|
| 363 |
+
) -> pl.LazyFrame:
|
| 364 |
+
"""Compute concurrency dataframe using Polars."""
|
| 365 |
+
|
| 366 |
+
if start_timestamp_key is None:
|
| 367 |
+
start_timestamp_key = xes_constants.DEFAULT_START_TIMESTAMP_KEY
|
| 368 |
+
|
| 369 |
+
df = _ensure_start_timestamp(df, start_timestamp_key, timestamp_key)
|
| 370 |
+
|
| 371 |
+
if reduce_dataframe:
|
| 372 |
+
columns = [case_id_glue, activity_key, start_timestamp_key, timestamp_key]
|
| 373 |
+
df = df.select([pl.col(col) for col in df.schema if col in columns])
|
| 374 |
+
|
| 375 |
+
if sort_caseid_required:
|
| 376 |
+
if sort_timestamp_along_case_id:
|
| 377 |
+
df = df.sort([case_id_glue, start_timestamp_key, timestamp_key], maintain_order=True)
|
| 378 |
+
else:
|
| 379 |
+
df = df.sort(case_id_glue, maintain_order=True)
|
| 380 |
+
|
| 381 |
+
df = _ensure_row_index(df, constants.DEFAULT_INDEX_KEY)
|
| 382 |
+
|
| 383 |
+
joined = df.join(df, on=case_id_glue, how="inner", suffix="_2", maintain_order="left")
|
| 384 |
+
joined = joined.filter(
|
| 385 |
+
pl.col(constants.DEFAULT_INDEX_KEY)
|
| 386 |
+
< pl.col(constants.DEFAULT_INDEX_KEY + "_2")
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
joined = joined.filter(
|
| 390 |
+
pl.col(timestamp_key)
|
| 391 |
+
<= pl.col(start_timestamp_key + "_2")
|
| 392 |
+
)
|
| 393 |
+
|
| 394 |
+
joined = joined.with_columns([
|
| 395 |
+
pl.max_horizontal(
|
| 396 |
+
[pl.col(start_timestamp_key), pl.col(start_timestamp_key + "_2")]
|
| 397 |
+
).alias(max_start_column),
|
| 398 |
+
pl.min_horizontal([pl.col(timestamp_key), pl.col(timestamp_key + "_2")]).alias(
|
| 399 |
+
min_complete_column
|
| 400 |
+
),
|
| 401 |
+
])
|
| 402 |
+
|
| 403 |
+
joined = joined.with_columns(
|
| 404 |
+
(
|
| 405 |
+
pl.col(min_complete_column) - pl.col(max_start_column)
|
| 406 |
+
)
|
| 407 |
+
.dt.total_seconds()
|
| 408 |
+
.alias(diff_maxs_minc)
|
| 409 |
+
)
|
| 410 |
+
|
| 411 |
+
if strict:
|
| 412 |
+
joined = joined.filter(pl.col(diff_maxs_minc) > 0)
|
| 413 |
+
else:
|
| 414 |
+
joined = joined.filter(pl.col(diff_maxs_minc) >= 0)
|
| 415 |
+
|
| 416 |
+
return joined.drop(constants.DEFAULT_INDEX_KEY + "_2")
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/adapters/polars/freq_triples.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
|
| 23 |
+
from typing import Dict, Tuple
|
| 24 |
+
|
| 25 |
+
import polars as pl
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def get_freq_triples(
|
| 29 |
+
df: pl.LazyFrame,
|
| 30 |
+
activity_key: str = "concept:name",
|
| 31 |
+
case_id_glue: str = "case:concept:name",
|
| 32 |
+
timestamp_key: str = "time:timestamp",
|
| 33 |
+
sort_caseid_required: bool = True,
|
| 34 |
+
sort_timestamp_along_case_id: bool = True,
|
| 35 |
+
) -> Dict[Tuple[str, str, str], int]:
|
| 36 |
+
"""Compute frequency triples directly on a Polars LazyFrame."""
|
| 37 |
+
|
| 38 |
+
if sort_caseid_required:
|
| 39 |
+
if sort_timestamp_along_case_id:
|
| 40 |
+
df = df.sort([case_id_glue, timestamp_key], maintain_order=True)
|
| 41 |
+
else:
|
| 42 |
+
df = df.sort(case_id_glue, maintain_order=True)
|
| 43 |
+
|
| 44 |
+
triples = df.with_columns(
|
| 45 |
+
[
|
| 46 |
+
pl.col(activity_key)
|
| 47 |
+
.shift(-1)
|
| 48 |
+
.over(case_id_glue)
|
| 49 |
+
.alias(activity_key + "_2"),
|
| 50 |
+
pl.col(activity_key)
|
| 51 |
+
.shift(-2)
|
| 52 |
+
.over(case_id_glue)
|
| 53 |
+
.alias(activity_key + "_3"),
|
| 54 |
+
]
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
triples = triples.filter(
|
| 58 |
+
pl.col(activity_key + "_2").is_not_null()
|
| 59 |
+
& pl.col(activity_key + "_3").is_not_null()
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
grouped = (
|
| 63 |
+
triples.group_by(
|
| 64 |
+
[activity_key, activity_key + "_2", activity_key + "_3"]
|
| 65 |
+
)
|
| 66 |
+
.agg(pl.len().alias("count"))
|
| 67 |
+
.collect()
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
return {
|
| 71 |
+
(
|
| 72 |
+
row[activity_key],
|
| 73 |
+
row[activity_key + "_2"],
|
| 74 |
+
row[activity_key + "_3"],
|
| 75 |
+
): row["count"]
|
| 76 |
+
for row in grouped.iter_rows(named=True)
|
| 77 |
+
}
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/algorithm.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
|
| 23 |
+
from pm4py import util as pmutil
|
| 24 |
+
from pm4py.algo.discovery.dfg.variants import (
|
| 25 |
+
native,
|
| 26 |
+
performance,
|
| 27 |
+
freq_triples,
|
| 28 |
+
case_attributes,
|
| 29 |
+
clean,
|
| 30 |
+
)
|
| 31 |
+
from pm4py.objects.conversion.log import converter as log_conversion
|
| 32 |
+
from pm4py.util import xes_constants as xes_util
|
| 33 |
+
from pm4py.util import exec_utils
|
| 34 |
+
from pm4py.util import constants, pandas_utils
|
| 35 |
+
from enum import Enum
|
| 36 |
+
from typing import Optional, Dict, Any, Union, Tuple
|
| 37 |
+
from pm4py.objects.log.obj import EventLog, EventStream
|
| 38 |
+
from pm4py.algo.discovery.dfg.adapters.pandas import df_statistics
|
| 39 |
+
import pandas as pd
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class Parameters(Enum):
|
| 43 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 44 |
+
START_TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY
|
| 45 |
+
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
|
| 46 |
+
CASE_ID_KEY = constants.PARAMETER_CONSTANT_CASEID_KEY
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class Variants(Enum):
|
| 50 |
+
NATIVE = native
|
| 51 |
+
FREQUENCY = native
|
| 52 |
+
PERFORMANCE = performance
|
| 53 |
+
FREQUENCY_GREEDY = native
|
| 54 |
+
PERFORMANCE_GREEDY = performance
|
| 55 |
+
FREQ_TRIPLES = freq_triples
|
| 56 |
+
CASE_ATTRIBUTES = case_attributes
|
| 57 |
+
CLEAN = clean # 'novel' replacement for native
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
DFG_NATIVE = Variants.NATIVE
|
| 61 |
+
DFG_FREQUENCY = Variants.FREQUENCY
|
| 62 |
+
DFG_PERFORMANCE = Variants.PERFORMANCE
|
| 63 |
+
DFG_FREQUENCY_GREEDY = Variants.FREQUENCY_GREEDY
|
| 64 |
+
DFG_PERFORMANCE_GREEDY = Variants.PERFORMANCE_GREEDY
|
| 65 |
+
FREQ_TRIPLES = Variants.FREQ_TRIPLES
|
| 66 |
+
DFG_CLEAN = Variants.CLEAN
|
| 67 |
+
|
| 68 |
+
DEFAULT_VARIANT = Variants.NATIVE
|
| 69 |
+
|
| 70 |
+
VERSIONS = {
|
| 71 |
+
DFG_NATIVE,
|
| 72 |
+
DFG_FREQUENCY,
|
| 73 |
+
DFG_PERFORMANCE,
|
| 74 |
+
DFG_FREQUENCY_GREEDY,
|
| 75 |
+
DFG_PERFORMANCE_GREEDY,
|
| 76 |
+
FREQ_TRIPLES,
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def apply(
|
| 81 |
+
log: Union[EventLog, EventStream, pd.DataFrame],
|
| 82 |
+
parameters: Optional[Dict[Any, Any]] = None,
|
| 83 |
+
variant=DEFAULT_VARIANT,
|
| 84 |
+
) -> Dict[Tuple[str, str], float]:
|
| 85 |
+
"""
|
| 86 |
+
Calculates DFG graph (frequency or performance) starting from a log
|
| 87 |
+
|
| 88 |
+
Parameters
|
| 89 |
+
----------
|
| 90 |
+
log
|
| 91 |
+
Log
|
| 92 |
+
parameters
|
| 93 |
+
Possible parameters passed to the algorithms:
|
| 94 |
+
Parameters.AGGREGATION_MEASURE -> performance aggregation measure (min, max, mean, median)
|
| 95 |
+
Parameters.ACTIVITY_KEY -> Attribute to use as activity
|
| 96 |
+
Parameters.TIMESTAMP_KEY -> Attribute to use as timestamp
|
| 97 |
+
variant
|
| 98 |
+
Variant of the algorithm to use, possible values:
|
| 99 |
+
- Variants.NATIVE
|
| 100 |
+
- Variants.FREQUENCY
|
| 101 |
+
- Variants.FREQUENCY_GREEDY
|
| 102 |
+
- Variants.PERFORMANCE
|
| 103 |
+
- Variants.PERFORMANCE_GREEDY
|
| 104 |
+
- Variants.FREQ_TRIPLES
|
| 105 |
+
|
| 106 |
+
Returns
|
| 107 |
+
-------
|
| 108 |
+
dfg: dict
|
| 109 |
+
DFG graph
|
| 110 |
+
"""
|
| 111 |
+
if variant == Variants.CLEAN and pandas_utils.check_is_pandas_dataframe(
|
| 112 |
+
log
|
| 113 |
+
):
|
| 114 |
+
return clean.apply(log, parameters)
|
| 115 |
+
elif variant is None:
|
| 116 |
+
variant = Variants.NATIVE
|
| 117 |
+
|
| 118 |
+
if parameters is None:
|
| 119 |
+
parameters = {}
|
| 120 |
+
activity_key = exec_utils.get_param_value(
|
| 121 |
+
Parameters.ACTIVITY_KEY, parameters, xes_util.DEFAULT_NAME_KEY
|
| 122 |
+
)
|
| 123 |
+
start_timestamp_key = exec_utils.get_param_value(
|
| 124 |
+
Parameters.START_TIMESTAMP_KEY, parameters, None
|
| 125 |
+
)
|
| 126 |
+
timestamp_key = exec_utils.get_param_value(
|
| 127 |
+
Parameters.TIMESTAMP_KEY, parameters, xes_util.DEFAULT_TIMESTAMP_KEY
|
| 128 |
+
)
|
| 129 |
+
case_id_glue = exec_utils.get_param_value(
|
| 130 |
+
Parameters.CASE_ID_KEY, parameters, pmutil.constants.CASE_CONCEPT_NAME
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
if (
|
| 134 |
+
pandas_utils.check_is_pandas_dataframe(log)
|
| 135 |
+
and not variant == Variants.FREQ_TRIPLES
|
| 136 |
+
):
|
| 137 |
+
dfg_frequency, dfg_performance = df_statistics.get_dfg_graph(
|
| 138 |
+
log,
|
| 139 |
+
measure="both",
|
| 140 |
+
activity_key=activity_key,
|
| 141 |
+
timestamp_key=timestamp_key,
|
| 142 |
+
case_id_glue=case_id_glue,
|
| 143 |
+
start_timestamp_key=start_timestamp_key,
|
| 144 |
+
)
|
| 145 |
+
if variant in [Variants.PERFORMANCE, Variants.PERFORMANCE_GREEDY]:
|
| 146 |
+
return dfg_performance
|
| 147 |
+
else:
|
| 148 |
+
return dfg_frequency
|
| 149 |
+
|
| 150 |
+
return exec_utils.get_variant(variant).apply(
|
| 151 |
+
log_conversion.apply(log, parameters, log_conversion.TO_EVENT_LOG),
|
| 152 |
+
parameters=parameters,
|
| 153 |
+
)
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/replacement.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
def replace_values(dfg1, dfg2):
|
| 23 |
+
"""
|
| 24 |
+
Replace edge values specified in a DFG by values from a (potentially bigger) DFG
|
| 25 |
+
|
| 26 |
+
Parameters
|
| 27 |
+
-----------
|
| 28 |
+
dfg1
|
| 29 |
+
First specified DFG (where values of edges should be replaces)
|
| 30 |
+
dfg2
|
| 31 |
+
Second specified DFG (from which values should be taken)
|
| 32 |
+
|
| 33 |
+
Returns
|
| 34 |
+
-----------
|
| 35 |
+
dfg1
|
| 36 |
+
First specified DFG with overrided values
|
| 37 |
+
"""
|
| 38 |
+
for edge in dfg1:
|
| 39 |
+
if edge in dfg2:
|
| 40 |
+
dfg1[edge] = dfg2[edge]
|
| 41 |
+
return dfg1
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/utils/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.dfg.utils import dfg_utils
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/utils/dfg_utils.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.objects.dfg.utils.dfg_utils import *
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/__init__.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.dfg.variants import (
|
| 23 |
+
native,
|
| 24 |
+
performance,
|
| 25 |
+
freq_triples,
|
| 26 |
+
case_attributes,
|
| 27 |
+
clean,
|
| 28 |
+
)
|
| 29 |
+
import importlib.util
|
| 30 |
+
|
| 31 |
+
if importlib.util.find_spec("polars"):
|
| 32 |
+
from pm4py.algo.discovery.dfg.variants import clean_polars
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/case_attributes.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from enum import Enum
|
| 23 |
+
from typing import Optional, Dict, Any, Tuple, Union
|
| 24 |
+
|
| 25 |
+
from pm4py.objects.conversion.log import converter as log_converter
|
| 26 |
+
from pm4py.objects.log.obj import EventLog
|
| 27 |
+
from pm4py.util import exec_utils, constants, xes_constants
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class Parameters(Enum):
|
| 31 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 32 |
+
CASE_ATTRIBUTES = "case_attributes"
|
| 33 |
+
RETURN_NODES_ATTRIBUTES = "return_nodes_attributes"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def apply(
|
| 37 |
+
log: EventLog,
|
| 38 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 39 |
+
) -> Union[
|
| 40 |
+
Tuple[
|
| 41 |
+
Dict[Tuple[str, str], Dict[str, Dict[str, Any]]],
|
| 42 |
+
Dict[str, Dict[str, Dict[str, Any]]],
|
| 43 |
+
],
|
| 44 |
+
Dict[Tuple[str, str], Dict[str, Dict[str, Any]]],
|
| 45 |
+
]:
|
| 46 |
+
"""
|
| 47 |
+
Discovers a directly-follows graph from an event log, with the edges that are annotated with the different values
|
| 48 |
+
for the given case attributes.
|
| 49 |
+
|
| 50 |
+
Parameters
|
| 51 |
+
-----------------
|
| 52 |
+
log
|
| 53 |
+
Event log
|
| 54 |
+
parameters
|
| 55 |
+
Parameters of the variant, including:
|
| 56 |
+
- Parameters.ACTIVITY_KEY => the attribute to use as activity
|
| 57 |
+
- Parameters.CASE_ATTRIBUTES => the case attributes that are used to annotate the edges (default: the case ID)
|
| 58 |
+
- Parameters.RETURN_NODES_ATTRIBUTES => (optional) returns also a dictionary with the values of the
|
| 59 |
+
attributes for each activity of the graph (default: False)
|
| 60 |
+
|
| 61 |
+
Returns
|
| 62 |
+
-----------------
|
| 63 |
+
dfg
|
| 64 |
+
Directly-follows graph (with the edges annotated with the specified case attributes), e.g.:
|
| 65 |
+
{('register request', 'examine casually'): {'creator': {'Fluxicon Nitro': 3}, 'concept:name':
|
| 66 |
+
{'3': 1, '6': 1, '5': 1}} ...
|
| 67 |
+
nodes
|
| 68 |
+
(Optional) dictionary of activities (annotated with the specified case attributes), e.g.:
|
| 69 |
+
{'register request': {'creator': {'Fluxicon Nitro': 6}, 'concept:name':
|
| 70 |
+
{'3': 1, '2': 1, '1': 1, '6': 1, '5': 1, '4': 1}} ...
|
| 71 |
+
"""
|
| 72 |
+
if parameters is None:
|
| 73 |
+
parameters = {}
|
| 74 |
+
|
| 75 |
+
log = log_converter.apply(
|
| 76 |
+
log, variant=log_converter.Variants.TO_EVENT_LOG, parameters=parameters
|
| 77 |
+
)
|
| 78 |
+
activity_key = exec_utils.get_param_value(
|
| 79 |
+
Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY
|
| 80 |
+
)
|
| 81 |
+
case_attributes = exec_utils.get_param_value(
|
| 82 |
+
Parameters.CASE_ATTRIBUTES,
|
| 83 |
+
parameters,
|
| 84 |
+
list([xes_constants.DEFAULT_TRACEID_KEY]),
|
| 85 |
+
)
|
| 86 |
+
return_nodes_attributes = exec_utils.get_param_value(
|
| 87 |
+
Parameters.RETURN_NODES_ATTRIBUTES, parameters, False
|
| 88 |
+
)
|
| 89 |
+
dfg = {}
|
| 90 |
+
|
| 91 |
+
for trace in log:
|
| 92 |
+
for attr in set(case_attributes).intersection(set(trace.attributes)):
|
| 93 |
+
attr_value = trace.attributes[attr]
|
| 94 |
+
for i in range(len(trace) - 1):
|
| 95 |
+
ev_couple = (
|
| 96 |
+
trace[i][activity_key],
|
| 97 |
+
trace[i + 1][activity_key],
|
| 98 |
+
)
|
| 99 |
+
if ev_couple not in dfg:
|
| 100 |
+
dfg[ev_couple] = {}
|
| 101 |
+
if attr not in dfg[ev_couple]:
|
| 102 |
+
dfg[ev_couple][attr] = {}
|
| 103 |
+
if attr_value not in dfg[ev_couple][attr]:
|
| 104 |
+
dfg[ev_couple][attr][attr_value] = 0
|
| 105 |
+
dfg[ev_couple][attr][attr_value] += 1
|
| 106 |
+
|
| 107 |
+
if return_nodes_attributes:
|
| 108 |
+
nodes = {}
|
| 109 |
+
for trace in log:
|
| 110 |
+
for attr in set(case_attributes).intersection(
|
| 111 |
+
set(trace.attributes)
|
| 112 |
+
):
|
| 113 |
+
attr_value = trace.attributes[attr]
|
| 114 |
+
for i in range(len(trace)):
|
| 115 |
+
act = trace[i][activity_key]
|
| 116 |
+
if act not in nodes:
|
| 117 |
+
nodes[act] = {}
|
| 118 |
+
if attr not in nodes[act]:
|
| 119 |
+
nodes[act][attr] = {}
|
| 120 |
+
if attr_value not in nodes[act][attr]:
|
| 121 |
+
nodes[act][attr][attr_value] = 0
|
| 122 |
+
nodes[act][attr][attr_value] += 1
|
| 123 |
+
|
| 124 |
+
return dfg, nodes
|
| 125 |
+
|
| 126 |
+
return dfg
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/clean.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
import time
|
| 23 |
+
from enum import Enum
|
| 24 |
+
from typing import Optional, Dict, Any
|
| 25 |
+
|
| 26 |
+
import numpy as np
|
| 27 |
+
import pandas as pd
|
| 28 |
+
|
| 29 |
+
from pm4py.objects.dfg.obj import DFG
|
| 30 |
+
from pm4py.util import constants, exec_utils
|
| 31 |
+
from pm4py.util import xes_constants as xes_util
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class Parameters(Enum):
|
| 35 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 36 |
+
CASE_ID_KEY = constants.PARAMETER_CONSTANT_CASEID_KEY
|
| 37 |
+
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
CONST_AUX_ACT_START = "aux_act_start"
|
| 41 |
+
CONST_PROCESS_START = "#!$#PROCESS_START#!$#"
|
| 42 |
+
CONST_AUX_ACT_END = "aux_act_end"
|
| 43 |
+
CONST_PROCESS_END = "#!$#PROCESS_END#!$#"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def apply(
|
| 47 |
+
log: pd.DataFrame, parameters: Optional[Dict[str, Any]] = None
|
| 48 |
+
) -> DFG:
|
| 49 |
+
parameters = {} if parameters is None else parameters
|
| 50 |
+
act_key = exec_utils.get_param_value(
|
| 51 |
+
Parameters.ACTIVITY_KEY, parameters, xes_util.DEFAULT_NAME_KEY
|
| 52 |
+
)
|
| 53 |
+
cid_key = exec_utils.get_param_value(
|
| 54 |
+
Parameters.CASE_ID_KEY, parameters, constants.CASE_ATTRIBUTE_GLUE
|
| 55 |
+
)
|
| 56 |
+
time_key = exec_utils.get_param_value(
|
| 57 |
+
Parameters.TIMESTAMP_KEY, parameters, xes_util.DEFAULT_TIMESTAMP_KEY
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
df = (
|
| 61 |
+
log.sort_values([cid_key, time_key])
|
| 62 |
+
.loc[:, [cid_key, act_key]]
|
| 63 |
+
.reset_index()
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
aux_act_start = CONST_AUX_ACT_START + str(time.time())
|
| 67 |
+
aux_act_end = CONST_AUX_ACT_END + str(time.time())
|
| 68 |
+
df[aux_act_start] = (
|
| 69 |
+
df.groupby(cid_key)[act_key]
|
| 70 |
+
.shift(1)
|
| 71 |
+
.replace(np.nan, CONST_PROCESS_START)
|
| 72 |
+
)
|
| 73 |
+
df[aux_act_end] = (
|
| 74 |
+
df.groupby(cid_key)[act_key]
|
| 75 |
+
.shift(-1)
|
| 76 |
+
.replace(np.nan, CONST_PROCESS_END)
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
starters = df[(df[aux_act_start] == CONST_PROCESS_START)]
|
| 80 |
+
borders = df[(df[aux_act_end] == CONST_PROCESS_END)]
|
| 81 |
+
connections = df[
|
| 82 |
+
(
|
| 83 |
+
(df[aux_act_start] != CONST_PROCESS_START)
|
| 84 |
+
& (df[aux_act_end] != CONST_PROCESS_END)
|
| 85 |
+
)
|
| 86 |
+
]
|
| 87 |
+
|
| 88 |
+
dfg = DFG()
|
| 89 |
+
|
| 90 |
+
for a, b, f in list(
|
| 91 |
+
connections.groupby([act_key, aux_act_end])
|
| 92 |
+
.size()
|
| 93 |
+
.reset_index()
|
| 94 |
+
.itertuples(index=False, name=None)
|
| 95 |
+
):
|
| 96 |
+
dfg.graph[(a, b)] += f
|
| 97 |
+
|
| 98 |
+
for a, f in list(
|
| 99 |
+
starters.groupby([act_key])
|
| 100 |
+
.size()
|
| 101 |
+
.reset_index()
|
| 102 |
+
.itertuples(index=False, name=None)
|
| 103 |
+
):
|
| 104 |
+
dfg.start_activities[a] += f
|
| 105 |
+
|
| 106 |
+
for a, f in list(
|
| 107 |
+
borders.groupby([act_key])
|
| 108 |
+
.size()
|
| 109 |
+
.reset_index()
|
| 110 |
+
.itertuples(index=False, name=None)
|
| 111 |
+
):
|
| 112 |
+
dfg.end_activities[a] += f
|
| 113 |
+
|
| 114 |
+
return dfg
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/clean_polars.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
import time
|
| 23 |
+
from enum import Enum
|
| 24 |
+
from typing import Optional, Dict, Any, Union
|
| 25 |
+
|
| 26 |
+
import polars as pl
|
| 27 |
+
|
| 28 |
+
from pm4py.objects.dfg.obj import DFG
|
| 29 |
+
from pm4py.util import constants, exec_utils
|
| 30 |
+
from pm4py.util import xes_constants as xes_util
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class Parameters(Enum):
|
| 34 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 35 |
+
CASE_ID_KEY = constants.PARAMETER_CONSTANT_CASEID_KEY
|
| 36 |
+
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
CONST_AUX_ACT = "aux_act_"
|
| 40 |
+
CONST_AUX_CASE = "aux_case_"
|
| 41 |
+
CONST_COUNT = "count_"
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def apply(
|
| 45 |
+
log: Union[pl.DataFrame, pl.LazyFrame], parameters: Optional[Dict[str, Any]] = None
|
| 46 |
+
) -> DFG:
|
| 47 |
+
parameters = {} if parameters is None else parameters
|
| 48 |
+
act_key = exec_utils.get_param_value(
|
| 49 |
+
Parameters.ACTIVITY_KEY, parameters, xes_util.DEFAULT_NAME_KEY
|
| 50 |
+
)
|
| 51 |
+
cid_key = exec_utils.get_param_value(
|
| 52 |
+
Parameters.CASE_ID_KEY, parameters, constants.CASE_ATTRIBUTE_GLUE
|
| 53 |
+
)
|
| 54 |
+
time_key = exec_utils.get_param_value(
|
| 55 |
+
Parameters.TIMESTAMP_KEY, parameters, xes_util.DEFAULT_TIMESTAMP_KEY
|
| 56 |
+
)
|
| 57 |
+
aux_act = CONST_AUX_ACT + str(time.time())
|
| 58 |
+
df = log.lazy() if isinstance(log, pl.DataFrame) else log
|
| 59 |
+
df = df.select([cid_key, act_key, time_key]).sort(
|
| 60 |
+
[cid_key, time_key], maintain_order=True
|
| 61 |
+
)
|
| 62 |
+
cases = df.group_by(cid_key).agg(
|
| 63 |
+
pl.col(act_key).first().alias("__start_activity"),
|
| 64 |
+
pl.col(act_key).last().alias("__end_activity"),
|
| 65 |
+
)
|
| 66 |
+
dfg = DFG()
|
| 67 |
+
|
| 68 |
+
for column, counts in (
|
| 69 |
+
("__start_activity", dfg.start_activities),
|
| 70 |
+
("__end_activity", dfg.end_activities),
|
| 71 |
+
):
|
| 72 |
+
activities = cases.group_by(column).len(name="count").collect()
|
| 73 |
+
for activity, count in activities.iter_rows():
|
| 74 |
+
if activity is not None:
|
| 75 |
+
counts[activity] = count
|
| 76 |
+
|
| 77 |
+
for d in (
|
| 78 |
+
df.with_columns(pl.col(act_key).shift(-1).over(cid_key).alias(aux_act))
|
| 79 |
+
.filter(pl.col(act_key).is_not_null() & pl.col(aux_act).is_not_null())
|
| 80 |
+
.group_by([act_key, aux_act])
|
| 81 |
+
.len(name="count")
|
| 82 |
+
.collect()
|
| 83 |
+
.to_dicts()
|
| 84 |
+
):
|
| 85 |
+
dfg.graph[(d[act_key], d[aux_act])] = d["count"]
|
| 86 |
+
|
| 87 |
+
return dfg
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/clean_time.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
|
| 23 |
+
import time
|
| 24 |
+
from enum import Enum
|
| 25 |
+
from typing import List, Optional, Dict, Any
|
| 26 |
+
|
| 27 |
+
import pandas as pd
|
| 28 |
+
import numpy as np
|
| 29 |
+
from pandas._libs.tslibs.timestamps import Timestamp
|
| 30 |
+
from pandas.core.frame import DataFrame
|
| 31 |
+
from pandas.core.tools.datetimes import to_datetime
|
| 32 |
+
|
| 33 |
+
from pm4py.objects.dfg.obj import DFG
|
| 34 |
+
from pm4py.util import constants, exec_utils
|
| 35 |
+
from pm4py.util import xes_constants as xes_util
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class Parameters(Enum):
|
| 39 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 40 |
+
CASE_ID_KEY = constants.PARAMETER_CONSTANT_CASEID_KEY
|
| 41 |
+
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
CONST_AUX_ACT = 'aux_act_'
|
| 45 |
+
CONST_AUX_CASE = 'aux_case_'
|
| 46 |
+
CONST_COUNT = 'count_'
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
from pm4py.discovery import discover_dfg_typed
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def apply(log: pd.DataFrame, parameters=None):
|
| 53 |
+
if parameters is None:
|
| 54 |
+
parameters = {}
|
| 55 |
+
|
| 56 |
+
act_key = exec_utils.get_param_value(
|
| 57 |
+
Parameters.ACTIVITY_KEY, parameters, xes_util.DEFAULT_NAME_KEY)
|
| 58 |
+
cid_key = exec_utils.get_param_value(
|
| 59 |
+
Parameters.CASE_ID_KEY, parameters, constants.CASE_ATTRIBUTE_GLUE)
|
| 60 |
+
time_key = exec_utils.get_param_value(
|
| 61 |
+
Parameters.TIMESTAMP_KEY, parameters, xes_util.DEFAULT_TIMESTAMP_KEY)
|
| 62 |
+
|
| 63 |
+
'''sort the values according to cid and timekey'''
|
| 64 |
+
df = log.sort_values([cid_key, time_key]).loc[:, [cid_key, act_key, time_key]].reset_index()
|
| 65 |
+
|
| 66 |
+
'''mapping each case ID to the first time stamp of that case.'''
|
| 67 |
+
grouped = df.groupby(cid_key)
|
| 68 |
+
all_cases = df[cid_key].unique()
|
| 69 |
+
|
| 70 |
+
time_dictionary_list = {}
|
| 71 |
+
|
| 72 |
+
for case in all_cases:
|
| 73 |
+
current_group = grouped.get_group(case)
|
| 74 |
+
current_group = current_group.sort_values([cid_key, time_key]).loc[:, [cid_key, act_key, time_key]].reset_index()
|
| 75 |
+
|
| 76 |
+
all_act = current_group[act_key].unique()
|
| 77 |
+
init_timestamp = current_group[time_key][0]
|
| 78 |
+
'''deal with loops in a case'''
|
| 79 |
+
for act in all_act:
|
| 80 |
+
df1 = current_group[current_group[act_key] == act]
|
| 81 |
+
mean_time = df1[time_key].mean()
|
| 82 |
+
average_time = mean_time - init_timestamp
|
| 83 |
+
|
| 84 |
+
if act not in time_dictionary_list.keys():
|
| 85 |
+
time_dictionary_list[act] = []
|
| 86 |
+
time_dictionary_list[act].append(average_time)
|
| 87 |
+
else:
|
| 88 |
+
time_dictionary_list[act].append(average_time)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
keys = time_dictionary_list.keys()
|
| 92 |
+
time_dictionary = {}
|
| 93 |
+
for key in keys:
|
| 94 |
+
avg=pd.to_timedelta(pd.Series(time_dictionary_list[key])).mean()
|
| 95 |
+
time_dictionary[key] = avg
|
| 96 |
+
|
| 97 |
+
return time_dictionary
|
| 98 |
+
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/freq_triples.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from collections import Counter
|
| 23 |
+
from enum import Enum
|
| 24 |
+
|
| 25 |
+
from pm4py.util import constants, exec_utils
|
| 26 |
+
from pm4py.util import xes_constants as xes_util
|
| 27 |
+
from typing import Optional, Dict, Any, Union, Tuple
|
| 28 |
+
from pm4py.objects.log.obj import EventLog, EventStream
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Parameters(Enum):
|
| 32 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def apply(
|
| 36 |
+
log: Union[EventLog, EventStream],
|
| 37 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 38 |
+
) -> Dict[Tuple[str, str, str], int]:
|
| 39 |
+
return freq_triples(log, parameters=parameters)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def freq_triples(
|
| 43 |
+
log: Union[EventLog, EventStream],
|
| 44 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 45 |
+
) -> Dict[Tuple[str, str, str], int]:
|
| 46 |
+
"""
|
| 47 |
+
Counts the number of directly follows occurrences, i.e. of the form <...a,b...>, in an event log.
|
| 48 |
+
|
| 49 |
+
Parameters
|
| 50 |
+
----------
|
| 51 |
+
log
|
| 52 |
+
Trace log
|
| 53 |
+
parameters
|
| 54 |
+
Possible parameters passed to the algorithms:
|
| 55 |
+
activity_key -> Attribute to use as activity
|
| 56 |
+
|
| 57 |
+
Returns
|
| 58 |
+
-------
|
| 59 |
+
dfg: dict
|
| 60 |
+
DFG graph
|
| 61 |
+
"""
|
| 62 |
+
if parameters is None:
|
| 63 |
+
parameters = {}
|
| 64 |
+
activity_key = exec_utils.get_param_value(
|
| 65 |
+
Parameters.ACTIVITY_KEY, parameters, xes_util.DEFAULT_NAME_KEY
|
| 66 |
+
)
|
| 67 |
+
dfgs = map(
|
| 68 |
+
(
|
| 69 |
+
lambda t: [
|
| 70 |
+
(
|
| 71 |
+
t[i - 2][activity_key],
|
| 72 |
+
t[i - 1][activity_key],
|
| 73 |
+
t[i][activity_key],
|
| 74 |
+
)
|
| 75 |
+
for i in range(2, len(t))
|
| 76 |
+
]
|
| 77 |
+
),
|
| 78 |
+
log,
|
| 79 |
+
)
|
| 80 |
+
return dict(Counter([dfg for lista in dfgs for dfg in lista]))
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/native.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from collections import Counter
|
| 23 |
+
|
| 24 |
+
from pm4py.util import constants, exec_utils
|
| 25 |
+
from pm4py.util import xes_constants as xes_util
|
| 26 |
+
from enum import Enum
|
| 27 |
+
from typing import Optional, Dict, Any, Union, Tuple
|
| 28 |
+
from pm4py.objects.log.obj import EventLog, EventStream
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Parameters(Enum):
|
| 32 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 33 |
+
WINDOW = "window"
|
| 34 |
+
KEEP_ONCE_PER_CASE = "keep_once_per_case"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def apply(
|
| 38 |
+
log: Union[EventLog, EventStream],
|
| 39 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 40 |
+
) -> Dict[Tuple[str, str], int]:
|
| 41 |
+
return native(log, parameters=parameters)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def native(
|
| 45 |
+
log: Union[EventLog, EventStream],
|
| 46 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 47 |
+
) -> Dict[Tuple[str, str], int]:
|
| 48 |
+
"""
|
| 49 |
+
Counts the number of directly follows occurrences, i.e. of the form <...a,b...>, in an event log.
|
| 50 |
+
|
| 51 |
+
Parameters
|
| 52 |
+
----------
|
| 53 |
+
log
|
| 54 |
+
Trace log
|
| 55 |
+
parameters
|
| 56 |
+
Possible parameters passed to the algorithms:
|
| 57 |
+
activity_key -> Attribute to use as activity
|
| 58 |
+
|
| 59 |
+
Returns
|
| 60 |
+
-------
|
| 61 |
+
dfg: dict
|
| 62 |
+
DFG graph
|
| 63 |
+
"""
|
| 64 |
+
if parameters is None:
|
| 65 |
+
parameters = {}
|
| 66 |
+
activity_key = exec_utils.get_param_value(
|
| 67 |
+
Parameters.ACTIVITY_KEY, parameters, xes_util.DEFAULT_NAME_KEY
|
| 68 |
+
)
|
| 69 |
+
window = exec_utils.get_param_value(Parameters.WINDOW, parameters, 1)
|
| 70 |
+
keep_once_per_case = exec_utils.get_param_value(
|
| 71 |
+
Parameters.KEEP_ONCE_PER_CASE, parameters, False
|
| 72 |
+
)
|
| 73 |
+
if keep_once_per_case:
|
| 74 |
+
dfgs = map(
|
| 75 |
+
(
|
| 76 |
+
lambda t: set(
|
| 77 |
+
(t[i - window][activity_key], t[i][activity_key])
|
| 78 |
+
for i in range(window, len(t))
|
| 79 |
+
)
|
| 80 |
+
),
|
| 81 |
+
log,
|
| 82 |
+
)
|
| 83 |
+
else:
|
| 84 |
+
dfgs = map(
|
| 85 |
+
(
|
| 86 |
+
lambda t: [
|
| 87 |
+
(t[i - window][activity_key], t[i][activity_key])
|
| 88 |
+
for i in range(window, len(t))
|
| 89 |
+
]
|
| 90 |
+
),
|
| 91 |
+
log,
|
| 92 |
+
)
|
| 93 |
+
return Counter([dfg for lista in dfgs for dfg in lista])
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/dfg/variants/performance.py
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from collections import Counter
|
| 23 |
+
from enum import Enum
|
| 24 |
+
|
| 25 |
+
from pm4py.util import constants, exec_utils
|
| 26 |
+
from pm4py.util import xes_constants as xes_util
|
| 27 |
+
from pm4py.util.business_hours import BusinessHours
|
| 28 |
+
from typing import Optional, Dict, Any, Union, Tuple
|
| 29 |
+
from pm4py.objects.log.obj import EventLog, EventStream
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class Parameters(Enum):
|
| 33 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 34 |
+
START_TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY
|
| 35 |
+
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
|
| 36 |
+
AGGREGATION_MEASURE = "aggregationMeasure"
|
| 37 |
+
BUSINESS_HOURS = "business_hours"
|
| 38 |
+
BUSINESS_HOUR_SLOTS = "business_hour_slots"
|
| 39 |
+
WORKCALENDAR = "workcalendar"
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def apply(
|
| 43 |
+
log: Union[EventLog, EventStream],
|
| 44 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 45 |
+
) -> Dict[Tuple[str, str], float]:
|
| 46 |
+
return performance(log, parameters=parameters)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def performance(
|
| 50 |
+
log: Union[EventLog, EventStream],
|
| 51 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 52 |
+
) -> Dict[Tuple[str, str], float]:
|
| 53 |
+
"""
|
| 54 |
+
Measure performance between couples of attributes in the DFG graph.
|
| 55 |
+
|
| 56 |
+
Parameters
|
| 57 |
+
----------
|
| 58 |
+
log
|
| 59 |
+
Log
|
| 60 |
+
parameters
|
| 61 |
+
Possible parameters passed to the algorithms:
|
| 62 |
+
aggregationMeasure -> performance aggregation measure (min, max, mean, median)
|
| 63 |
+
activity_key -> Attribute to use as activity
|
| 64 |
+
timestamp_key -> Attribute to use as timestamp
|
| 65 |
+
|
| 66 |
+
- Parameters.BUSINESS_HOURS => calculates the difference of time based on the business hours, not the total time. Default: False
|
| 67 |
+
- Parameters.BUSINESS_HOURS_SLOTS => work schedule of the company.
|
| 68 |
+
The following list defines that business hours are Mondays 07:00 - 17:00
|
| 69 |
+
and Tuesdays 07:00 - 12:00 and 13:00 - 17:00::
|
| 70 |
+
|
| 71 |
+
[
|
| 72 |
+
(7 * 60 * 60, 17 * 60 * 60),
|
| 73 |
+
((24 + 7) * 60 * 60, (24 + 12) * 60 * 60),
|
| 74 |
+
((24 + 13) * 60 * 60, (24 + 17) * 60 * 60),
|
| 75 |
+
]
|
| 76 |
+
Returns
|
| 77 |
+
-------
|
| 78 |
+
dfg : dict
|
| 79 |
+
DFG graph
|
| 80 |
+
|
| 81 |
+
"""
|
| 82 |
+
|
| 83 |
+
if parameters is None:
|
| 84 |
+
parameters = {}
|
| 85 |
+
|
| 86 |
+
from statistics import mean, median, stdev
|
| 87 |
+
|
| 88 |
+
activity_key = exec_utils.get_param_value(
|
| 89 |
+
Parameters.ACTIVITY_KEY, parameters, xes_util.DEFAULT_NAME_KEY
|
| 90 |
+
)
|
| 91 |
+
start_timestamp_key = exec_utils.get_param_value(
|
| 92 |
+
Parameters.START_TIMESTAMP_KEY,
|
| 93 |
+
parameters,
|
| 94 |
+
xes_util.DEFAULT_TIMESTAMP_KEY,
|
| 95 |
+
)
|
| 96 |
+
timestamp_key = exec_utils.get_param_value(
|
| 97 |
+
Parameters.TIMESTAMP_KEY, parameters, xes_util.DEFAULT_TIMESTAMP_KEY
|
| 98 |
+
)
|
| 99 |
+
aggregation_measure = exec_utils.get_param_value(
|
| 100 |
+
Parameters.AGGREGATION_MEASURE, parameters, "mean"
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
business_hours = exec_utils.get_param_value(
|
| 104 |
+
Parameters.BUSINESS_HOURS, parameters, False
|
| 105 |
+
)
|
| 106 |
+
business_hours_slots = exec_utils.get_param_value(
|
| 107 |
+
Parameters.BUSINESS_HOUR_SLOTS,
|
| 108 |
+
parameters,
|
| 109 |
+
constants.DEFAULT_BUSINESS_HOUR_SLOTS,
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
workcalendar = exec_utils.get_param_value(
|
| 113 |
+
Parameters.WORKCALENDAR,
|
| 114 |
+
parameters,
|
| 115 |
+
constants.DEFAULT_BUSINESS_HOURS_WORKCALENDAR,
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
if business_hours:
|
| 119 |
+
dfgs0 = map(
|
| 120 |
+
(
|
| 121 |
+
lambda t: [
|
| 122 |
+
(
|
| 123 |
+
(t[i - 1][activity_key], t[i][activity_key]),
|
| 124 |
+
max(
|
| 125 |
+
0,
|
| 126 |
+
BusinessHours(
|
| 127 |
+
t[i - 1][timestamp_key],
|
| 128 |
+
t[i][start_timestamp_key],
|
| 129 |
+
business_hour_slots=business_hours_slots,
|
| 130 |
+
workcalendar=workcalendar,
|
| 131 |
+
).get_seconds(),
|
| 132 |
+
),
|
| 133 |
+
)
|
| 134 |
+
for i in range(1, len(t))
|
| 135 |
+
]
|
| 136 |
+
),
|
| 137 |
+
log,
|
| 138 |
+
)
|
| 139 |
+
else:
|
| 140 |
+
dfgs0 = map(
|
| 141 |
+
(
|
| 142 |
+
lambda t: [
|
| 143 |
+
(
|
| 144 |
+
(t[i - 1][activity_key], t[i][activity_key]),
|
| 145 |
+
max(
|
| 146 |
+
0,
|
| 147 |
+
(
|
| 148 |
+
t[i][start_timestamp_key]
|
| 149 |
+
- t[i - 1][timestamp_key]
|
| 150 |
+
).total_seconds(),
|
| 151 |
+
),
|
| 152 |
+
)
|
| 153 |
+
for i in range(1, len(t))
|
| 154 |
+
]
|
| 155 |
+
),
|
| 156 |
+
log,
|
| 157 |
+
)
|
| 158 |
+
ret0 = {}
|
| 159 |
+
for el in dfgs0:
|
| 160 |
+
for couple in el:
|
| 161 |
+
if couple[0] not in ret0:
|
| 162 |
+
ret0[couple[0]] = []
|
| 163 |
+
ret0[couple[0]].append(couple[1])
|
| 164 |
+
ret = Counter()
|
| 165 |
+
for key in ret0:
|
| 166 |
+
if aggregation_measure == "median":
|
| 167 |
+
ret[key] = median(ret0[key])
|
| 168 |
+
elif aggregation_measure == "min":
|
| 169 |
+
ret[key] = min(ret0[key])
|
| 170 |
+
elif aggregation_measure == "max":
|
| 171 |
+
ret[key] = max(ret0[key])
|
| 172 |
+
elif aggregation_measure == "stdev":
|
| 173 |
+
ret[key] = stdev(ret0[key]) if len(ret0[key]) > 1 else 0
|
| 174 |
+
elif aggregation_measure == "sum":
|
| 175 |
+
ret[key] = sum(ret0[key])
|
| 176 |
+
elif aggregation_measure == "raw_values":
|
| 177 |
+
ret[key] = ret0[key]
|
| 178 |
+
elif aggregation_measure == "all":
|
| 179 |
+
ret[key] = {
|
| 180 |
+
"median": median(ret0[key]),
|
| 181 |
+
"min": min(ret0[key]),
|
| 182 |
+
"max": max(ret0[key]),
|
| 183 |
+
"stdev": stdev(ret0[key]) if len(ret0[key]) > 1 else 0,
|
| 184 |
+
"sum": sum(ret0[key]),
|
| 185 |
+
"mean": mean(ret0[key]),
|
| 186 |
+
}
|
| 187 |
+
else:
|
| 188 |
+
ret[key] = mean(ret0[key])
|
| 189 |
+
|
| 190 |
+
return ret
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.footprints import log, petri, dfg, algorithm, tree
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/algorithm.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.footprints.log.variants import (
|
| 23 |
+
entire_event_log,
|
| 24 |
+
trace_by_trace,
|
| 25 |
+
entire_dataframe,
|
| 26 |
+
)
|
| 27 |
+
from pm4py.algo.discovery.footprints.petri.variants import reach_graph
|
| 28 |
+
from pm4py.algo.discovery.footprints.dfg.variants import dfg
|
| 29 |
+
from pm4py.algo.discovery.footprints.tree.variants import bottomup
|
| 30 |
+
from pm4py.algo.discovery.footprints.powl.variants import bottomup as bottomup_powl
|
| 31 |
+
from pm4py.objects.log.obj import EventLog
|
| 32 |
+
from pm4py.objects.petri_net.obj import PetriNet
|
| 33 |
+
from pm4py.objects.process_tree.obj import ProcessTree
|
| 34 |
+
from enum import Enum
|
| 35 |
+
from pm4py.util import exec_utils, pandas_utils
|
| 36 |
+
from pm4py.utils import is_polars_lazyframe
|
| 37 |
+
import pandas as pd
|
| 38 |
+
from typing import Optional, Dict, Any
|
| 39 |
+
import importlib.util
|
| 40 |
+
|
| 41 |
+
POLARS_AVAILABLE = importlib.util.find_spec("polars") is not None
|
| 42 |
+
if POLARS_AVAILABLE:
|
| 43 |
+
from pm4py.algo.discovery.footprints.log.variants import polars_lazyframes
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class Variants(Enum):
|
| 47 |
+
ENTIRE_EVENT_LOG = entire_event_log
|
| 48 |
+
ENTIRE_DATAFRAME = entire_dataframe
|
| 49 |
+
TRACE_BY_TRACE = trace_by_trace
|
| 50 |
+
PETRI_REACH_GRAPH = reach_graph
|
| 51 |
+
PROCESS_TREE = bottomup
|
| 52 |
+
POWL = bottomup_powl
|
| 53 |
+
DFG = dfg
|
| 54 |
+
POLARS_LAZYFRAMES = polars_lazyframes if POLARS_AVAILABLE else entire_dataframe
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def apply(
|
| 58 |
+
*args, variant=None, parameters: Optional[Dict[Any, Any]] = None
|
| 59 |
+
) -> Dict[str, Any]:
|
| 60 |
+
"""
|
| 61 |
+
Discovers a footprint object from a log/model
|
| 62 |
+
|
| 63 |
+
Parameters
|
| 64 |
+
--------------
|
| 65 |
+
args
|
| 66 |
+
Positional arguments that describe the log/model
|
| 67 |
+
parameters
|
| 68 |
+
Parameters of the algorithm
|
| 69 |
+
variant
|
| 70 |
+
Variant of the algorithm, including:
|
| 71 |
+
- Variants.ENTIRE_EVENT_LOG
|
| 72 |
+
- Variants.TRACE_BY_TRACE
|
| 73 |
+
- Variants.PETRI_REACH_GRAPH
|
| 74 |
+
- Variants.DFG
|
| 75 |
+
|
| 76 |
+
Returns
|
| 77 |
+
--------------
|
| 78 |
+
footprints_obj
|
| 79 |
+
Footprints object
|
| 80 |
+
"""
|
| 81 |
+
from pm4py.objects.powl.obj import POWL, StrictPartialOrder, OperatorPOWL
|
| 82 |
+
|
| 83 |
+
if variant is None:
|
| 84 |
+
if type(args[0]) is EventLog:
|
| 85 |
+
variant = Variants.TRACE_BY_TRACE
|
| 86 |
+
elif type(args[0]) is PetriNet:
|
| 87 |
+
variant = Variants.PETRI_REACH_GRAPH
|
| 88 |
+
elif isinstance(args[0], POWL):
|
| 89 |
+
variant = Variants.POWL
|
| 90 |
+
elif type(args[0]) is ProcessTree:
|
| 91 |
+
variant = Variants.PROCESS_TREE
|
| 92 |
+
elif isinstance(args[0], dict):
|
| 93 |
+
variant = Variants.DFG
|
| 94 |
+
|
| 95 |
+
if pandas_utils.check_is_pandas_dataframe(args[0]):
|
| 96 |
+
if is_polars_lazyframe(args[0]):
|
| 97 |
+
if not POLARS_AVAILABLE:
|
| 98 |
+
raise RuntimeError(
|
| 99 |
+
"Polars LazyFrame provided but 'polars' package is not installed."
|
| 100 |
+
)
|
| 101 |
+
variant = Variants.POLARS_LAZYFRAMES
|
| 102 |
+
else:
|
| 103 |
+
variant = Variants.ENTIRE_DATAFRAME
|
| 104 |
+
|
| 105 |
+
if variant is None:
|
| 106 |
+
return Exception("unsupported arguments")
|
| 107 |
+
|
| 108 |
+
if variant in [
|
| 109 |
+
Variants.TRACE_BY_TRACE,
|
| 110 |
+
Variants.ENTIRE_EVENT_LOG,
|
| 111 |
+
Variants.DFG,
|
| 112 |
+
Variants.PROCESS_TREE,
|
| 113 |
+
Variants.POWL,
|
| 114 |
+
Variants.ENTIRE_DATAFRAME,
|
| 115 |
+
Variants.POLARS_LAZYFRAMES,
|
| 116 |
+
]:
|
| 117 |
+
return exec_utils.get_variant(variant).apply(
|
| 118 |
+
args[0], parameters=parameters
|
| 119 |
+
)
|
| 120 |
+
elif variant in [Variants.PETRI_REACH_GRAPH]:
|
| 121 |
+
return exec_utils.get_variant(variant).apply(
|
| 122 |
+
args[0], args[1], parameters=parameters
|
| 123 |
+
)
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/dfg/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.footprints.dfg import variants
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/dfg/variants/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.footprints.dfg.variants import dfg
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/dfg/variants/dfg.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.objects.dfg import utils
|
| 23 |
+
from enum import Enum
|
| 24 |
+
from typing import Optional, Dict, Any, Tuple
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Outputs(Enum):
|
| 28 |
+
DFG = "dfg"
|
| 29 |
+
SEQUENCE = "sequence"
|
| 30 |
+
PARALLEL = "parallel"
|
| 31 |
+
START_ACTIVITIES = "start_activities"
|
| 32 |
+
END_ACTIVITIES = "end_activities"
|
| 33 |
+
ACTIVITIES = "activities"
|
| 34 |
+
SKIPPABLE = "skippable"
|
| 35 |
+
ACTIVITIES_ALWAYS_HAPPENING = "activities_always_happening"
|
| 36 |
+
MIN_TRACE_LENGTH = "min_trace_length"
|
| 37 |
+
TRACE = "trace"
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def apply(
|
| 41 |
+
dfg: Dict[Tuple[str, str], int],
|
| 42 |
+
parameters: Optional[Dict[Any, Any]] = None,
|
| 43 |
+
) -> Dict[str, Any]:
|
| 44 |
+
"""
|
| 45 |
+
Discovers a footprint object from a DFG
|
| 46 |
+
|
| 47 |
+
Parameters
|
| 48 |
+
--------------
|
| 49 |
+
dfg
|
| 50 |
+
DFG
|
| 51 |
+
parameters
|
| 52 |
+
Parameters of the algorithm
|
| 53 |
+
|
| 54 |
+
Returns
|
| 55 |
+
--------------
|
| 56 |
+
footprints_obj
|
| 57 |
+
Footprints object
|
| 58 |
+
"""
|
| 59 |
+
if parameters is None:
|
| 60 |
+
parameters = {}
|
| 61 |
+
|
| 62 |
+
parallel = {(x, y) for (x, y) in dfg if (y, x) in dfg}
|
| 63 |
+
sequence = {(x, y) for (x, y) in dfg if not (y, x) in dfg}
|
| 64 |
+
# replace this if needed
|
| 65 |
+
start_activities = set(utils.dfg_utils.infer_start_activities(dfg))
|
| 66 |
+
# replace this if needed
|
| 67 |
+
end_activities = set(utils.dfg_utils.infer_end_activities(dfg))
|
| 68 |
+
activities = set(utils.dfg_utils.get_activities_from_dfg(dfg))
|
| 69 |
+
|
| 70 |
+
return {
|
| 71 |
+
Outputs.SEQUENCE.value: sequence,
|
| 72 |
+
Outputs.PARALLEL.value: parallel,
|
| 73 |
+
Outputs.START_ACTIVITIES.value: start_activities,
|
| 74 |
+
Outputs.END_ACTIVITIES.value: end_activities,
|
| 75 |
+
Outputs.ACTIVITIES.value: activities,
|
| 76 |
+
}
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/log/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.footprints.log import variants
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/log/variants/__init__.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.algo.discovery.footprints.log.variants import (
|
| 23 |
+
entire_event_log,
|
| 24 |
+
trace_by_trace,
|
| 25 |
+
entire_dataframe,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
import importlib.util
|
| 29 |
+
|
| 30 |
+
if importlib.util.find_spec("polars"):
|
| 31 |
+
from pm4py.algo.discovery.footprints.log.variants import polars_lazyframes # type: ignore[F401]
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/log/variants/entire_dataframe.py
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.util import xes_constants
|
| 23 |
+
from pm4py.util import constants
|
| 24 |
+
from pm4py.algo.discovery.dfg.adapters.pandas import df_statistics
|
| 25 |
+
from pm4py.util import exec_utils, pandas_utils
|
| 26 |
+
from pm4py.algo.discovery.causal import algorithm as causal_discovery
|
| 27 |
+
from enum import Enum
|
| 28 |
+
from typing import Optional, Dict, Any, Union
|
| 29 |
+
import pandas as pd
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class Outputs(Enum):
|
| 33 |
+
DFG = "dfg"
|
| 34 |
+
SEQUENCE = "sequence"
|
| 35 |
+
PARALLEL = "parallel"
|
| 36 |
+
START_ACTIVITIES = "start_activities"
|
| 37 |
+
END_ACTIVITIES = "end_activities"
|
| 38 |
+
ACTIVITIES = "activities"
|
| 39 |
+
SKIPPABLE = "skippable"
|
| 40 |
+
ACTIVITIES_ALWAYS_HAPPENING = "activities_always_happening"
|
| 41 |
+
MIN_TRACE_LENGTH = "min_trace_length"
|
| 42 |
+
TRACE = "trace"
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class Parameters(Enum):
|
| 46 |
+
SORT_REQUIRED = "sort_required"
|
| 47 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 48 |
+
START_TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY
|
| 49 |
+
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
|
| 50 |
+
CASE_ID_KEY = constants.PARAMETER_CONSTANT_CASEID_KEY
|
| 51 |
+
INDEX_KEY = "index_key"
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
DEFAULT_SORT_REQUIRED = True
|
| 55 |
+
DEFAULT_INDEX_KEY = "@@index"
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def apply(
|
| 59 |
+
df: pd.DataFrame,
|
| 60 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 61 |
+
) -> Dict[str, Any]:
|
| 62 |
+
"""
|
| 63 |
+
Discovers a footprint object from a dataframe
|
| 64 |
+
(the footprints of the dataframe are returned)
|
| 65 |
+
|
| 66 |
+
Parameters
|
| 67 |
+
--------------
|
| 68 |
+
df
|
| 69 |
+
Dataframe
|
| 70 |
+
parameters
|
| 71 |
+
Parameters of the algorithm
|
| 72 |
+
|
| 73 |
+
Returns
|
| 74 |
+
--------------
|
| 75 |
+
footprints_obj
|
| 76 |
+
Footprints object
|
| 77 |
+
"""
|
| 78 |
+
if parameters is None:
|
| 79 |
+
parameters = {}
|
| 80 |
+
|
| 81 |
+
activity_key = exec_utils.get_param_value(
|
| 82 |
+
Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY
|
| 83 |
+
)
|
| 84 |
+
caseid_key = exec_utils.get_param_value(
|
| 85 |
+
Parameters.CASE_ID_KEY, parameters, constants.CASE_CONCEPT_NAME
|
| 86 |
+
)
|
| 87 |
+
start_timestamp_key = exec_utils.get_param_value(
|
| 88 |
+
Parameters.TIMESTAMP_KEY, parameters, None
|
| 89 |
+
)
|
| 90 |
+
timestamp_key = exec_utils.get_param_value(
|
| 91 |
+
Parameters.TIMESTAMP_KEY,
|
| 92 |
+
parameters,
|
| 93 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 94 |
+
)
|
| 95 |
+
sort_required = exec_utils.get_param_value(
|
| 96 |
+
Parameters.SORT_REQUIRED, parameters, DEFAULT_SORT_REQUIRED
|
| 97 |
+
)
|
| 98 |
+
index_key = exec_utils.get_param_value(
|
| 99 |
+
Parameters.INDEX_KEY, parameters, DEFAULT_INDEX_KEY
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
df = df[[caseid_key, activity_key, timestamp_key]]
|
| 103 |
+
if sort_required:
|
| 104 |
+
df = pandas_utils.insert_index(df, index_key)
|
| 105 |
+
if start_timestamp_key is not None:
|
| 106 |
+
df = df.sort_values(
|
| 107 |
+
[caseid_key, start_timestamp_key, timestamp_key, index_key]
|
| 108 |
+
)
|
| 109 |
+
else:
|
| 110 |
+
df = df.sort_values([caseid_key, timestamp_key, index_key])
|
| 111 |
+
|
| 112 |
+
grouped_df = df.groupby(caseid_key)
|
| 113 |
+
dfg = df_statistics.get_dfg_graph(
|
| 114 |
+
df,
|
| 115 |
+
measure="frequency",
|
| 116 |
+
activity_key=activity_key,
|
| 117 |
+
case_id_glue=caseid_key,
|
| 118 |
+
timestamp_key=timestamp_key,
|
| 119 |
+
sort_caseid_required=False,
|
| 120 |
+
sort_timestamp_along_case_id=False,
|
| 121 |
+
start_timestamp_key=start_timestamp_key,
|
| 122 |
+
)
|
| 123 |
+
activities = set(pandas_utils.format_unique(df[activity_key].unique()))
|
| 124 |
+
start_activities = set(
|
| 125 |
+
pandas_utils.format_unique(grouped_df.first()[activity_key].unique())
|
| 126 |
+
)
|
| 127 |
+
end_activities = set(
|
| 128 |
+
pandas_utils.format_unique(grouped_df.last()[activity_key].unique())
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
parallel = {(x, y) for (x, y) in dfg if (y, x) in dfg}
|
| 132 |
+
sequence = set(
|
| 133 |
+
causal_discovery.apply(dfg, causal_discovery.Variants.CAUSAL_ALPHA)
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
ret = {}
|
| 137 |
+
ret[Outputs.DFG.value] = dfg
|
| 138 |
+
ret[Outputs.SEQUENCE.value] = sequence
|
| 139 |
+
ret[Outputs.PARALLEL.value] = parallel
|
| 140 |
+
ret[Outputs.ACTIVITIES.value] = activities
|
| 141 |
+
ret[Outputs.START_ACTIVITIES.value] = start_activities
|
| 142 |
+
ret[Outputs.END_ACTIVITIES.value] = end_activities
|
| 143 |
+
ret[Outputs.MIN_TRACE_LENGTH.value] = int(grouped_df.size().min())
|
| 144 |
+
|
| 145 |
+
return ret
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/log/variants/entire_event_log.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from pm4py.util import xes_constants
|
| 23 |
+
from pm4py.util import constants
|
| 24 |
+
from pm4py.algo.discovery.dfg import algorithm as dfg_discovery
|
| 25 |
+
from pm4py.algo.discovery.causal import algorithm as causal_discovery
|
| 26 |
+
from pm4py.statistics.start_activities.log import get as get_start_activities
|
| 27 |
+
from pm4py.statistics.end_activities.log import get as get_end_activities
|
| 28 |
+
from pm4py.objects.conversion.log import converter
|
| 29 |
+
from pm4py.util import exec_utils
|
| 30 |
+
from enum import Enum
|
| 31 |
+
from typing import Optional, Dict, Any, Union
|
| 32 |
+
from pm4py.objects.log.obj import EventLog
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class Outputs(Enum):
|
| 36 |
+
DFG = "dfg"
|
| 37 |
+
SEQUENCE = "sequence"
|
| 38 |
+
PARALLEL = "parallel"
|
| 39 |
+
START_ACTIVITIES = "start_activities"
|
| 40 |
+
END_ACTIVITIES = "end_activities"
|
| 41 |
+
ACTIVITIES = "activities"
|
| 42 |
+
SKIPPABLE = "skippable"
|
| 43 |
+
ACTIVITIES_ALWAYS_HAPPENING = "activities_always_happening"
|
| 44 |
+
MIN_TRACE_LENGTH = "min_trace_length"
|
| 45 |
+
TRACE = "trace"
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class Parameters(Enum):
|
| 49 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def apply(
|
| 53 |
+
log: EventLog,
|
| 54 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 55 |
+
) -> Dict[str, Any]:
|
| 56 |
+
"""
|
| 57 |
+
Discovers a footprint object from an event log
|
| 58 |
+
(the footprints of the event log are returned)
|
| 59 |
+
|
| 60 |
+
Parameters
|
| 61 |
+
--------------
|
| 62 |
+
log
|
| 63 |
+
Log
|
| 64 |
+
parameters
|
| 65 |
+
Parameters of the algorithm:
|
| 66 |
+
- Parameters.ACTIVITY_KEY
|
| 67 |
+
|
| 68 |
+
Returns
|
| 69 |
+
--------------
|
| 70 |
+
footprints_obj
|
| 71 |
+
Footprints object
|
| 72 |
+
"""
|
| 73 |
+
if parameters is None:
|
| 74 |
+
parameters = {}
|
| 75 |
+
|
| 76 |
+
activity_key = exec_utils.get_param_value(
|
| 77 |
+
Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
log = converter.apply(
|
| 81 |
+
log, variant=converter.TO_EVENT_LOG, parameters=parameters
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
dfg = dfg_discovery.apply(log, parameters=parameters)
|
| 85 |
+
parallel = {(x, y) for (x, y) in dfg if (y, x) in dfg}
|
| 86 |
+
sequence = set(
|
| 87 |
+
causal_discovery.apply(dfg, causal_discovery.Variants.CAUSAL_ALPHA)
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
start_activities = set(
|
| 91 |
+
get_start_activities.get_start_activities(log, parameters=parameters)
|
| 92 |
+
)
|
| 93 |
+
end_activities = set(
|
| 94 |
+
get_end_activities.get_end_activities(log, parameters=parameters)
|
| 95 |
+
)
|
| 96 |
+
activities = set(y[activity_key] for x in log for y in x)
|
| 97 |
+
|
| 98 |
+
return {
|
| 99 |
+
Outputs.DFG.value: dfg,
|
| 100 |
+
Outputs.SEQUENCE.value: sequence,
|
| 101 |
+
Outputs.PARALLEL.value: parallel,
|
| 102 |
+
Outputs.START_ACTIVITIES.value: start_activities,
|
| 103 |
+
Outputs.END_ACTIVITIES.value: end_activities,
|
| 104 |
+
Outputs.ACTIVITIES.value: activities,
|
| 105 |
+
Outputs.MIN_TRACE_LENGTH.value: (
|
| 106 |
+
min(len(x) for x in log) if len(log) > 0 else 0
|
| 107 |
+
),
|
| 108 |
+
}
|
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/discovery/footprints/log/variants/polars_lazyframes.py
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
PM4Py – A Process Mining Library for Python
|
| 3 |
+
Copyright (C) 2026 Process Intelligence Solutions GmbH
|
| 4 |
+
|
| 5 |
+
This program is free software: you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU Affero General Public License as
|
| 7 |
+
published by the Free Software Foundation, either version 3 of the
|
| 8 |
+
License, or any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU Affero General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU Affero General Public License
|
| 16 |
+
along with this program. If not, see this software project's root or
|
| 17 |
+
visit <https://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
Website: https://processintelligence.solutions
|
| 20 |
+
Contact: info@processintelligence.solutions
|
| 21 |
+
'''
|
| 22 |
+
from enum import Enum
|
| 23 |
+
from typing import Optional, Dict, Any, Union
|
| 24 |
+
|
| 25 |
+
import importlib.util
|
| 26 |
+
|
| 27 |
+
from pm4py.util import xes_constants, constants, exec_utils, pandas_utils
|
| 28 |
+
from pm4py.algo.discovery.causal import algorithm as causal_discovery
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Outputs(Enum):
|
| 32 |
+
DFG = "dfg"
|
| 33 |
+
SEQUENCE = "sequence"
|
| 34 |
+
PARALLEL = "parallel"
|
| 35 |
+
START_ACTIVITIES = "start_activities"
|
| 36 |
+
END_ACTIVITIES = "end_activities"
|
| 37 |
+
ACTIVITIES = "activities"
|
| 38 |
+
SKIPPABLE = "skippable"
|
| 39 |
+
ACTIVITIES_ALWAYS_HAPPENING = "activities_always_happening"
|
| 40 |
+
MIN_TRACE_LENGTH = "min_trace_length"
|
| 41 |
+
TRACE = "trace"
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class Parameters(Enum):
|
| 45 |
+
SORT_REQUIRED = "sort_required"
|
| 46 |
+
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
|
| 47 |
+
START_TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY
|
| 48 |
+
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
|
| 49 |
+
CASE_ID_KEY = constants.PARAMETER_CONSTANT_CASEID_KEY
|
| 50 |
+
INDEX_KEY = "index_key"
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
DEFAULT_SORT_REQUIRED = True
|
| 54 |
+
DEFAULT_INDEX_KEY = "@@index"
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def apply(
|
| 58 |
+
lf,
|
| 59 |
+
parameters: Optional[Dict[Union[str, Parameters], Any]] = None,
|
| 60 |
+
) -> Dict[str, Any]:
|
| 61 |
+
if parameters is None:
|
| 62 |
+
parameters = {}
|
| 63 |
+
|
| 64 |
+
if importlib.util.find_spec("polars") is None:
|
| 65 |
+
raise RuntimeError(
|
| 66 |
+
"Polars LazyFrame provided but 'polars' package is not installed."
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
import polars as pl # type: ignore[import-untyped]
|
| 70 |
+
from pm4py.algo.discovery.dfg.adapters.polars import df_statistics
|
| 71 |
+
|
| 72 |
+
activity_key = exec_utils.get_param_value(
|
| 73 |
+
Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY
|
| 74 |
+
)
|
| 75 |
+
caseid_key = exec_utils.get_param_value(
|
| 76 |
+
Parameters.CASE_ID_KEY, parameters, constants.CASE_CONCEPT_NAME
|
| 77 |
+
)
|
| 78 |
+
start_timestamp_key = exec_utils.get_param_value(
|
| 79 |
+
Parameters.START_TIMESTAMP_KEY, parameters, None
|
| 80 |
+
)
|
| 81 |
+
timestamp_key = exec_utils.get_param_value(
|
| 82 |
+
Parameters.TIMESTAMP_KEY,
|
| 83 |
+
parameters,
|
| 84 |
+
xes_constants.DEFAULT_TIMESTAMP_KEY,
|
| 85 |
+
)
|
| 86 |
+
sort_required = exec_utils.get_param_value(
|
| 87 |
+
Parameters.SORT_REQUIRED, parameters, DEFAULT_SORT_REQUIRED
|
| 88 |
+
)
|
| 89 |
+
index_key = exec_utils.get_param_value(
|
| 90 |
+
Parameters.INDEX_KEY, parameters, DEFAULT_INDEX_KEY
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
required_columns = {caseid_key, activity_key, timestamp_key}
|
| 94 |
+
if start_timestamp_key is not None:
|
| 95 |
+
required_columns.add(start_timestamp_key)
|
| 96 |
+
|
| 97 |
+
if hasattr(lf, "collect_schema"):
|
| 98 |
+
lf_columns = lf.collect_schema().names()
|
| 99 |
+
else:
|
| 100 |
+
lf_columns = lf.columns
|
| 101 |
+
|
| 102 |
+
missing_columns = [col for col in required_columns if col not in lf_columns]
|
| 103 |
+
if missing_columns:
|
| 104 |
+
raise Exception(
|
| 105 |
+
"The provided Polars LazyFrame does not contain the following required columns: "
|
| 106 |
+
+ ", ".join(sorted(missing_columns))
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
lf_selected = lf.select(list(required_columns))
|
| 110 |
+
|
| 111 |
+
if sort_required:
|
| 112 |
+
lf_selected = pandas_utils.insert_index(
|
| 113 |
+
lf_selected, column_name=index_key, copy_dataframe=False
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
sort_columns = [caseid_key]
|
| 117 |
+
if start_timestamp_key is not None:
|
| 118 |
+
sort_columns.append(start_timestamp_key)
|
| 119 |
+
sort_columns.append(timestamp_key)
|
| 120 |
+
sort_columns.append(index_key)
|
| 121 |
+
|
| 122 |
+
lf_selected = lf_selected.sort(sort_columns, maintain_order=True)
|
| 123 |
+
|
| 124 |
+
dfg = df_statistics.get_dfg_graph(
|
| 125 |
+
lf_selected,
|
| 126 |
+
measure="frequency",
|
| 127 |
+
activity_key=activity_key,
|
| 128 |
+
case_id_glue=caseid_key,
|
| 129 |
+
timestamp_key=timestamp_key,
|
| 130 |
+
sort_caseid_required=False,
|
| 131 |
+
sort_timestamp_along_case_id=False,
|
| 132 |
+
start_timestamp_key=start_timestamp_key,
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
activities_df = (
|
| 136 |
+
lf_selected.select(pl.col(activity_key).unique().alias("__act__"))
|
| 137 |
+
.collect()
|
| 138 |
+
)
|
| 139 |
+
activities = set(activities_df["__act__"].to_list())
|
| 140 |
+
|
| 141 |
+
grouped = lf_selected.group_by(caseid_key)
|
| 142 |
+
first_df = grouped.agg(pl.col(activity_key).first().alias("__first__"))
|
| 143 |
+
last_df = grouped.agg(pl.col(activity_key).last().alias("__last__"))
|
| 144 |
+
|
| 145 |
+
start_activities = set(first_df.collect()["__first__"].to_list())
|
| 146 |
+
end_activities = set(last_df.collect()["__last__"].to_list())
|
| 147 |
+
|
| 148 |
+
parallel = {(x, y) for (x, y) in dfg if (y, x) in dfg}
|
| 149 |
+
sequence = set(
|
| 150 |
+
causal_discovery.apply(dfg, causal_discovery.Variants.CAUSAL_ALPHA)
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
min_trace_length_df = grouped.agg(pl.len().alias("__size__")).collect()
|
| 154 |
+
min_trace_length = int(min_trace_length_df["__size__"].min())
|
| 155 |
+
|
| 156 |
+
ret: Dict[str, Any] = {}
|
| 157 |
+
ret[Outputs.DFG.value] = dfg
|
| 158 |
+
ret[Outputs.SEQUENCE.value] = sequence
|
| 159 |
+
ret[Outputs.PARALLEL.value] = parallel
|
| 160 |
+
ret[Outputs.ACTIVITIES.value] = activities
|
| 161 |
+
ret[Outputs.START_ACTIVITIES.value] = start_activities
|
| 162 |
+
ret[Outputs.END_ACTIVITIES.value] = end_activities
|
| 163 |
+
ret[Outputs.MIN_TRACE_LENGTH.value] = min_trace_length
|
| 164 |
+
|
| 165 |
+
return ret
|
| 166 |
+
|