Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions examples/dcr_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import pm4py
import os

def execute_discover():
"""
example script to discover dcr graph from event log
"""

log = pm4py.read_xes(os.path.join("..","tests","input_data","running-example.xes"))

#return the graph and the log abstraction used for mining
graph, _ = pm4py.discover_dcr(log)
print(graph)

def execute_discover_roles():
"""
example script to discover dcr graph with orginazational information
"""
log = pm4py.read_xes(os.path.join("..","tests","input_data","running-example.xes"))
# is initaitad with the set of wanted post process types after the original discover miner
# if no standard default group key is present, but org:resource is present, can specify
graph, _ = pm4py.discover_dcr(log, post_process={'distributed'}, group_key='org:resource')
print(graph)

def execute_dcr_conformance():
"""
example script of how to call and check for conformance of dcr graph
"""
log = pm4py.read_xes(os.path.join("..","tests","input_data","receipt.xes"))

# is initaitad with the set of wanted post process types after the original discover miner
# if no standard default group key is present, but org:resource is present, can specify to mine org:resource as distributed
graph_base, _ = pm4py.discover_dcr(log)
graph_roles, _ = pm4py.discover_dcr(log, post_process={'distributed'})

#DisCoveR discovers a perfect fitting graph from event log
conf_res_base = pm4py.conformance_dcr(log, graph_base, return_diagnostics_dataframe=True)
print(conf_res_base)

log.replace("Group 1",float("nan"))

#if distributed are present in the graph, will then by default check conformance for correct assignment of distributed to activities
#dropped a role, cause deviation
conf_res_roles = pm4py.conformance_dcr(log, graph_base, return_diagnostics_dataframe=True)
print("both runs")
print(conf_res_roles)

def execute_dcr_alignment():
"""
run of the alignment of dcr graphs

"""
log = pm4py.read_xes(os.path.join("..","tests","input_data","running-example.xes"))

#discover base dcr graph, does not support dcr graphs with distributed
graph, _ = pm4py.discover_dcr(log)

align_res = pm4py.optimal_alignment_dcr(log, graph,return_diagnostics_dataframe=True)
print(align_res)

#work with the visualization
align_res = pm4py.optimal_alignment_dcr(log, graph)

#works with view_alignments()
pm4py.view_alignments(log, align_res, format='svg')

def execute_import_export():
"""
import and export of dcr graphs
"""
from pm4py.objects.dcr.exporter.exporter import Variants
log = pm4py.read_xes(os.path.join("..","tests","input_data","running-example.xes"))
graph, _ = pm4py.discover_dcr(log)

#currently only support the base dcr graph
pm4py.write_dcr_xml(graph,path=os.path.join("..","tests","test_output_data","dcr.xml"),
variant=Variants.XML_DCR_PORTAL, dcr_title="dcr graph of running-example")

graph = pm4py.read_dcr_xml(file_path=os.path.join("..","tests","test_output_data","dcr.xml"))
print(graph)


if __name__ == "__main__":
execute_discover()
execute_discover_roles()
execute_dcr_alignment()
execute_dcr_conformance()
execute_import_export()
1,264 changes: 1,264 additions & 0 deletions notebooks/dcr_tutorial.ipynb

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions pm4py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

from pm4py import util, objects, statistics, algo, visualization, llm, connectors
from pm4py import analysis, conformance, convert, discovery, filtering, hof, ml, ocel, org, read, sim, stats, utils, vis, write
from pm4py.read import read_xes, read_dfg, read_bpmn, read_pnml, read_ptml, read_ocel, read_ocel_csv, read_ocel_xml, read_ocel_json, read_ocel_sqlite, read_ocel2, read_ocel2_sqlite, read_ocel2_json, read_ocel2_xml
from pm4py.write import write_xes, write_dfg, write_bpmn, write_pnml, write_ptml, write_ocel, write_ocel_json, write_ocel_csv, write_ocel_xml, write_ocel_sqlite, write_ocel2, write_ocel2_sqlite, write_ocel2_xml, write_ocel2_json
from pm4py.read import read_xes, read_dfg, read_bpmn, read_pnml, read_ptml, read_ocel, read_ocel_csv, read_ocel_xml, read_ocel_json, read_ocel_sqlite, read_ocel2, read_ocel2_sqlite, read_ocel2_json, read_ocel2_xml, read_dcr_xml
from pm4py.write import write_xes, write_dfg, write_bpmn, write_pnml, write_ptml, write_ocel, write_ocel_json, write_ocel_csv, write_ocel_xml, write_ocel_sqlite, write_ocel2, write_ocel2_sqlite, write_ocel2_xml, write_ocel2_json, write_dcr_xml
from pm4py.utils import format_dataframe, parse_process_tree, serialize, deserialize, set_classifier, parse_event_log_string, project_on_event_attribute, \
sample_cases, sample_events, rebase, parse_powl_model_string
from pm4py.filtering import filter_log_relative_occurrence_event_attribute, filter_start_activities, filter_end_activities, filter_variants, \
Expand All @@ -35,13 +35,13 @@
discover_petri_net_inductive, discover_process_tree_inductive, discover_heuristics_net, \
discover_dfg, discover_footprints, discover_eventually_follows_graph, discover_directly_follows_graph, discover_bpmn_inductive, \
discover_performance_dfg, discover_transition_system, discover_prefix_tree, \
discover_temporal_profile, discover_log_skeleton, discover_batches, derive_minimum_self_distance, discover_dfg_typed, discover_declare, discover_powl
discover_temporal_profile, discover_log_skeleton, discover_batches, derive_minimum_self_distance, discover_dfg_typed, discover_declare, discover_powl, discover_dcr
from pm4py.conformance import conformance_diagnostics_token_based_replay, conformance_diagnostics_alignments, \
fitness_token_based_replay, \
fitness_alignments, precision_token_based_replay, \
precision_alignments, conformance_diagnostics_footprints, \
fitness_footprints, precision_footprints, check_is_fitting, conformance_temporal_profile, \
conformance_declare, conformance_log_skeleton, replay_prefix_tbr, generalization_tbr
conformance_declare, conformance_log_skeleton, replay_prefix_tbr, generalization_tbr, conformance_dcr, optimal_alignment_dcr
from pm4py.ocel import ocel_objects_interactions_summary, ocel_temporal_summary, ocel_objects_summary, ocel_get_object_types, ocel_get_attribute_names, ocel_flattening, ocel_object_type_activities, ocel_objects_ot_count, \
discover_ocdfg, discover_oc_petri_net, discover_objects_graph, sample_ocel_objects, ocel_drop_duplicates, ocel_merge_duplicates, ocel_sort_by_additional_column, \
ocel_add_index_based_timedelta, sample_ocel_connected_components, ocel_o2o_enrichment, ocel_e2o_lifecycle_enrichment, cluster_equivalent_ocel
Expand All @@ -52,7 +52,7 @@
save_vis_events_per_time_graph, view_events_distribution_graph, save_vis_events_distribution_graph, view_performance_dfg, save_vis_performance_dfg, \
view_ocpn, save_vis_ocpn, view_network_analysis, save_vis_network_analysis, view_transition_system, save_vis_transition_system, \
view_prefix_tree, save_vis_prefix_tree, view_object_graph, save_vis_object_graph, view_alignments, save_vis_alignments, \
view_footprints, save_vis_footprints, view_powl, save_vis_powl
view_footprints, save_vis_footprints, view_powl, save_vis_powl, view_dcr, save_vis_dcr
from pm4py.convert import convert_to_event_log, convert_to_event_stream, convert_to_dataframe, convert_to_bpmn, \
convert_to_petri_net, convert_to_process_tree, convert_to_reachability_graph, convert_log_to_ocel, convert_ocel_to_networkx, convert_log_to_networkx, \
convert_log_to_time_intervals, convert_petri_net_to_networkx, convert_petri_net_type
Expand All @@ -78,5 +78,6 @@
from pm4py.objects.process_tree.obj import ProcessTree
from pm4py.objects.ocel.obj import OCEL
from pm4py.objects.bpmn.obj import BPMN
from pm4py.objects.dcr.obj import DcrGraph

time.clock = time.process_time
1 change: 1 addition & 0 deletions pm4py/algo/conformance/alignments/dcr/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from pm4py.algo.conformance.alignments.dcr import variants, algorithm
Binary file not shown.
Binary file not shown.
60 changes: 60 additions & 0 deletions pm4py/algo/conformance/alignments/dcr/algorithm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from pm4py.algo.conformance.alignments.dcr.variants import optimal
from enum import Enum
from pm4py.util import exec_utils
from pm4py.objects.dcr.obj import DcrGraph
from pm4py.objects.log.obj import EventLog, Trace
from typing import Optional, Dict, Any, Union, Tuple, List
from pm4py.util import typing
import pandas as pd


class Variants(Enum):
OPTIMAL = optimal


def apply(obj: Union[EventLog, Trace], G: DcrGraph, variant=Variants.OPTIMAL, parameters: Optional[Dict[Any, Any]] = None) -> Union[typing.AlignmentResult, typing.ListAlignments]:
"""
Applies the alignment algorithm provided a log/trace object, and a DCR graph.

Parameters
--------------
obj
Event log / Trace
G
DCR graph
variant
Variant of the DCR alignments to be used. Possible values:
- Variants.OPTIMAL
parameters
Variant-specific parameters.

Returns
--------------
ali
Result of the alignment
"""
return exec_utils.get_variant(variant).apply(obj, G, parameters=parameters)


def get_diagnostics_dataframe(log: Union[EventLog, pd.DataFrame], conf_result: List[Dict[str, Any]], variant=Variants.OPTIMAL, parameters=None) -> pd.DataFrame:
"""
Gets the diagnostics dataframe from a log and the conformance results

Parameters
--------------
log
Event log
conf_result
Results of conformance checking
variant
Variant to be used:
- Variants.CLASSIC
parameters
Variant-specific parameters

Returns
--------------
diagn_dataframe
Diagnostics dataframe
"""
return exec_utils.get_variant(variant).get_diagnostics_dataframe(log, conf_result, parameters)
1 change: 1 addition & 0 deletions pm4py/algo/conformance/alignments/dcr/variants/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from pm4py.algo.conformance.alignments.dcr.variants import optimal
Binary file not shown.
Binary file not shown.
Loading