2024-03-06 17:59:22 +01:00
|
|
|
# 08_infos-clusters.py
|
|
|
|
#
|
|
|
|
# content: (1) Load data and create event log
|
|
|
|
# (2) Infos for clusters
|
|
|
|
# (3) Process maps for clusters
|
|
|
|
#
|
|
|
|
# input: results/haum/eventlogs_pre-corona_item-clusters.csv
|
|
|
|
# output: results/haum/pn_infos_clusters.csv
|
|
|
|
#
|
|
|
|
# last mod: 2024-03-06
|
|
|
|
|
2024-01-25 17:21:18 +01:00
|
|
|
import pm4py
|
|
|
|
import pandas as pd
|
|
|
|
|
|
|
|
from python_helpers import eval_pm, pn_infos
|
|
|
|
|
2024-03-06 17:59:22 +01:00
|
|
|
#--------------- (1) Load data and create event logs ---------------
|
2024-01-25 17:21:18 +01:00
|
|
|
|
2024-03-06 17:59:22 +01:00
|
|
|
dat = pd.read_csv("results/haum/eventlogs_pre-corona_item-clusters.csv", sep = ";")
|
2024-01-25 17:21:18 +01:00
|
|
|
|
|
|
|
log_path = pm4py.format_dataframe(dat, case_id = "path", activity_key = "event",
|
2024-03-06 17:59:22 +01:00
|
|
|
timestamp_key = "date.start")
|
2024-01-25 17:21:18 +01:00
|
|
|
|
2024-03-06 17:59:22 +01:00
|
|
|
#--------------- (2) Infos for clusters ---------------
|
2024-01-25 17:21:18 +01:00
|
|
|
|
|
|
|
# Merge clusters into data frame
|
2024-01-30 11:48:48 +01:00
|
|
|
eval = pd.DataFrame(columns = ["fitness", "precision", "generalizability",
|
|
|
|
"simplicity", "sound", "narcs", "ntrans",
|
|
|
|
"nplaces", "nvariants", "mostfreq"])
|
2024-01-25 17:21:18 +01:00
|
|
|
for cluster in log_path.grp.unique().tolist():
|
2024-01-30 11:48:48 +01:00
|
|
|
eval = pd.concat([eval, pn_infos(log_path, "grp", cluster)])
|
|
|
|
eval = eval.sort_index()
|
2024-01-25 17:21:18 +01:00
|
|
|
|
2024-01-30 11:48:48 +01:00
|
|
|
eval.to_csv("results/haum/pn_infos_clusters.csv", sep = ";")
|
2024-01-25 17:21:18 +01:00
|
|
|
|
2024-03-06 17:59:22 +01:00
|
|
|
#--------------- (3) Process maps for clusters ---------------
|
2024-01-25 17:21:18 +01:00
|
|
|
|
|
|
|
for cluster in log_path.grp.unique().tolist():
|
|
|
|
subdata = log_path[log_path.grp == cluster]
|
2024-03-06 17:59:22 +01:00
|
|
|
subnet, subim, subfm = pm4py.discover_petri_net_inductive(subdata, noise_threshold=0.5)
|
2024-01-25 17:21:18 +01:00
|
|
|
pm4py.save_vis_petri_net(subnet, subim, subfm,
|
2024-03-06 17:59:22 +01:00
|
|
|
"results/processmaps/petrinet_cluster" + str(cluster).zfill(3) + ".png")
|
2024-01-25 17:21:18 +01:00
|
|
|
bpmn = pm4py.convert.convert_to_bpmn(subnet, subim, subfm)
|
2024-03-06 17:59:22 +01:00
|
|
|
pm4py.vis.save_vis_bpmn(bpmn, "results/processmaps/bpmn_cluster_" +
|
|
|
|
str(cluster).zfill(3) + ".png")
|