Dealing with variants example

[15]:
! pip install sax4bpm
[16]:
import warnings
warnings.filterwarnings('ignore', category=RuntimeWarning)
warnings.filterwarnings('ignore', category=UserWarning)
[17]:

from sax.core.process_data.formatters.xes_formatter import XESFormatter from sax.core.process_data.formatters.csv_formatter import CSVFormatter from sax.core.utils.constants import Constants from lingam.utils import make_dot from sax.core.process_data.tabular_data import TabularEventData import pm4py from pm4py.algo.discovery.alpha import algorithm as alpha_miner from pm4py.algo.discovery.inductive import algorithm as inductive_miner from pm4py.algo.discovery.heuristics import algorithm as heuristics_miner from pm4py.algo.discovery.dfg import algorithm as dfg_discovery import sax.core.process_mining.process_mining as pm # viz from pm4py.visualization.petri_net import visualizer as pn_visualizer from pm4py.visualization.process_tree import visualizer as pt_visualizer from pm4py.visualization.heuristics_net import visualizer as hn_visualizer from pm4py.visualization.dfg import visualizer as dfg_visualization from pm4py.objects.conversion.log import converter as log_converter from pm4py.objects.log.importer.xes import importer as xes_importer # misc from pm4py.objects.conversion.process_tree import converter as pt_converter
[18]:
#Import the event log file and create an event log data object

fileName = "RequestPaymentRejectedAndPayment.xes"
event_log = pm.import_xes(fileName,timestamp_format="%Y-%m-%d %H:%M:%S.%f")
parsing log, completed traces :: 100%|██████████| 378/378 [00:00<00:00, 1380.97it/s]
[5]:
# Get the parsed dataset from the event log object
event_log.getData()
[5]:
org:resource concept:name org:role time:timestamp case:concept:name start:timestamp lifecycle:transition
0 STAFF MEMBER Request For Payment REJECTED by ADMINISTRATION ADMINISTRATION 2018-02-14 08:56:47+00:00 request for payment 153160 2018-02-14 08:56:47+00:00 start
0 STAFF MEMBER Request For Payment REJECTED by ADMINISTRATION ADMINISTRATION 2018-02-14 08:56:47+00:00 request for payment 153160 2018-02-14 08:56:47+00:00 complete
6 STAFF MEMBER Request For Payment REJECTED by EMPLOYEE EMPLOYEE 2018-02-14 14:24:32+00:00 request for payment 153160 2018-02-14 08:56:47+00:00 start
6 STAFF MEMBER Request For Payment REJECTED by EMPLOYEE EMPLOYEE 2018-02-14 14:24:32+00:00 request for payment 153160 2018-02-14 08:56:47+00:00 complete
1 STAFF MEMBER Request For Payment SUBMITTED by EMPLOYEE EMPLOYEE 2018-02-14 14:47:01+00:00 request for payment 153160 2018-02-14 08:56:47+00:00 start
... ... ... ... ... ... ... ...
2789 STAFF MEMBER Request For Payment FINAL_APPROVED by SUPERVISOR SUPERVISOR 2018-12-20 08:14:26+00:00 request for payment 185301 2018-12-19 12:56:10+00:00 complete
2787 SYSTEM Request Payment UNDEFINED 2018-12-20 08:22:54+00:00 request for payment 185301 2018-12-19 12:56:10+00:00 start
2787 SYSTEM Request Payment UNDEFINED 2018-12-20 08:22:54+00:00 request for payment 185301 2018-12-19 12:56:10+00:00 complete
2788 SYSTEM Payment Handled UNDEFINED 2019-01-03 10:59:16+00:00 request for payment 185301 2018-12-19 12:56:10+00:00 start
2788 SYSTEM Payment Handled UNDEFINED 2019-01-03 10:59:16+00:00 request for payment 185301 2018-12-19 12:56:10+00:00 complete

5582 rows × 7 columns

[6]:
# Fetch and print the mandatory properties and optional properties within the event log file
print('Mandatory Properties of the parsed event log: \n',event_log.getMandatoryProperties())
print('Optional properties of the parsed event log: \n',event_log.getOptionalProperties())

Mandatory Properties of the parsed event log:
 {'case:concept:name': 'case:concept:name', 'concept:name': 'concept:name', 'time:timestamp': 'time:timestamp', 'lifecycle:transition': 'lifecycle:transition', 'start:timestamp': 'start:timestamp'}
Optional properties of the parsed event log:
 {'org:resource': 'org:resource', 'org:role': 'org:role'}
[7]:
# Run heuristic process miner on the whole dataset and visualize the resulting net
net = pm.discover_heuristics_net(event_log)
pm.view_heuristics_net(net)
_images/Dealing_variants_7_0.png
[8]:
# Get the data  for all mandatory properties columns within the event log
activities_data = event_log.getMandatoryPropertiesData()
activities_data
[8]:
concept:name time:timestamp case:concept:name start:timestamp lifecycle:transition
0 Request For Payment REJECTED by ADMINISTRATION 2018-02-14 08:56:47+00:00 request for payment 153160 2018-02-14 08:56:47+00:00 start
0 Request For Payment REJECTED by ADMINISTRATION 2018-02-14 08:56:47+00:00 request for payment 153160 2018-02-14 08:56:47+00:00 complete
6 Request For Payment REJECTED by EMPLOYEE 2018-02-14 14:24:32+00:00 request for payment 153160 2018-02-14 08:56:47+00:00 start
6 Request For Payment REJECTED by EMPLOYEE 2018-02-14 14:24:32+00:00 request for payment 153160 2018-02-14 08:56:47+00:00 complete
1 Request For Payment SUBMITTED by EMPLOYEE 2018-02-14 14:47:01+00:00 request for payment 153160 2018-02-14 08:56:47+00:00 start
... ... ... ... ... ...
2789 Request For Payment FINAL_APPROVED by SUPERVISOR 2018-12-20 08:14:26+00:00 request for payment 185301 2018-12-19 12:56:10+00:00 complete
2787 Request Payment 2018-12-20 08:22:54+00:00 request for payment 185301 2018-12-19 12:56:10+00:00 start
2787 Request Payment 2018-12-20 08:22:54+00:00 request for payment 185301 2018-12-19 12:56:10+00:00 complete
2788 Payment Handled 2019-01-03 10:59:16+00:00 request for payment 185301 2018-12-19 12:56:10+00:00 start
2788 Payment Handled 2019-01-03 10:59:16+00:00 request for payment 185301 2018-12-19 12:56:10+00:00 complete

5582 rows × 5 columns

[9]:
# Get all process variants within the event_log
event_log.getVariants()
[9]:
{'Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled': 233,
 'Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment APPROVED by BUDGET OWNER,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled': 124,
 'Request For Payment REJECTED by EMPLOYEE,Request For Payment REJECTED by ADMINISTRATION,Request For Payment FOR_APPROVAL by ADMINISTRATION,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment APPROVED by BUDGET OWNER,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled': 1,
 'Request For Payment REJECTED by ADMINISTRATION,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled': 4,
 'Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment APPROVED by BUDGET OWNER,Request Payment,Request For Payment FINAL_APPROVED by SUPERVISOR,Payment Handled': 1,
 'Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by BUDGET OWNER,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment APPROVED by BUDGET OWNER,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled': 1,
 'Request For Payment REJECTED by BUDGET OWNER,Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment APPROVED by BUDGET OWNER,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled': 1,
 'Request For Payment REJECTED by ADMINISTRATION,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment APPROVED by BUDGET OWNER,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled': 2,
 'Request For Payment APPROVED by BUDGET OWNER,Request For Payment REJECTED by SUPERVISOR,Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled': 2,
 'Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by SUPERVISOR,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment APPROVED by BUDGET OWNER,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled': 3,
 'Request For Payment REJECTED by SUPERVISOR,Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled': 1,
 'Request For Payment REJECTED by EMPLOYEE,Request For Payment REJECTED by ADMINISTRATION,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment APPROVED by BUDGET OWNER,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled': 1,
 'Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by BUDGET OWNER,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled': 1,
 'Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment APPROVED by BUDGET OWNER,Request For Payment APPROVED by SUPERVISOR,Request For Payment FINAL_APPROVED by DIRECTOR,Request Payment,Payment Handled': 2,
 'Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment APPROVED by SUPERVISOR,Request For Payment FINAL_APPROVED by DIRECTOR,Request Payment,Payment Handled': 1}
[10]:
# Explore particular variant - get the heuristic process net for the chosen variant
from sax.core.utils.constants import LifecycleTypes
variant1 = 'Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled'
net = pm.discover_heuristics_net(event_log,[variant1],[LifecycleTypes.COMPLETE.value])
pm.view_heuristics_net(net)
_images/Dealing_variants_10_0.png
[11]:
# Explore particular variant - get the heuristic process net for two chosen variants
from sax.core.utils.constants import LifecycleTypes

variant2='Request For Payment REJECTED by ADMINISTRATION,Request For Payment REJECTED by EMPLOYEE,Request For Payment SUBMITTED by EMPLOYEE,Request For Payment APPROVED by ADMINISTRATION,Request For Payment APPROVED by BUDGET OWNER,Request For Payment FINAL_APPROVED by SUPERVISOR,Request Payment,Payment Handled'
net = pm.discover_heuristics_net(event_log,[variant1,variant2],[LifecycleTypes.COMPLETE.value])
pm.view_heuristics_net(net)
_images/Dealing_variants_11_0.png
[12]:
# Get causal discovery model for the event log

import sax.core.causal_process_discovery.causal_discovery as cd
result = cd.discover_causal_dependencies(event_log)
cd.view_causal_dependencies(result)
[12]:
_images/Dealing_variants_12_0.svg
[13]:
# Explore particular variant - get the causal model for chosen variant

import sax.core.causal_process_discovery.causal_discovery as cd
result = cd.discover_causal_dependencies(event_log,[variant1])
cd.view_causal_dependencies(result)

[13]:
_images/Dealing_variants_13_0.svg
[14]:
# Explore particular variant - get the causal model for two chosen variants

import sax.core.causal_process_discovery.causal_discovery as cd
result = cd.discover_causal_dependencies(event_log,[variant1,variant2])
cd.view_causal_dependencies(result)
[14]:
_images/Dealing_variants_14_0.svg