【pm4py 官网】https://pm4py.fit.fraunhofer.de/
【ProM官网】http://promtools.org/doku.php
A sneak peak of pmp4y’s simple application:
import pm4py
log = pm4py.read_xes('' )
process_model = pm4py.discover_bpmn_inductive(log)
pm4py.view_bpmn(process_model)
即读取XES log,基于inductive miner生成bpmn,并进行预览。例如:
virtualenv -p python3.7 ~/venv/processmining
source ~/venv/processminging/bin/activate
python3.7 -m pip install pm4py
pip list
pm4py为最新版本2.2.27
可读取XES和CSV格式log:
import pm4py
log = pm4py.read_xes('tests/input_data/running-example.xes')
此时可查看log,可看出log包含25个eventlog(即ProM中的cases),第一个eventlog包含92个traces(即Prom中第一个case包含92个event),第2个eventlog包含62个traces;这25个eventlog包含的traces数目最大为92,最小为34。
其中第一个eventlog的第一个trace(即ProM中第一个case的第一个event),concept:name为Start,lifecycle:transition为start……
下图即为ProM软件(【ProM官网】http://promtools.org/doku.php)对同一XES日志文件的读取分析数据,与pm4py相同。
除了pm4py官网上所显示的pm4py.read_xes('tests/input_data/running-example.xes')
,还可以通过converter进行读取:
from pm4py.objects.log.importer.xes import importer as xes_importer
log = xes_importer.apply('' )
import pandas as pd
import pm4py
dataframe = pd.read_csv('tests/input_data/running-example.csv', sep=',')
dataframe = pm4py.format_dataframe(dataframe, case_id='case:concept:name', activity_key='concept:name', timestamp_key='time:timestamp')
event_log = pm4py.convert_to_event_log(dataframe)
要注意的是,表头应与case:concept:name
, concept:name
,time:timestamp
对应;
但是当表格中有起始和终止时间时,未确定读取方法。(可在ProM中读取CSV,再转换为XES格式;然后即可通过1.1的方式读取)
process_model = pm4py.discover_bpmn_inductive(log)
petri_net, initial_marking, final_marking = pm4py.discover_petri_net_inductive(log)
process_tree = pm4py.discover_process_tree_inductive(log)
# BPMN
pm4py.view_bpmn(process_model_bpmn, format="pdf")
# Petri net
pm4py.view_petri_net(petri_net)
# Process tree
pm4py.view_process_tree(process_tree)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 8/26/22 4:13 PM
# @Author :
# @File : processmining.py
# @Version :
# @Software: PyCharm
# @Description : 'process mining'
import pm4py
from pm4py.objects.log.importer.xes import importer as xes_importer
def quick_start():
log = pm4py.read_xes('/home/deng/cugb/STL/CSTL/Process/PromEventLog/activitylog_uci_detailed_labour.xes')
process_model = pm4py.discover_bpmn_inductive(log)
pm4py.view_bpmn(process_model)
def read_xes():
# read XES log
# by pm4py.read_xes
log = pm4py.read_xes('./PromEventLog/activitylog_uci_detailed_labour.xes')
# by xes_importer.apply
log = xes_importer.apply('./PromEventLog/activitylog_uci_detailed_labour.xes')
log = xes_importer.apply('./PromEventLog/PurchasingExample_convertedByProM.xes')
return log
def miner(log):
# BPMN
process_model_bpmn = pm4py.discover_bpmn_inductive(log)
# Petri net
petri_net, initial_marking, final_marking = pm4py.discover_petri_net_inductive(log)
# Process tree
process_tree = pm4py.discover_process_tree_inductive(log)
return process_model_bpmn, petri_net, process_tree
def view(process_model_bpmn, petri_net, process_tree):
# BPMN
pm4py.view_bpmn(process_model_bpmn, format="pdf")
pm4py.save_vis_bpmn(process_model_bpmn, 'test.pdf')
# Petri net
pm4py.view_petri_net(petri_net)
# Process tree
pm4py.view_process_tree(process_tree)
if __name__ == '__main__':
quick_start()
log = read_xes()
process_model_bpmn, petri_net, process_tree = miner(log)
view(process_model_bpmn, petri_net, process_tree)
print('done')