Source code for pm4py.visualization.transition_system.variants.trans_frequency

    This file is part of PM4Py (More Info:

    PM4Py is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    PM4Py is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PM4Py.  If not, see <>.
import uuid

from typing import Optional, Dict, Any, Union
from pm4py.objects.transition_system.obj import TransitionSystem
import graphviz

import tempfile

from graphviz import Digraph
from pm4py.util import exec_utils
from enum import Enum

[docs]class Parameters(Enum): FORMAT = "format" BGCOLOR = "bgcolor"
[docs]def get_perc(total_events, arc_events): if total_events > 0: return " " + str(total_events) + " / %.2f %%" % (100.0 * arc_events / total_events) return " 0 / 0.00 %"
[docs]def apply(tsys: TransitionSystem, parameters: Optional[Dict[Union[str, Parameters], Any]] = None) -> graphviz.Digraph: if parameters is None: parameters = {} image_format = exec_utils.get_param_value(Parameters.FORMAT, parameters, "png") bgcolor = exec_utils.get_param_value(Parameters.BGCOLOR, parameters, "transparent") filename = tempfile.NamedTemporaryFile(suffix='.gv') viz = Digraph(,, engine='dot', graph_attr={'bgcolor': bgcolor}) states_dictio = {} for s in tsys.states: node_uuid = str(uuid.uuid4()) states_dictio[id(s)] = node_uuid sum_ingoing = 0 sum_outgoing = 0 for t in s.incoming: sum_ingoing += len(["events"]) for t in s.outgoing: sum_outgoing += len(["events"]) fillcolor = "white" if sum_ingoing != len(["ingoing_events"]) or sum_outgoing != len(["outgoing_events"]): fillcolor = "red" taillabel = get_perc(sum_ingoing, len(["ingoing_events"])) headlabel = get_perc(sum_outgoing, len(["outgoing_events"])) label = "IN=" + taillabel + "\n" + str( + "\nOUT=" + headlabel viz.node(node_uuid, label=label, fontsize="10", style="filled", fillcolor=fillcolor) for t in tsys.transitions: viz.edge(states_dictio[id(t.from_state)], states_dictio[id(t.to_state)], fontsize="8", label=str(, taillabel=get_perc(len(["outgoing_events"]), len(["events"])), headlabel=get_perc(len(["ingoing_events"]), len(["events"]))) viz.attr(overlap='false') viz.format = image_format return viz