Exemplo n.º 1
0
def execute_script():
    # imports a XES event log
    log = pm4py.read_xes(
        os.path.join("..", "tests", "input_data", "receipt.xes"))
    # converts the log into a list of events (not anymore grouped in cases)
    event_stream = pm4py.convert_to_event_stream(log)
    # calculates a process tree using the IMf algorithm (30% noise)
    net, im, fm = pm4py.discover_petri_net_inductive(log, noise_threshold=0.3)
    # creates a live event stream (an object that distributes the messages to the algorithm)
    live_stream = LiveEventStream()
    # creates the TBR streaming conformance checking object
    conf_obj = streaming_tbr.apply(net, im, fm)
    # register the conformance checking object to the live event stream
    live_stream.register(conf_obj)
    # start the recording of events from the live event stream
    live_stream.start()
    # append each event of the original log to the live event stream
    # (so it is sent to the conformance checking algorithm)
    for index, event in enumerate(event_stream):
        live_stream.append(event)
    #time.sleep(5)
    # stops the live event stream
    live_stream.stop()
    # sends a termination signal to the conformance checking algorithm;
    # the conditions on the closure of all the cases are checked
    # (for each case, it is checked whether the final marking is reached)
    diagn_df = conf_obj.get()
    conf_obj.terminate_all()
    print(diagn_df)
    print(diagn_df[diagn_df["is_fit"] == False])
Exemplo n.º 2
0
 def test_tbr_normal(self):
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log,
                                                      noise_threshold=0.2)
     replayed_traces = token_based_replay.apply(log, net, im, fm)
     diagn_df = token_based_replay.get_diagnostics_dataframe(
         log, replayed_traces)
Exemplo n.º 3
0
 def test_ext_marking_equation_sync_net(self):
     import pm4py
     log = pm4py.read_xes(os.path.join("input_data", "running-example.xes"))
     net, im, fm = pm4py.discover_petri_net_inductive(log)
     sync_net, sync_im, sync_fm = pm4py.construct_synchronous_product_net(log[0], net, im, fm)
     res = pm4py.solve_extended_marking_equation(log[0], sync_net, sync_im, sync_fm)
     self.assertIsNotNone(res)
Exemplo n.º 4
0
def execute_script():
    log = pm4py.read_xes(
        os.path.join("..", "tests", "input_data", "running-example.xes"))
    filtered_log = pm4py.filter_variants_top_k(log, 1)
    net, im, fm = pm4py.discover_petri_net_inductive(filtered_log)
    aligned_traces = alignments.apply(
        log, net, im, fm, parameters={"ret_tuple_as_trans_desc": True})
    enriched_log = log_enrichment.apply(log, aligned_traces)
    print(enriched_log)
Exemplo n.º 5
0
 def test_variant_dijkstra_less_memory(self):
     import pm4py
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log)
     align_alg.apply(
         log,
         net,
         im,
         fm,
         variant=align_alg.Variants.VERSION_DIJKSTRA_LESS_MEMORY)
Exemplo n.º 6
0
 def test_tbr_backwards(self):
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log,
                                                      noise_threshold=0.2)
     replayed_traces = token_based_replay.apply(
         log, net, im, fm, variant=token_based_replay.Variants.BACKWARDS)
     diagn_df = token_based_replay.get_diagnostics_dataframe(
         log,
         replayed_traces,
         variant=token_based_replay.Variants.BACKWARDS)
Exemplo n.º 7
0
 def test_variant_state_eq_a_star(self):
     import pm4py
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log)
     align_alg.apply(
         log,
         net,
         im,
         fm,
         variant=align_alg.Variants.VERSION_STATE_EQUATION_A_STAR)
Exemplo n.º 8
0
def discoverProcess(miner, log):

    if miner == "Alpha":
        petri_net, initial_marking, final_marking = pm4py.discover_petri_net_alpha(
            log)

    if miner == "Alpha+":
        petri_net, initial_marking, final_marking = pm4py.discover_petri_net_alpha_plus(
            log)

    if miner == "Heuristic":
        petri_net, initial_marking, final_marking = pm4py.discover_petri_net_heuristics(
            log)

    if miner == "Inductive":
        petri_net, initial_marking, final_marking = pm4py.discover_petri_net_inductive(
            log)

    return petri_net, initial_marking, final_marking
Exemplo n.º 9
0
 def test_precision_tbr(self):
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log)
     precision_tbr = pm4py.precision_token_based_replay(log, net, im, fm)
Exemplo n.º 10
0
 def test_precision_alignments(self):
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log)
     precision_ali = pm4py.precision_alignments(log, net, im, fm)
Exemplo n.º 11
0
 def test_tbr(self):
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log)
     replayed_traces = pm4py.conformance_diagnostics_token_based_replay(log, net, im, fm)
Exemplo n.º 12
0
 def test_alignments(self):
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log)
     aligned_traces = pm4py.conformance_diagnostics_alignments(log, net, im, fm)
Exemplo n.º 13
0
 def test_inductive_miner_noise(self):
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log, noise_threshold=0.5)
Exemplo n.º 14
0
 def test_inductive_miner(self):
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log)
Exemplo n.º 15
0
 def test_precision_tbr(self):
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log)
     precision_tbr = pm4py.evaluate_precision_tbr(log, net, im, fm)
Exemplo n.º 16
0
 def test_fitness_alignments(self):
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log)
     fitness_ali = pm4py.evaluate_fitness_alignments(log, net, im, fm)
Exemplo n.º 17
0
def execute_script():
    ENABLE_VISUALIZATION = True

    # reads a XES into an event log
    log1 = pm4py.read_xes("../tests/input_data/running-example.xes")

    # reads a CSV into a dataframe
    df = pd.read_csv("../tests/input_data/running-example.csv")
    # formats the dataframe with the mandatory columns for process mining purposes
    df = pm4py.format_dataframe(df,
                                case_id="case:concept:name",
                                activity_key="concept:name",
                                timestamp_key="time:timestamp")
    # converts the dataframe to an event log
    log2 = pm4py.convert_to_event_log(df)

    # converts the log read from XES into a stream and dataframe respectively
    stream1 = pm4py.convert_to_event_stream(log1)
    df2 = pm4py.convert_to_dataframe(log1)

    # writes the log1 to a XES file
    pm4py.write_xes(log1, "ru1.xes")

    dfg, dfg_sa, dfg_ea = pm4py.discover_dfg(log1)
    petri_alpha, im_alpha, fm_alpha = pm4py.discover_petri_net_alpha(log1)
    petri_inductive, im_inductive, fm_inductive = pm4py.discover_petri_net_inductive(
        log1)
    petri_heuristics, im_heuristics, fm_heuristics = pm4py.discover_petri_net_heuristics(
        log1)
    tree_inductive = pm4py.discover_tree_inductive(log1)
    heu_net = pm4py.discover_heuristics_net(log1)

    pm4py.write_dfg(dfg, dfg_sa, dfg_ea, "ru_dfg.dfg")
    pm4py.write_petri_net(petri_alpha, im_alpha, fm_alpha, "ru_alpha.pnml")
    pm4py.write_petri_net(petri_inductive, im_inductive, fm_inductive,
                          "ru_inductive.pnml")
    pm4py.write_petri_net(petri_heuristics, im_heuristics, fm_heuristics,
                          "ru_heuristics.pnml")
    pm4py.write_process_tree(tree_inductive, "ru_inductive.ptml")

    dfg, dfg_sa, dfg_ea = pm4py.read_dfg("ru_dfg.dfg")
    petri_alpha, im_alpha, fm_alpha = pm4py.read_petri_net("ru_alpha.pnml")
    petri_inductive, im_inductive, fm_inductive = pm4py.read_petri_net(
        "ru_inductive.pnml")
    petri_heuristics, im_heuristics, fm_heuristics = pm4py.read_petri_net(
        "ru_heuristics.pnml")
    tree_inductive = pm4py.read_process_tree("ru_inductive.ptml")

    pm4py.save_vis_petri_net(petri_alpha, im_alpha, fm_alpha, "ru_alpha.png")
    pm4py.save_vis_petri_net(petri_inductive, im_inductive, fm_inductive,
                             "ru_inductive.png")
    pm4py.save_vis_petri_net(petri_heuristics, im_heuristics, fm_heuristics,
                             "ru_heuristics.png")
    pm4py.save_vis_process_tree(tree_inductive, "ru_inductive_tree.png")
    pm4py.save_vis_heuristics_net(heu_net, "ru_heunet.png")
    pm4py.save_vis_dfg(dfg, dfg_sa, dfg_ea, "ru_dfg.png")

    if ENABLE_VISUALIZATION:
        pm4py.view_petri_net(petri_alpha, im_alpha, fm_alpha, format="svg")
        pm4py.view_petri_net(petri_inductive,
                             im_inductive,
                             fm_inductive,
                             format="svg")
        pm4py.view_petri_net(petri_heuristics,
                             im_heuristics,
                             fm_heuristics,
                             format="svg")
        pm4py.view_process_tree(tree_inductive, format="svg")
        pm4py.view_heuristics_net(heu_net, format="svg")
        pm4py.view_dfg(dfg, dfg_sa, dfg_ea, format="svg")

    aligned_traces = pm4py.conformance_alignments(log1, petri_inductive,
                                                  im_inductive, fm_inductive)
    replayed_traces = pm4py.conformance_tbr(log1, petri_inductive,
                                            im_inductive, fm_inductive)

    fitness_tbr = pm4py.evaluate_fitness_tbr(log1, petri_inductive,
                                             im_inductive, fm_inductive)
    print("fitness_tbr", fitness_tbr)
    fitness_align = pm4py.evaluate_fitness_alignments(log1, petri_inductive,
                                                      im_inductive,
                                                      fm_inductive)
    print("fitness_align", fitness_align)
    precision_tbr = pm4py.evaluate_precision_tbr(log1, petri_inductive,
                                                 im_inductive, fm_inductive)
    print("precision_tbr", precision_tbr)
    precision_align = pm4py.evaluate_precision_alignments(
        log1, petri_inductive, im_inductive, fm_inductive)
    print("precision_align", precision_align)

    print("log start activities = ", pm4py.get_start_activities(log2))
    print("df start activities = ", pm4py.get_start_activities(df2))
    print("log end activities = ", pm4py.get_end_activities(log2))
    print("df end activities = ", pm4py.get_end_activities(df2))
    print("log attributes = ", pm4py.get_attributes(log2))
    print("df attributes = ", pm4py.get_attributes(df2))
    print("log org:resource values = ",
          pm4py.get_attribute_values(log2, "org:resource"))
    print("df org:resource values = ",
          pm4py.get_attribute_values(df2, "org:resource"))

    print("start_activities len(filt_log) = ",
          len(pm4py.filter_start_activities(log2, ["register request"])))
    print("start_activities len(filt_df) = ",
          len(pm4py.filter_start_activities(df2, ["register request"])))
    print("end_activities len(filt_log) = ",
          len(pm4py.filter_end_activities(log2, ["pay compensation"])))
    print("end_activities len(filt_df) = ",
          len(pm4py.filter_end_activities(df2, ["pay compensation"])))
    print(
        "attributes org:resource len(filt_log) (cases) cases = ",
        len(
            pm4py.filter_attribute_values(log2,
                                          "org:resource", ["Ellen"],
                                          level="case")))
    print(
        "attributes org:resource len(filt_log) (cases)  events = ",
        len(
            pm4py.filter_attribute_values(log2,
                                          "org:resource", ["Ellen"],
                                          level="event")))
    print(
        "attributes org:resource len(filt_df) (events) cases = ",
        len(
            pm4py.filter_attribute_values(df2,
                                          "org:resource", ["Ellen"],
                                          level="case")))
    print(
        "attributes org:resource len(filt_df) (events) events = ",
        len(
            pm4py.filter_attribute_values(df2,
                                          "org:resource", ["Ellen"],
                                          level="event")))
    print(
        "attributes org:resource len(filt_df) (events) events notpositive = ",
        len(
            pm4py.filter_attribute_values(df2,
                                          "org:resource", ["Ellen"],
                                          level="event",
                                          retain=False)))

    print("variants log = ", pm4py.get_variants(log2))
    print("variants df = ", pm4py.get_variants(df2))
    print(
        "variants filter log = ",
        len(
            pm4py.filter_variants(log2, [[
                "register request", "examine thoroughly", "check ticket",
                "decide", "reject request"
            ]])))
    print(
        "variants filter df = ",
        len(
            pm4py.filter_variants(df2, [[
                "register request", "examine thoroughly", "check ticket",
                "decide", "reject request"
            ]])))
    print("variants filter percentage = ",
          len(pm4py.filter_variants_percentage(log2, threshold=0.8)))

    print(
        "paths filter log len = ",
        len(
            pm4py.filter_directly_follows_relation(
                log2, [("register request", "examine casually")])))
    print(
        "paths filter dataframe len = ",
        len(
            pm4py.filter_directly_follows_relation(
                df2, [("register request", "examine casually")])))

    print(
        "timeframe filter log events len = ",
        len(
            pm4py.filter_time_range(log2,
                                    "2011-01-01 00:00:00",
                                    "2011-02-01 00:00:00",
                                    mode="events")))
    print(
        "timeframe filter log traces_contained len = ",
        len(
            pm4py.filter_time_range(log2,
                                    "2011-01-01 00:00:00",
                                    "2011-02-01 00:00:00",
                                    mode="traces_contained")))
    print(
        "timeframe filter log traces_intersecting len = ",
        len(
            pm4py.filter_time_range(log2,
                                    "2011-01-01 00:00:00",
                                    "2011-02-01 00:00:00",
                                    mode="traces_intersecting")))
    print(
        "timeframe filter df events len = ",
        len(
            pm4py.filter_time_range(df2,
                                    "2011-01-01 00:00:00",
                                    "2011-02-01 00:00:00",
                                    mode="events")))
    print(
        "timeframe filter df traces_contained len = ",
        len(
            pm4py.filter_time_range(df2,
                                    "2011-01-01 00:00:00",
                                    "2011-02-01 00:00:00",
                                    mode="traces_contained")))
    print(
        "timeframe filter df traces_intersecting len = ",
        len(
            pm4py.filter_time_range(df2,
                                    "2011-01-01 00:00:00",
                                    "2011-02-01 00:00:00",
                                    mode="traces_intersecting")))

    # remove the temporary files
    os.remove("ru1.xes")
    os.remove("ru_dfg.dfg")
    os.remove("ru_alpha.pnml")
    os.remove("ru_inductive.pnml")
    os.remove("ru_heuristics.pnml")
    os.remove("ru_inductive.ptml")
    os.remove("ru_alpha.png")
    os.remove("ru_inductive.png")
    os.remove("ru_heuristics.png")
    os.remove("ru_inductive_tree.png")
    os.remove("ru_heunet.png")
    os.remove("ru_dfg.png")
Exemplo n.º 18
0
 def test_marking_equation_net(self):
     import pm4py
     log = pm4py.read_xes(os.path.join("input_data", "running-example.xes"))
     net, im, fm = pm4py.discover_petri_net_inductive(log)
     pm4py.solve_marking_equation(net, im, fm)
Exemplo n.º 19
0
 def test_align(self):
     log = pm4py.read_xes("input_data/running-example.xes")
     net, im, fm = pm4py.discover_petri_net_inductive(log,
                                                      noise_threshold=0.2)
     aligned_traces = alignments.apply(log, net, im, fm)
     diagn_df = alignments.get_diagnostics_dataframe(log, aligned_traces)