Skip to main content

Package for Multi-Perspective Process Visualization

Project description

mpvis

A Python package for Multi-Perspective Process Visualization of event logs

Index

Installation

This package runs under Python 3.9+, use pip to install.

pip install mpvis

IMPORTANT To render and save generated diagrams, you will also need to install Graphviz

Documentation

This package has three main modules:

  • preprocessing has functionalities for log pruning based on top k variants and manual grouping of log activities.
  • mpdfg to discover and visualize Multi-Perspective Directly-Follows Graphs (DFG)
  • mddrt to discover and visualize Multi-Dimensional Directed-Rooted Trees (DRT)

Event Log Preprocessing

Format event log

Using mpvis.log_formatter you can format your own initial event log with the corresponding column names, based on pm4py standard way of naming logs columns.

The format dictionary to pass as argument to this function needs to have the following structure:

{
    "case:concept:name": <Case Id>, # required
    "concept:name": <Activity Id>, # required
    "time:timestamp": <Timestamp>, # required
    "start_timestamp": <Start Timestamp>, # optional
    "org:resource": <Resource>, # optional
    "cost:total": <Cost>, # optional
}

Each value of the dictionary needs to match the corresponding column name of the initial event log. If start_timestamp, org:resource and cost:total are not present in your event log, you can leave its values as blank strings.

import mpvis
import pandas as pd

raw_event_log = pd.read_csv("raw_event_log.csv")

format_dictionary = {
    "case:concept:name": "Case ID",
    "concept:name": "Activity",
    "time:timestamp": "Complete",
    "start_timestamp": "Start",
    "org:resource": "Resource",
    "cost:total": "Cost",
}

event_log = mpvis.log_formatter(raw_event_log, format_dictionary)

Manual log grouping of activities

Groups specified activities in a process log into a single activity group. Every activity name in activities_to_group needs to be in the event log activity column.

from mpvis import preprocessing

activities_to_group = ["A", "B", "C"]

manual_grouped_log = preprocessing.manual_log_grouping(
    event_log=event_log,
    activities_to_group=activities_to_group,
    group_name="Grouped Activities" # Optional
    )

Log pruning by number of variants

This function filters the event log to keep only the top k variants based on their frequency. Variants are different sequences of activities in the event log.

from mpvis import preprocessing

#k is the number of variants to keep
pruned_log_by_variants = preprocessing.prune_log_based_on_top_variants(event_log, k=3)

Multi-Perspective Directly-Follows Graph (Discovery / Visualization)

Discover Multi Perspective DFG

Discovers a multi-perspective Directly-Follows Graph (DFG) from a log.

from mpvis import mpdfg

(
    multi_perspective_dfg,
    start_activities,
    end_activities,
) = mpdfg.discover_multi_perspective_dfg(
    event_log,
    calculate_cost=True,
    calculate_frequency=True,
    calculate_time=True,
    frequency_statistic="absolute-activity", # or absolute-case, relative-activity, relative-case
    time_statistic="mean", # or sum, max, min, stdev, median
    cost_statistic="mean", # or sum, max, min, stdev, median
)

Filter DFG by activities

Filters activities of a multi-perspective Directly-Follows Graph (DFG) diagram.

from mpvis import mpdfg

activities_filtered_multi_perspective_dfg = mpdfg.filter_multi_perspective_dfg_activities(
    percentage=0.5,
    dfg=multi_perspective_dfg,
    start_activities=start_activities,
    end_activities=end_activities,
    sort_by="frequency",
    ascending=True,
)

Filter DFG by paths

Filters paths of a multi-perspective Directly-Follows Graph (DFG) diagram.

from mpvis import mpdfg

activities_filtered_multi_perspective_dfg = mpdfg.filter_multi_perspective_dfg_paths(
    percentage=0.5,
    dfg=multi_perspective_dfg,
    start_activities=start_activities,
    end_activities=end_activities,
    sort_by="frequency",
    ascending=True,
)

Get the DFG diagram string representation

Creates a string representation of a multi-perspective Directly-Follows Graph (DFG) diagram.

mpdfg_string = mpdfg.get_multi_perspective_dfg_string(
    multi_perspective_dfg,
    start_activities,
    end_activities,
    visualize_frequency=True,
    visualize_time=True,
    visualize_cost=True,
    rankdir="TB", # or BT, LR, RL, etc.
    diagram_tool="graphviz", # or mermaid
)

View the generated DFG diagram

Allows the user to view the diagram in interactive Python environments like Jupyter and Google Colab.

mpdfg.view_multi_perspective_dfg(
    multi_perspective_dfg,
    start_activities,
    end_activities,
    visualize_frequency=True,
    visualize_time=True,
    visualize_cost=True,
    rankdir="TB", # or BT, LR, RL, etc.
)

Save the generated DFG diagram

mpdfg.save_vis_multi_perspective_dfg(
    multi_perspective_dfg,
    start_activities,
    end_activities,
    file_name="diagram",
    visualize_frequency=True,
    visualize_time=True,
    visualize_cost=True,
    format="png", # or pdf, webp, svg, etc.
    rankdir="TB", # or BT, LR, RL, etc.
    diagram_tool="graphviz", # or mermaid
)

Multi-Dimensional Directed-Rooted Tree (Discovery / Visualization)

Discover Multi-Dimensional DRT

Discovers and constructs a multi-dimensional Directly Rooted Tree (DRT) from the provided event log.

This function analyzes an event log and creates a multi-dimensional Directly Rooted Tree (DRT) representing the process model. The DRT is built based on various dimensions such as time, cost, quality, and flexibility, according to the specified parameters.

from mpvis import mddrt

drt = mddrt.discover_multi_dimensional_drt(
    event_log,
    calculate_cost=True,
    calculate_time=True,
    calculate_flexibility=True,
    calculate_quality=True,
    group_activities=False,
    show_names=False
)

Get the DRT diagram string representation

Generates a string representation of a multi-dimensional directly rooted tree (DRT) diagram.

mddrt_string = mddrt.get_multi_dimension_drt_string(
    multi_dimensional_drt,
    visualize_time=True,
    visualize_cost=True,
    visualize_quality=True,
    visualize_flexibility=True
)

View the generated DRT diagram

Allows the user to view the diagram in interactive Python environments like Jupyter and Google Colab.

mddrt.view_multi_dimensional_drt(
    multi_dimensional_drt
    visualize_time=True,
    visualize_cost=True,
    visualize_quality=True,
    visualize_flexibility=True,
    node_measures=["total"], # accepts also "consumed" and "remaining"
    arc_measures=[], # accepts "avg", "min" and "max", or you can keep this argument empty
    format="svg" # Format value should be a valid image extension like 'jpg', 'png', 'jpeq' or 'webp
)

WARNING Not all output file formats of Graphviz are available to display in environments like Jupyter Notebook or Google Colab.

Save the generated DRT diagram

Saves a visualization of a multi-dimensional directly rooted tree (DRT) to a file.

mddrt.save_vis_multi_dimensional_drt(
    multi_dimensional_drt
    file_path="diagram",
    visualize_time=True,
    visualize_cost=True,
    visualize_quality=True,
    visualize_flexibility=True,
    node_measures=["total"], # accepts also "consumed" and "remaining"
    arc_measures=[], # accepts "avg", "min" and "max", or you can keep this argument empty
    format="svg", # or pdf, webp, svg, etc.
)

Examples

Checkout Examples to see the package being used to visualize an event log of a mining process.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpvis-1.0.2.tar.gz (19.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mpvis-1.0.2-py3-none-any.whl (68.6 kB view details)

Uploaded Python 3

File details

Details for the file mpvis-1.0.2.tar.gz.

File metadata

  • Download URL: mpvis-1.0.2.tar.gz
  • Upload date:
  • Size: 19.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for mpvis-1.0.2.tar.gz
Algorithm Hash digest
SHA256 4bece06c9ad6160561ffa506b865e3794e68f1b0be715651ef4139b27cd28bf3
MD5 493d37edc1e3e39a8f9d29cbdcebd9c2
BLAKE2b-256 e94ccf5751d335d756acacffda6fffcc96d2082b9455f3dc4cccaa3915df7ac8

See more details on using hashes here.

Provenance

The following attestation bundles were made for mpvis-1.0.2.tar.gz:

Publisher: python-publish.yml on nicoabarca/mpvis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mpvis-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: mpvis-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 68.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for mpvis-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a02efdc638b5c551b111fff9c6a4907a148a96c836cd452e5eaf5ceaace3f8c6
MD5 196a1224d50faebbb3f8c9e3c9ca0957
BLAKE2b-256 5f874a92ae59b1f792bc45698b9fe8483d77b2a136c4e7ecb0a4baf7fbf3a992

See more details on using hashes here.

Provenance

The following attestation bundles were made for mpvis-1.0.2-py3-none-any.whl:

Publisher: python-publish.yml on nicoabarca/mpvis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page