Pm4py: analisa performance dari xes

From OnnoWiki
Jump to navigation Jump to search

Berikut contoh source code Python untuk melakukan analisis performa (performance analysis) atau deteksi congestion (kemacetan/bottleneck) menggunakan library `pm4py` pada file `.xes` yang telah kamu lampirkan (`Production.xes`):

# Pertama, pastikan pm4py terinstal:
# !pip install pm4py

import pm4py
from pm4py.objects.log.importer.xes import importer as xes_importer
from pm4py.algo.discovery.performance_spectrum import algorithm as performance_spectrum
from pm4py.visualization.performance_spectrum import visualizer as performance_spectrum_visualizer
from pm4py.algo.filtering.log.attributes import attributes_filter

# 1. Memuat log peristiwa dari file XES
log = xes_importer.apply("Production.xes")

# 2. Mengidentifikasi aktivitas unik dalam log
activities = attributes_filter.get_attribute_values(log, "concept:name")
list_activities = list(activities.keys())

# 3. Menerapkan algoritma performance spectrum
parameters = {performance_spectrum.Parameters.TIMESTAMP_KEY: 'Complete Timestamp'}
ps = performance_spectrum.apply(log, list_activities, parameters=parameters)
# ps = performance_spectrum.apply(log, list_activities)

# 4. Memvisualisasikan hasil performance spectrum
gviz = performance_spectrum_visualizer.apply(ps)
performance_spectrum_visualizer.view(gviz)

Penjelasan:

  • `performance_spectrum.apply(log)`: Menghitung waktu antar aktivitas, mendeteksi bottleneck atau kemacetan proses.
  • `spectrum_visualizer.view()`: Menampilkan visualisasi interaktif (biasanya dalam bentuk histogram atau heatmap) yang menunjukkan waktu yang dihabiskan antara transisi aktivitas.


Kalau kamu ingin menganalisis performance berdasarkan start time, end time, atau throughput, kamu juga bisa gunakan ini:

from pm4py.algo.performance.summarization.pandas import algorithm as performance_summarizer

df = pm4py.convert_to_dataframe(log)
summary = performance_summarizer.apply(df, parameters={"timestamp_key": "time:timestamp"})
print(summary)