Difference between revisions of "Pm4py: analisa performance dari xes"

From OnnoWiki
Jump to navigation Jump to search
Line 5: Line 5:
 
   
 
   
 
  import pm4py
 
  import pm4py
  from pm4py.objects.log.importer.xes import factory as xes_importer
+
  from pm4py.objects.log.importer.xes import importer as xes_importer
  from pm4py.algo.performance.spectrum import algorithm as performance_spectrum
+
  from pm4py.algo.discovery.performance_spectrum import algorithm as performance_spectrum
 +
from pm4py.algo.discovery.performance_spectrum import visualizer as performance_spectrum_visualizer
 +
from pm4py.algo.filtering.log.attributes import attributes_filter
 
   
 
   
  # 1. Load XES event log
+
  # 1. Memuat log peristiwa dari file XES
 
  log = xes_importer.apply("Production.xes")
 
  log = xes_importer.apply("Production.xes")
 
   
 
   
  # 2. Apply performance spectrum algorithm
+
  # 2. Mengidentifikasi aktivitas unik dalam log
  spectrum = performance_spectrum.apply(log)
+
  activities = attributes_filter.get_attribute_values(log, "concept:name")
 +
list_activities = list(activities.keys())
 
   
 
   
  # 3. Tampilkan hasil awal
+
  # 3. Menerapkan algoritma performance spectrum
  print(spectrum.head())
+
  ps = performance_spectrum.apply(log, list_activities)
 +
 +
# 4. Memvisualisasikan hasil performance spectrum
 +
gviz = performance_spectrum_visualizer.apply(ps)
 +
performance_spectrum_visualizer.view(gviz)
 +
 
  
  

Revision as of 07:51, 30 March 2025

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.algo.discovery.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
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)