Example #1
0
def save_vis_petri_net(petri_net, initial_marking, final_marking, file_path):
    """
    Saves a Petri net visualization to a file

    Parameters
    --------------
    petri_net
        Petri net
    initial_marking
        Initial marking
    final marking
        Final marking
    file_path
        Destination path
    """
    format = file_path[file_path.index(".") + 1:].lower()
    from pm4py.visualization.petrinet import visualizer as pn_visualizer
    gviz = pn_visualizer.apply(
        petri_net,
        initial_marking,
        final_marking,
        parameters={
            pn_visualizer.Variants.WO_DECORATION.value.Parameters.FORMAT:
            format
        })
    pn_visualizer.save(gviz, file_path)
Example #2
0
def svg(net_im_fm, kwargs0):
    kwargs = copy(kwargs0)
    gviz = pn_visualizer.apply(net_im_fm[0],
                               net_im_fm[1],
                               net_im_fm[2],
                               parameters={"format": "svg"})
    temp_file = NamedTemporaryFile(suffix=".svg")
    temp_file.close()
    pn_visualizer.save(gviz, temp_file.name)
    F = open(temp_file.name, "r")
    content = F.read()
    F.close()
    return content
Example #3
0
    def test_52(self):
        # creating an empty Petri net
        from pm4py.objects.petri.petrinet import PetriNet, Marking
        net = PetriNet("new_petri_net")

        # creating source, p_1 and sink place
        source = PetriNet.Place("source")
        sink = PetriNet.Place("sink")
        p_1 = PetriNet.Place("p_1")
        # add the places to the Petri Net
        net.places.add(source)
        net.places.add(sink)
        net.places.add(p_1)

        # Create transitions
        t_1 = PetriNet.Transition("name_1", "label_1")
        t_2 = PetriNet.Transition("name_2", "label_2")
        # Add the transitions to the Petri Net
        net.transitions.add(t_1)
        net.transitions.add(t_2)

        # Add arcs
        from pm4py.objects.petri import utils
        utils.add_arc_from_to(source, t_1, net)
        utils.add_arc_from_to(t_1, p_1, net)
        utils.add_arc_from_to(p_1, t_2, net)
        utils.add_arc_from_to(t_2, sink, net)

        # Adding tokens
        initial_marking = Marking()
        initial_marking[source] = 1
        final_marking = Marking()
        final_marking[sink] = 1

        from pm4py.objects.petri.exporter import exporter as pnml_exporter
        pnml_exporter.apply(net, initial_marking, "createdPetriNet1.pnml", final_marking=final_marking)

        from pm4py.visualization.petrinet import visualizer as pn_visualizer
        gviz = pn_visualizer.apply(net, initial_marking, final_marking)

        from pm4py.visualization.petrinet import visualizer as pn_visualizer
        parameters = {pn_visualizer.Variants.WO_DECORATION.value.Parameters.FORMAT: "svg"}
        gviz = pn_visualizer.apply(net, initial_marking, final_marking, parameters=parameters)

        from pm4py.visualization.petrinet import visualizer as pn_visualizer
        parameters = {pn_visualizer.Variants.WO_DECORATION.value.Parameters.FORMAT: "svg"}
        gviz = pn_visualizer.apply(net, initial_marking, final_marking, parameters=parameters)
        pn_visualizer.save(gviz, "alpha.svg")

        os.remove("createdPetriNet1.pnml")
        os.remove("alpha.svg")
Example #4
0
        def function_before_get(b_click):
            if b_click == 1:
                pn_visualizer.save(before_gviz, "clean_process.png")
                messagebox.showinfo("Message", "Downloaded in 'output' folder")

            else:
                before = self.before

                if self.a == 1:
                    before = before[[
                        'Case', 'Activity', "Timestamp", "Resource"
                    ]]
                    before.rename(
                        columns={
                            "Case": "case:concept:name",
                            "Activity": "concept:name",
                            "Timestamp": "time:timestamp",
                            "Resource": "Resource"
                        })
                    before.columns = [
                        'case:concept:name', 'concept:name', "time:timestamp",
                        "Resource"
                    ]
                elif self.a == 0 and self.b == 1:
                    before = before[[
                        'Case', 'Activity', "Timestamp", "System"
                    ]]
                    before.rename(
                        columns={
                            "Case": "case:concept:name",
                            "Activity": "concept:name",
                            "Timestamp": "time:timestamp",
                            "System": "Resource"
                        })

                    before.columns = [
                        'case:concept:name', 'concept:name', "time:timestamp",
                        "Resource"
                    ]

                before_log = log_converter.apply(before)
                b_net, b_initial_marking, b_final_marking = inductive_miner.apply(
                    before_log)
                before_gviz = pn_visualizer.apply(b_net, b_initial_marking,
                                                  b_final_marking)
                b_click = 1
                pn_visualizer.save(
                    before_gviz, "{}_clean_process.png".format(self.dat_name))
                messagebox.showinfo("Message", "Downloaded in 'output' folder")

            return b_click
Example #5
0
def visualize_as_petri_net(net, initial_marking, final_marking, path=''):
    if len(path) > 0:
        parameters = {
            pn_visualizer.Variants.WO_DECORATION.value.Parameters.FORMAT: "svg"
        }
        gviz = pn_visualizer.apply(net,
                                   initial_marking,
                                   final_marking,
                                   parameters=parameters)
        pn_visualizer.save(gviz, path)
    else:
        gviz = pn_vis_factory.apply(net, initial_marking, final_marking)
        pn_vis_factory.view(gviz)
    return net, initial_marking, final_marking
Example #6
0
    def test_47(self):
        log = self.load_running_example_xes()

        import os
        from pm4py.algo.discovery.inductive import algorithm as inductive_miner
        net, initial_marking, final_marking = inductive_miner.apply(log)

        from pm4py.visualization.petrinet import visualizer as pn_visualizer
        parameters = {pn_visualizer.Variants.WO_DECORATION.value.Parameters.FORMAT: "png"}
        gviz = pn_visualizer.apply(net, initial_marking, final_marking, parameters=parameters,
                                   variant=pn_visualizer.Variants.FREQUENCY, log=log)
        pn_visualizer.save(gviz, os.path.join("test_output_data", "inductive_frequency.png"))

        os.remove(os.path.join("test_output_data", "inductive_frequency.png"))
Example #7
0
        def function_after_get(a_click):
            if a_click == 1:
                pn_visualizer.save(after_gviz, "anomaly_process.png")
                messagebox.showinfo("Message", "Downloaded in 'output' folder")

            else:
                after = self.after

                if self.a == 1:
                    after = after[[
                        'Case', 'Activity', "Timestamp", "Resource"
                    ]]
                    after.rename(
                        columns={
                            "Case": "case:concept:name",
                            "Activity": "concept:name",
                            "Timestamp": "time:timestamp",
                            "Resource": "Resource"
                        })
                    after.columns = [
                        'case:concept:name', 'concept:name', "time:timestamp",
                        "Resource"
                    ]
                elif self.a == 0 and self.b == 1:
                    after = after[['Case', 'Activity', "Timestamp", "System"]]
                    after.rename(
                        columns={
                            "Case": "case:concept:name",
                            "Activity": "concept:name",
                            "Timestamp": "time:timestamp",
                            "System": "Resource"
                        })

                    after.columns = [
                        'case:concept:name', 'concept:name', "time:timestamp",
                        "Resource"
                    ]

                after_log = log_converter.apply(after)
                a_net, a_initial_marking, a_final_marking = inductive_miner.apply(
                    after_log)
                after_gviz = pn_visualizer.apply(a_net, a_initial_marking,
                                                 a_final_marking)
                a_click = 1
                pn_visualizer.save(
                    after_gviz, "{}_anomaly_process.png".format(self.dat_name))
                messagebox.showinfo("Message", "Downloaded in 'output' folder")

            return a_click
Example #8
0
def strongly_test():
    net = preprocess(example_graph)
    print(net)
    initial_marking = Marking()
    final_marking = Marking()
    for place in net.places:
        if place.name != "p2":
            initial_marking[place] = 1
        else:
            final_marking[place] = 1

    parameters = {
        pn_visualizer.Variants.WO_DECORATION.value.Parameters.FORMAT: "svg"
    }
    gviz = pn_visualizer.apply(net,
                               initial_marking,
                               final_marking,
                               parameters=parameters)
    pn_visualizer.save(gviz, "alpha.svg")
Example #9
0
def save_graph_file(type, gviz, path):
    if type == "alpha":
        pn_visualizer.save(gviz, path)
    elif type == "heuristic-heu-net":
        hn_visualizer.save(gviz, path)
    elif type == "heuristic-pet-net":
        pn_visualizer.save(gviz, path)
    elif type == "dfg-discovery-frequency":
        dfg_visualization.save(gviz, path)
    elif type == "dfg-discovery-active-time":
        dfg_visualization.save(gviz, path)
    elif type == "dfg-discovery-pet-net":
        pt_visualizer.save(gviz, path)
    elif type == "inductive-miner-tree":
        pt_visualizer.save(gviz, path)
    elif type == "inductive-miner-petri":
        pn_visualizer.save(gviz, path)
Example #10
0
    columns={
        'case concept:name': 'case:concept:name',
        'event concept:name': 'concept:name',
        'event time:timestamp': 'time:timestamp'
    })
df_2012_Test = pd.read_csv('..\.\data\BPI2012Test.csv')

# Parse data
# (df_2012, df_2012_last_event_per_case) = parseData(df_2012)
# (df_2012_Test, df_2012_last_event_per_case_Test) = parseData(df_2012_Test)

df_2012 = dataframe_utils.convert_timestamp_columns_in_df(df_2012)
df_2012 = df_2012.sort_values(by='time:timestamp')

log = log_converter.apply(df_2012)

# alpha miner
net, initial_marking, final_marking = alpha_miner.apply(log)

# add information about frequency to the viz
parameters = {pn_visualizer.Variants.FREQUENCY.value.Parameters.FORMAT: "png"}
gviz = pn_visualizer.apply(net,
                           initial_marking,
                           final_marking,
                           parameters=parameters,
                           variant=pn_visualizer.Variants.FREQUENCY,
                           log=log)

# save the Petri net
pn_visualizer.save(gviz, "alpha_miner_petri_net.png")
Example #11
0
from pm4py.objects.log.importer.xes import importer as xes_importer
from pm4py.algo.discovery.inductive import algorithm as inductive_miner
import sys
from pm4py.algo.discovery.inductive.parameters import Parameters
from pm4py.visualization.petrinet import visualizer as pn_visualizer

log_path = sys.argv[1]
out_path = sys.argv[2]

log = xes_importer.apply(log_path)
parameters = {Parameters.NOISE_THRESHOLD: 0.20}
model, initial_marking, final_marking = inductive_miner.apply(
    log, parameters, variant=inductive_miner.Variants.IMf)

parameters = {
    pn_visualizer.Variants.WO_DECORATION.value.Parameters.FORMAT: "png"
}
gviz = pn_visualizer.apply(model, initial_marking, final_marking, parameters)
pn_visualizer.save(gviz, out_path)
Example #12
0
from pm4py.algo.discovery.dfg import algorithm as dfg_discovery
dfg = dfg_discovery.apply(log)

from pm4py.objects.conversion.dfg import converter as dfg_mining
net, im, fm = dfg_mining.apply(dfg)
net
im
fm


#Adding info about freq/ performance
from pm4py.visualization.petrinet import visualizer as pn_visualizer
parameters = {pn_visualizer.Variants.FREQUENCY.value.Parameters.FORMAT: "png"}
gviz = pn_visualizer.apply(net, initial_marking, final_marking, parameters=parameters, variant=pn_visualizer.Variants.FREQUENCY, log=log)
pn_visualizer.save(gviz, "inductive_frequency.png")


#classifier
import os
from pm4py.objects.log.importer.xes import importer as xes_importer
from pm4py.algo.discovery.alpha import algorithm as alpha_miner
log = xes_importer.apply(filepath)
parameters = {alpha_miner.Variants.ALPHA_CLASSIC.value.Parameters.ACTIVITY_KEY: "concept:name"}
net, initial_marking, final_marking = alpha_miner.apply(log, parameters=parameters)

net
initial_marking
final_marking

#-----
Example #13
0
from pm4py.algo.discovery.alpha import algorithm as alpha_miner
from pm4py.algo.discovery.inductive import algorithm as inductive_miner
from pm4py.algo.discovery.heuristics import algorithm as heuristics_miner
from pm4py.algo.discovery.dfg import algorithm as dfg_discovery

# viz
from pm4py.visualization.petrinet import visualizer as pn_visualizer
from pm4py.visualization.process_tree import visualizer as pt_visualizer
from pm4py.visualization.heuristics_net import visualizer as hn_visualizer
from pm4py.visualization.dfg import visualizer as dfg_visualization

# misc
from pm4py.objects.conversion.process_tree import converter as pt_converter
from pm4py.objects.conversion.log import factory as log_conv_factory

#Tilføye en mer kompleks log

from pm4py.objects.log.adapters.pandas import csv_import_adapter as csv_importer

df = csv_importer.import_dataframe_from_path("receipt.csv")
log = log_conv_factory.apply(df)
from pm4py.algo.discovery.inductive import factory as inductive_miner

net, im, fm = inductive_miner.apply(log)

from pm4py.visualization.petrinet import factory as pn_vis_factory

gviz = pn_vis_factory.apply(net, im, fm)
pn_visualizer.save(gviz, "inductive_miner_recipt.png")
pn_vis_factory.view(gviz)