Vinyeh commited on
Commit
49aaacd
·
verified ·
1 Parent(s): 1c4d287

Add pinned source: pm4py-process (part 2)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_alignments.py +105 -0
  2. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_bert.py +71 -0
  3. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_count2vec.py +83 -0
  4. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_doc2vec.py +70 -0
  5. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_n_grams.py +91 -0
  6. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_one_hot.py +86 -0
  7. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_tf_idf.py +80 -0
  8. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_token_replay.py +105 -0
  9. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_word2vec.py +77 -0
  10. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trans_system_stochastic_vis.py +22 -0
  11. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/transform_db_to_ocel.py +136 -0
  12. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/transform_db_to_ocel_2.py +156 -0
  13. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/transform_db_to_xes.py +77 -0
  14. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/transient_dfg.py +21 -0
  15. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/transient_petri_net.py +28 -0
  16. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/transition_system_test.py +29 -0
  17. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/tree_manual_generation.py +47 -0
  18. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/tree_playout.py +23 -0
  19. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trie.py +22 -0
  20. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/validation_ocel20_relational.py +19 -0
  21. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/validation_ocel20_xml.py +16 -0
  22. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/variants_duration_vis.py +23 -0
  23. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/variants_paths_duration.py +21 -0
  24. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/visualization_align_table.py +31 -0
  25. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/visualization_processtree.py +25 -0
  26. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/windows_key_mouse_logger.py +27 -0
  27. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/woflan.py +21 -0
  28. source_data/pinned/pm4py-process/tag-2.7.23.11/examples/workalendar_example.py +23 -0
  29. source_data/pinned/pm4py-process/tag-2.7.23.11/files/HOWTO_LINT.md +57 -0
  30. source_data/pinned/pm4py-process/tag-2.7.23.11/files/bundle.py +182 -0
  31. source_data/pinned/pm4py-process/tag-2.7.23.11/files/flake8.ini +3 -0
  32. source_data/pinned/pm4py-process/tag-2.7.23.11/files/flake8_score.py +62 -0
  33. source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/.gitignore +5 -0
  34. source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/1_event_data.ipynb +1176 -0
  35. source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/2_event_data_filtering.ipynb +964 -0
  36. source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/3_process_discovery.ipynb +0 -0
  37. source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/4_conformance_checking.ipynb +0 -0
  38. source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/5_advanced_examples.ipynb +0 -0
  39. source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/data/receipt.xes +0 -0
  40. source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/data/running_example.csv +43 -0
  41. source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/data/running_example.xes +373 -0
  42. source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/data/running_example_broken.csv +35 -0
  43. source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/img/bpmn_running_example.png +3 -0
  44. source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/__init__.py +413 -0
  45. source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/__init__.py +41 -0
  46. source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/analysis/__init__.py +30 -0
  47. source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/analysis/extended_marking_equation/__init__.py +22 -0
  48. source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/analysis/extended_marking_equation/algorithm.py +97 -0
  49. source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/analysis/extended_marking_equation/variants/__init__.py +22 -0
  50. source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/analysis/extended_marking_equation/variants/classic.py +641 -0
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_alignments.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Alignment-based trace encoding example.
3
+
4
+ Alignments are another process-model-based encoding. Each trace is aligned
5
+ against a Petri net by finding a least-cost explanation of how the observed log
6
+ moves can match the model moves.
7
+
8
+ In this example the model is:
9
+
10
+ A -> B -> C
11
+
12
+ The event log contains two traces:
13
+
14
+ fit: A, B, C
15
+ skip_b: A, C
16
+
17
+ The first trace aligns synchronously with the model. The second trace cannot
18
+ match the model without a deviation, so the alignment cost increases and the
19
+ fitness decreases. The output vector stores these conformance diagnostics.
20
+ """
21
+
22
+ from pm4py.algo.transformation.trace_encodings import algorithm as trace_encodings
23
+ from pm4py.objects.log.obj import Event, EventLog, Trace
24
+ from pm4py.objects.petri_net.obj import Marking, PetriNet
25
+ from pm4py.objects.petri_net.utils import petri_utils
26
+
27
+
28
+ def _build_log_and_model():
29
+ """Build a tiny event log and a matching A -> B -> C Petri net."""
30
+ # Build the log explicitly so the two cases and their expected behavior are
31
+ # visible without opening an external file.
32
+ log = EventLog()
33
+ for case_id, activities in [("fit", ["A", "B", "C"]), ("skip_b", ["A", "C"])]:
34
+ trace = Trace(attributes={"concept:name": case_id})
35
+ for activity in activities:
36
+ trace.append(Event({"concept:name": activity}))
37
+ log.append(trace)
38
+
39
+ # Build a simple sequential Petri net:
40
+ # p0 --A--> p1 --B--> p2 --C--> p3
41
+ net = PetriNet("abc")
42
+ p0 = PetriNet.Place("p0")
43
+ p1 = PetriNet.Place("p1")
44
+ p2 = PetriNet.Place("p2")
45
+ p3 = PetriNet.Place("p3")
46
+ t_a = PetriNet.Transition("A", "A")
47
+ t_b = PetriNet.Transition("B", "B")
48
+ t_c = PetriNet.Transition("C", "C")
49
+
50
+ for place in [p0, p1, p2, p3]:
51
+ net.places.add(place)
52
+ for transition in [t_a, t_b, t_c]:
53
+ net.transitions.add(transition)
54
+
55
+ petri_utils.add_arc_from_to(p0, t_a, net)
56
+ petri_utils.add_arc_from_to(t_a, p1, net)
57
+ petri_utils.add_arc_from_to(p1, t_b, net)
58
+ petri_utils.add_arc_from_to(t_b, p2, net)
59
+ petri_utils.add_arc_from_to(p2, t_c, net)
60
+ petri_utils.add_arc_from_to(t_c, p3, net)
61
+
62
+ # The initial marking puts one token in p0; the final marking expects one
63
+ # token in p3 after replaying A, then B, then C.
64
+ initial_marking = Marking()
65
+ initial_marking[p0] = 1
66
+ final_marking = Marking()
67
+ final_marking[p3] = 1
68
+
69
+ return log, net, initial_marking, final_marking
70
+
71
+
72
+ def execute_script():
73
+ log, net, initial_marking, final_marking = _build_log_and_model()
74
+
75
+ # ALIGNMENTS returns one row per trace with these columns:
76
+ # @@alignment_is_fit
77
+ # @@alignment_fitness
78
+ # @@alignment_cost
79
+ # @@alignment_bwc
80
+ # @@alignment_visited_states
81
+ # @@alignment_queued_states
82
+ # @@alignment_traversed_arcs
83
+ #
84
+ # The first columns describe conformance quality. The state/arc counters
85
+ # describe computational effort of the alignment search.
86
+ data, feature_names = trace_encodings.apply(
87
+ log,
88
+ variant=trace_encodings.Variants.ALIGNMENTS,
89
+ parameters={
90
+ "net": net,
91
+ "initial_marking": initial_marking,
92
+ "final_marking": final_marking,
93
+ "show_progress_bar": False,
94
+ },
95
+ )
96
+
97
+ print(feature_names)
98
+ for trace, row in zip(log, data):
99
+ # Compare the "fit" and "skip_b" rows: the skipped-B trace should have
100
+ # a non-zero cost and a lower fitness than the perfectly fitting trace.
101
+ print(trace.attributes["concept:name"], row)
102
+
103
+
104
+ if __name__ == "__main__":
105
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_bert.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ BERT-style trace encoding example.
3
+
4
+ This method converts a trace to a sentence and embeds that sentence with a
5
+ sentence-transformers model. From an event-log point of view, a case such as:
6
+
7
+ A, B, C
8
+
9
+ is converted to a textual sentence:
10
+
11
+ "A B C"
12
+
13
+ The sentence-transformer maps the whole sentence to a dense vector. This can
14
+ capture information beyond raw counts when a suitable language/sequence model
15
+ is available. In process-mining settings, the "words" are process tokens
16
+ derived from event attributes, not natural-language words.
17
+
18
+ The model name can also be a local model path. In offline environments, the
19
+ model must already be available locally or in the sentence-transformers cache.
20
+ """
21
+
22
+ import importlib.util
23
+ import os
24
+
25
+ import pandas
26
+ import pm4py
27
+ from pm4py.algo.transformation.trace_encodings import algorithm as trace_encodings
28
+
29
+
30
+ def execute_script():
31
+ # BERT-style encoding delegates to sentence-transformers. This dependency
32
+ # is optional and may also need a locally available model checkpoint.
33
+ if not importlib.util.find_spec("sentence_transformers"):
34
+ print("sentence-transformers is not installed; skipping BERT encoding")
35
+ return
36
+
37
+ # Load and normalize the small XES log used in PM4Py tests.
38
+ log: pandas.DataFrame = pm4py.read_xes(
39
+ os.path.join("..", "tests", "input_data", "running-example.xes")
40
+ )
41
+ log = pm4py.format_dataframe(log)
42
+
43
+ # event_attributes controls how process events are rendered as text tokens.
44
+ # With ["concept:name"], each trace sentence is simply its activity
45
+ # sequence. Additional event or trace attributes can be added when the
46
+ # embedding should include resource, cost, or case-level context.
47
+ #
48
+ # bert_model is passed to sentence-transformers. Use a cached model name or
49
+ # a local path when running without network access.
50
+ data, feature_names = trace_encodings.apply(
51
+ log,
52
+ variant=trace_encodings.Variants.BERT,
53
+ parameters={
54
+ "event_attributes": ["concept:name"],
55
+ "bert_model": "bert-base-nli-mean-tokens",
56
+ },
57
+ )
58
+
59
+ print("BERT-style trace embeddings")
60
+ # Each row corresponds to one trace/case in the event log.
61
+ print(" rows:", len(data))
62
+ # Each column is one dense embedding dimension returned by the model.
63
+ print(" dimensions:", len(feature_names))
64
+ if len(data):
65
+ # Values are dense floating-point coordinates. Their meaning depends on
66
+ # the selected transformer model, not on explicit process feature names.
67
+ print(" first row:", data[0][:5])
68
+
69
+
70
+ if __name__ == "__main__":
71
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_count2vec.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Count2Vec trace encoding example.
3
+
4
+ Count2Vec uses the same tokenization idea as one-hot encoding, but stores
5
+ frequencies instead of only presence/absence. From an event-log point of view,
6
+ a trace such as:
7
+
8
+ A, B, C, B
9
+
10
+ is converted to tokens:
11
+
12
+ ["A", "B", "C", "B"]
13
+
14
+ If the fitted vocabulary is ["A", "B", "C", "D"], the trace is encoded as
15
+ [1, 2, 1, 0]. This is useful when repeated behavior matters, for example when
16
+ loops or rework should influence the vector more than one-off activities.
17
+
18
+ With multiple event attributes, a single event can become a combined token
19
+ such as "concept:name=A|org:resource=Mary|Costs=100". Trace attributes are
20
+ added as case-context tokens and are counted like any other token.
21
+ """
22
+
23
+ import importlib.util
24
+ import os
25
+
26
+ import pandas
27
+ import pm4py
28
+ from pm4py.algo.transformation.trace_encodings import algorithm as trace_encodings
29
+
30
+
31
+ def _print_result(name, data, feature_names):
32
+ """Print a compact preview of a trace encoding matrix."""
33
+ print(name)
34
+ # Each row corresponds to one trace/case in the event log.
35
+ print(" rows:", len(data))
36
+ # Each column corresponds to one token found in the fitted vocabulary.
37
+ print(" columns:", len(feature_names))
38
+ print(" first columns:", feature_names[:5])
39
+ if len(data):
40
+ # Values are counts: 2 means the token appears twice in that trace.
41
+ print(" first row:", data[0][:5])
42
+
43
+
44
+ def execute_script():
45
+ # COUNT2VEC is implemented through scikit-learn's CountVectorizer, so the
46
+ # example checks the optional dependency before trying to vectorize.
47
+ if not importlib.util.find_spec("sklearn"):
48
+ print("scikit-learn is not installed; skipping count2vec encoding")
49
+ return
50
+
51
+ # Load and normalize the small XES log used in PM4Py tests.
52
+ log: pandas.DataFrame = pm4py.read_xes(
53
+ os.path.join("..", "tests", "input_data", "running-example.xes")
54
+ )
55
+ log = pm4py.format_dataframe(log)
56
+
57
+ # Activity-only perspective:
58
+ # every activity label becomes a vocabulary column; the value is the number
59
+ # of times that activity occurs in the trace.
60
+ data, feature_names = trace_encodings.apply(
61
+ log,
62
+ variant=trace_encodings.Variants.COUNT2VEC,
63
+ parameters={"event_attributes": ["concept:name"]},
64
+ )
65
+ _print_result("count2vec, control-flow only", data, feature_names)
66
+
67
+ # Context-enriched perspective:
68
+ # the event token includes activity, resource, and cost, and the case
69
+ # creator is added as a trace token. This allows the frequency vector to
70
+ # distinguish, for instance, A performed by Mary from A performed by John.
71
+ data, feature_names = trace_encodings.apply(
72
+ log,
73
+ variant=trace_encodings.Variants.COUNT2VEC,
74
+ parameters={
75
+ "event_attributes": ["concept:name", "org:resource", "Costs"],
76
+ "trace_attributes": ["creator"],
77
+ },
78
+ )
79
+ _print_result("count2vec, with event and case context", data, feature_names)
80
+
81
+
82
+ if __name__ == "__main__":
83
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_doc2vec.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Doc2Vec trace encoding example.
3
+
4
+ Doc2Vec is related to Word2Vec, but learns a vector for each whole trace
5
+ directly. From an event-log point of view, every case is a document and every
6
+ event token is a word in that document:
7
+
8
+ case 1: A, B, C
9
+ case 2: A, B, D
10
+
11
+ Doc2Vec learns one dense vector for "A B C" and another dense vector for
12
+ "A B D". Unlike Word2Vec, the trace vector is not calculated by averaging
13
+ event vectors after training; the document/trace vector is part of the model.
14
+
15
+ This method is useful when the whole case should be embedded as one object,
16
+ rather than as a simple aggregate of event embeddings.
17
+ """
18
+
19
+ import importlib.util
20
+ import os
21
+
22
+ import pandas
23
+ import pm4py
24
+ from pm4py.algo.transformation.trace_encodings import algorithm as trace_encodings
25
+
26
+
27
+ def execute_script():
28
+ # DOC2VEC delegates model training to gensim. The example skips cleanly
29
+ # when gensim is not installed.
30
+ if not importlib.util.find_spec("gensim"):
31
+ print("gensim is not installed; skipping Doc2Vec encoding")
32
+ return
33
+
34
+ # Load and normalize the small XES log used in PM4Py tests.
35
+ log: pandas.DataFrame = pm4py.read_xes(
36
+ os.path.join("..", "tests", "input_data", "running-example.xes")
37
+ )
38
+ log = pm4py.format_dataframe(log)
39
+
40
+ # This example trains a small Doc2Vec model directly on the example log.
41
+ # event_attributes selects what becomes a word in the trace document.
42
+ #
43
+ # vector_size=16 keeps the printed example compact. Real applications
44
+ # usually need more training data and may use a larger vector size.
45
+ #
46
+ # epochs controls how many training passes gensim performs. Doc2Vec
47
+ # training is stochastic, so the exact coordinates may differ by run.
48
+ data, feature_names = trace_encodings.apply(
49
+ log,
50
+ variant=trace_encodings.Variants.DOC2VEC,
51
+ parameters={
52
+ "event_attributes": ["concept:name"],
53
+ "vector_size": 16,
54
+ "epochs": 20,
55
+ },
56
+ )
57
+
58
+ print("Doc2Vec trace embeddings")
59
+ # Each row corresponds to one trace/case in the event log.
60
+ print(" rows:", len(data))
61
+ # Each column is one dimension of the learned trace/document vector.
62
+ print(" dimensions:", len(feature_names))
63
+ if len(data):
64
+ # Values are dense floating-point coordinates. Individual dimensions do
65
+ # not have direct process labels like "activity A count".
66
+ print(" first row:", data[0][:5])
67
+
68
+
69
+ if __name__ == "__main__":
70
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_n_grams.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ N-gram trace encoding example.
3
+
4
+ N-grams add local ordering information to bag-of-token encodings. From an
5
+ event-log point of view, a trace is first tokenized, and then contiguous token
6
+ windows are counted.
7
+
8
+ For a trace:
9
+
10
+ A, B, C
11
+
12
+ activity 1-grams are:
13
+
14
+ A, B, C
15
+
16
+ activity 2-grams are:
17
+
18
+ A >> B, B >> C
19
+
20
+ With ngram_range=(2, 2), the vector contains only directly-following pairs.
21
+ With ngram_range=(1, 2), it contains both individual tokens and adjacent
22
+ pairs. This is helpful when the difference between "A then B" and "B then A"
23
+ matters.
24
+ """
25
+
26
+ import importlib.util
27
+ import os
28
+
29
+ import pandas
30
+ import pm4py
31
+ from pm4py.algo.transformation.trace_encodings import algorithm as trace_encodings
32
+
33
+
34
+ def _print_result(name, data, feature_names):
35
+ """Print a compact preview of a trace encoding matrix."""
36
+ print(name)
37
+ # Each row corresponds to one trace/case in the event log.
38
+ print(" rows:", len(data))
39
+ # Each column corresponds to an observed n-gram.
40
+ print(" columns:", len(feature_names))
41
+ print(" first columns:", feature_names[:5])
42
+ if len(data):
43
+ # Values are counts of the corresponding n-gram in the trace.
44
+ print(" first row:", data[0][:5])
45
+
46
+
47
+ def execute_script():
48
+ # N_GRAMS uses the same scikit-learn vectorization utility as COUNT2VEC,
49
+ # but customizes the analyzer so it can count process-sequence windows.
50
+ if not importlib.util.find_spec("sklearn"):
51
+ print("scikit-learn is not installed; skipping n-gram encoding")
52
+ return
53
+
54
+ # Load and normalize the small XES log used in PM4Py tests.
55
+ log: pandas.DataFrame = pm4py.read_xes(
56
+ os.path.join("..", "tests", "input_data", "running-example.xes")
57
+ )
58
+ log = pm4py.format_dataframe(log)
59
+
60
+ # Directly-follows perspective:
61
+ # ngram_range=(2, 2) means "only pairs". The vocabulary contains columns
62
+ # like "A >> B" whenever A is followed immediately by B in a trace.
63
+ data, feature_names = trace_encodings.apply(
64
+ log,
65
+ variant=trace_encodings.Variants.N_GRAMS,
66
+ parameters={
67
+ "event_attributes": ["concept:name"],
68
+ "ngram_range": (2, 2),
69
+ },
70
+ )
71
+ _print_result("2-grams, control-flow only", data, feature_names)
72
+
73
+ # Mixed unigram/bigram perspective:
74
+ # ngram_range=(1, 2) keeps individual event tokens and adjacent pairs. The
75
+ # event token also includes the resource, and the creator is prepended as a
76
+ # trace-context token, so some n-grams connect case context to the first
77
+ # observed event token.
78
+ data, feature_names = trace_encodings.apply(
79
+ log,
80
+ variant=trace_encodings.Variants.N_GRAMS,
81
+ parameters={
82
+ "event_attributes": ["concept:name", "org:resource"],
83
+ "trace_attributes": ["creator"],
84
+ "ngram_range": (1, 2),
85
+ },
86
+ )
87
+ _print_result("1- and 2-grams, with event and case context", data, feature_names)
88
+
89
+
90
+ if __name__ == "__main__":
91
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_one_hot.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ One-hot trace encoding example.
3
+
4
+ This encoding turns each trace into a sparse vocabulary vector. From an
5
+ event-log point of view, every case is first converted to a list of textual
6
+ tokens. With the default activity-only perspective, a trace such as:
7
+
8
+ A, B, C, B
9
+
10
+ is seen as the token list:
11
+
12
+ ["A", "B", "C", "B"]
13
+
14
+ The one-hot vector only records whether a token appears at least once in the
15
+ trace. If the log vocabulary is ["A", "B", "C", "D"], the trace above is
16
+ encoded as [1, 1, 1, 0]. The second occurrence of B does not increase the B
17
+ column because this method models presence/absence, not frequency.
18
+
19
+ When several event attributes are selected, each event becomes a richer token.
20
+ For example, an event with concept:name="A" and org:resource="Mary" becomes a
21
+ token such as "concept:name=A|org:resource=Mary". Trace attributes are added
22
+ as case-context tokens before the event sequence.
23
+ """
24
+
25
+ import importlib.util
26
+ import os
27
+
28
+ import pandas
29
+ import pm4py
30
+ from pm4py.algo.transformation.trace_encodings import algorithm as trace_encodings
31
+
32
+
33
+ def _print_result(name, data, feature_names):
34
+ """Print a compact preview of a trace encoding matrix."""
35
+ print(name)
36
+ # Each row corresponds to one trace/case in the event log.
37
+ print(" rows:", len(data))
38
+ # Each column corresponds to one token found in the fitted vocabulary.
39
+ print(" columns:", len(feature_names))
40
+ print(" first columns:", feature_names[:5])
41
+ if len(data):
42
+ # Values are 0/1 for one-hot: 1 means the token appears in the trace.
43
+ print(" first row:", data[0][:5])
44
+
45
+
46
+ def execute_script():
47
+ # ONE_HOT is implemented through scikit-learn's CountVectorizer with
48
+ # binary=True, so the example can only run when scikit-learn is available.
49
+ if not importlib.util.find_spec("sklearn"):
50
+ print("scikit-learn is not installed; skipping one-hot encoding")
51
+ return
52
+
53
+ # The running example is a small XES event log shipped with the tests.
54
+ # format_dataframe normalizes the dataframe columns for PM4Py log handling.
55
+ log: pandas.DataFrame = pm4py.read_xes(
56
+ os.path.join("..", "tests", "input_data", "running-example.xes")
57
+ )
58
+ log = pm4py.format_dataframe(log)
59
+
60
+ # Activity-only perspective:
61
+ # the vocabulary contains activity labels such as "register request" or
62
+ # "check ticket". A trace receives 1 in a column if that activity appears.
63
+ data, feature_names = trace_encodings.apply(
64
+ log,
65
+ variant=trace_encodings.Variants.ONE_HOT,
66
+ parameters={"event_attributes": ["concept:name"]},
67
+ )
68
+ _print_result("one-hot, control-flow only", data, feature_names)
69
+
70
+ # Context-enriched perspective:
71
+ # each event token combines activity, resource, and cost; the creator case
72
+ # attribute is also added as a trace-level context token. This produces more
73
+ # specific columns than the activity-only encoding.
74
+ data, feature_names = trace_encodings.apply(
75
+ log,
76
+ variant=trace_encodings.Variants.ONE_HOT,
77
+ parameters={
78
+ "event_attributes": ["concept:name", "org:resource", "Costs"],
79
+ "trace_attributes": ["creator"],
80
+ },
81
+ )
82
+ _print_result("one-hot, with event and case context", data, feature_names)
83
+
84
+
85
+ if __name__ == "__main__":
86
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_tf_idf.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ TF-IDF trace encoding example.
3
+
4
+ TF-IDF keeps the bag-of-token shape of Count2Vec, but changes the value stored
5
+ in each column. The value is high when a token is frequent in the current
6
+ trace and relatively rare across other traces.
7
+
8
+ From an event-log point of view, suppose the fitted vocabulary contains
9
+ activities A, B, and C. If activity A appears in almost every case, while C
10
+ appears only in a few exceptional cases, then C receives a higher inverse
11
+ document-frequency weight. This can make exceptional behavior more visible to
12
+ downstream machine-learning algorithms.
13
+
14
+ The same tokenization rules are used as in the other text-style encodings:
15
+ selected event attributes form event tokens, trace attributes form case
16
+ context tokens, and ngram_range can include adjacent process fragments.
17
+ """
18
+
19
+ import importlib.util
20
+ import os
21
+
22
+ import pandas
23
+ import pm4py
24
+ from pm4py.algo.transformation.trace_encodings import algorithm as trace_encodings
25
+
26
+
27
+ def _print_result(name, data, feature_names):
28
+ """Print a compact preview of a trace encoding matrix."""
29
+ print(name)
30
+ # Each row corresponds to one trace/case in the event log.
31
+ print(" rows:", len(data))
32
+ # Each column corresponds to one token or n-gram in the fitted vocabulary.
33
+ print(" columns:", len(feature_names))
34
+ print(" first columns:", feature_names[:5])
35
+ if len(data):
36
+ # Values are floating-point TF-IDF weights, not raw counts.
37
+ print(" first row:", data[0][:5])
38
+
39
+
40
+ def execute_script():
41
+ # TF_IDF is implemented through scikit-learn's TfidfVectorizer.
42
+ if not importlib.util.find_spec("sklearn"):
43
+ print("scikit-learn is not installed; skipping TF-IDF encoding")
44
+ return
45
+
46
+ # Load and normalize the small XES log used in PM4Py tests.
47
+ log: pandas.DataFrame = pm4py.read_xes(
48
+ os.path.join("..", "tests", "input_data", "running-example.xes")
49
+ )
50
+ log = pm4py.format_dataframe(log)
51
+
52
+ # Activity-only perspective:
53
+ # each activity is weighted by how characteristic it is for the trace.
54
+ # Common activities still appear in the vector, but they receive less
55
+ # emphasis than tokens that are rarer across the log.
56
+ data, feature_names = trace_encodings.apply(
57
+ log,
58
+ variant=trace_encodings.Variants.TF_IDF,
59
+ parameters={"event_attributes": ["concept:name"]},
60
+ )
61
+ _print_result("TF-IDF, control-flow only", data, feature_names)
62
+
63
+ # Context and local-order perspective:
64
+ # adding resource and creator context enriches the token vocabulary, while
65
+ # ngram_range=(1, 2) adds adjacent token pairs. The resulting weights can
66
+ # highlight rare activity-resource combinations or rare short fragments.
67
+ data, feature_names = trace_encodings.apply(
68
+ log,
69
+ variant=trace_encodings.Variants.TF_IDF,
70
+ parameters={
71
+ "event_attributes": ["concept:name", "org:resource"],
72
+ "trace_attributes": ["creator"],
73
+ "ngram_range": (1, 2),
74
+ },
75
+ )
76
+ _print_result("TF-IDF, with event and case context", data, feature_names)
77
+
78
+
79
+ if __name__ == "__main__":
80
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_token_replay.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Token-replay trace encoding example.
3
+
4
+ Token replay is a process-model-based encoding. Instead of looking only at the
5
+ events in a trace, it replays each trace on a Petri net and stores conformance
6
+ diagnostics as numeric features.
7
+
8
+ In this example the model is:
9
+
10
+ A -> B -> C
11
+
12
+ The event log contains two traces:
13
+
14
+ fit: A, B, C
15
+ skip_b: A, C
16
+
17
+ The first trace can be replayed without deviations. The second trace skips B,
18
+ so token replay has to compensate for missing/remaining tokens. The resulting
19
+ vector records whether the trace is fit, its fitness, and token counters.
20
+ """
21
+
22
+ from pm4py.algo.transformation.trace_encodings import algorithm as trace_encodings
23
+ from pm4py.objects.log.obj import Event, EventLog, Trace
24
+ from pm4py.objects.petri_net.obj import Marking, PetriNet
25
+ from pm4py.objects.petri_net.utils import petri_utils
26
+
27
+
28
+ def _build_log_and_model():
29
+ """Build a tiny event log and a matching A -> B -> C Petri net."""
30
+ # Build the log explicitly so the example is independent of external XES
31
+ # files and the intended deviations are easy to inspect.
32
+ log = EventLog()
33
+ for case_id, activities in [("fit", ["A", "B", "C"]), ("skip_b", ["A", "C"])]:
34
+ trace = Trace(attributes={"concept:name": case_id})
35
+ for activity in activities:
36
+ trace.append(Event({"concept:name": activity}))
37
+ log.append(trace)
38
+
39
+ # Build a simple sequential Petri net:
40
+ # p0 --A--> p1 --B--> p2 --C--> p3
41
+ net = PetriNet("abc")
42
+ p0 = PetriNet.Place("p0")
43
+ p1 = PetriNet.Place("p1")
44
+ p2 = PetriNet.Place("p2")
45
+ p3 = PetriNet.Place("p3")
46
+ t_a = PetriNet.Transition("A", "A")
47
+ t_b = PetriNet.Transition("B", "B")
48
+ t_c = PetriNet.Transition("C", "C")
49
+
50
+ for place in [p0, p1, p2, p3]:
51
+ net.places.add(place)
52
+ for transition in [t_a, t_b, t_c]:
53
+ net.transitions.add(transition)
54
+
55
+ petri_utils.add_arc_from_to(p0, t_a, net)
56
+ petri_utils.add_arc_from_to(t_a, p1, net)
57
+ petri_utils.add_arc_from_to(p1, t_b, net)
58
+ petri_utils.add_arc_from_to(t_b, p2, net)
59
+ petri_utils.add_arc_from_to(p2, t_c, net)
60
+ petri_utils.add_arc_from_to(t_c, p3, net)
61
+
62
+ # The initial marking puts one token in p0. A perfectly replayed trace
63
+ # consumes and produces tokens until one token reaches p3.
64
+ initial_marking = Marking()
65
+ initial_marking[p0] = 1
66
+ final_marking = Marking()
67
+ final_marking[p3] = 1
68
+
69
+ return log, net, initial_marking, final_marking
70
+
71
+
72
+ def execute_script():
73
+ log, net, initial_marking, final_marking = _build_log_and_model()
74
+
75
+ # TOKEN_REPLAY returns one row per trace with these columns:
76
+ # @@token_replay_is_fit
77
+ # @@token_replay_fitness
78
+ # @@token_replay_missing_tokens
79
+ # @@token_replay_consumed_tokens
80
+ # @@token_replay_remaining_tokens
81
+ # @@token_replay_produced_tokens
82
+ #
83
+ # Passing an explicit net makes the conformance reference clear. If no net
84
+ # is supplied, the variant can discover one, but that is less didactic for
85
+ # this small example.
86
+ data, feature_names = trace_encodings.apply(
87
+ log,
88
+ variant=trace_encodings.Variants.TOKEN_REPLAY,
89
+ parameters={
90
+ "net": net,
91
+ "initial_marking": initial_marking,
92
+ "final_marking": final_marking,
93
+ "show_progress_bar": False,
94
+ },
95
+ )
96
+
97
+ print(feature_names)
98
+ for trace, row in zip(log, data):
99
+ # Compare the "fit" and "skip_b" rows: the skipped-B trace should show
100
+ # lower fitness and/or non-zero token-deviation counters.
101
+ print(trace.attributes["concept:name"], row)
102
+
103
+
104
+ if __name__ == "__main__":
105
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trace_encoding_word2vec.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Word2Vec trace encoding example.
3
+
4
+ Word2Vec is an embedding method: it learns dense vectors for individual event
5
+ tokens by looking at the neighboring tokens around them in the log.
6
+
7
+ From an event-log point of view, each trace is treated like a sentence:
8
+
9
+ A, B, C
10
+
11
+ becomes:
12
+
13
+ ["A", "B", "C"]
14
+
15
+ Word2Vec learns one vector for A, one for B, and one for C. The trace vector is
16
+ then computed by aggregating the event-token vectors in the trace. The default
17
+ aggregation is the mean, so the trace above is represented by the average of
18
+ the A, B, and C vectors.
19
+
20
+ This method is useful when traces sharing similar local contexts should end up
21
+ with similar dense vectors, even if their raw token columns are not identical.
22
+ """
23
+
24
+ import importlib.util
25
+ import os
26
+
27
+ import pandas
28
+ import pm4py
29
+ from pm4py.algo.transformation.trace_encodings import algorithm as trace_encodings
30
+
31
+
32
+ def execute_script():
33
+ # WORD2VEC delegates the actual model training to gensim. It is optional
34
+ # because gensim is a heavier dependency than the core PM4Py stack.
35
+ if not importlib.util.find_spec("gensim"):
36
+ print("gensim is not installed; skipping Word2Vec encoding")
37
+ return
38
+
39
+ # Load and normalize the small XES log used in PM4Py tests.
40
+ log: pandas.DataFrame = pm4py.read_xes(
41
+ os.path.join("..", "tests", "input_data", "running-example.xes")
42
+ )
43
+ log = pm4py.format_dataframe(log)
44
+
45
+ # This example trains a small Word2Vec model directly on the example log.
46
+ # event_attributes selects what becomes a token. With ["concept:name"], the
47
+ # token sequence is just the activity sequence of each case.
48
+ #
49
+ # vector_size=16 keeps the printed example compact. Larger values can carry
50
+ # more information but need more data to train reliably.
51
+ #
52
+ # epochs controls how many passes gensim makes over the trace "sentences".
53
+ # Because Word2Vec training is stochastic, exact numeric values may differ
54
+ # between runs or environments.
55
+ data, feature_names = trace_encodings.apply(
56
+ log,
57
+ variant=trace_encodings.Variants.WORD2VEC,
58
+ parameters={
59
+ "event_attributes": ["concept:name"],
60
+ "vector_size": 16,
61
+ "epochs": 20,
62
+ },
63
+ )
64
+
65
+ print("Word2Vec trace embeddings")
66
+ # Each row corresponds to one trace/case in the event log.
67
+ print(" rows:", len(data))
68
+ # Each column is one dimension of the aggregated dense embedding.
69
+ print(" dimensions:", len(feature_names))
70
+ if len(data):
71
+ # Values are dense floating-point coordinates, not interpretable token
72
+ # counts. Similar vectors should indicate similar learned contexts.
73
+ print(" first row:", data[0][:5])
74
+
75
+
76
+ if __name__ == "__main__":
77
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trans_system_stochastic_vis.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pm4py
2
+ from pm4py.algo.discovery.transition_system import algorithm as transition_system_discovery
3
+ from examples import examples_conf
4
+ import os
5
+ import importlib.util
6
+ import pandas
7
+ from pm4py.objects.transition_system.obj import TransitionSystem
8
+
9
+
10
+ def execute_script():
11
+ log: pandas.DataFrame = pm4py.read_xes(os.path.join("..", "tests", "input_data", "running-example.xes"))
12
+ ts: TransitionSystem = transition_system_discovery.apply(log, parameters={"include_data": True, "direction": "forward"})
13
+
14
+ if importlib.util.find_spec("graphviz"):
15
+ from pm4py.visualization.transition_system.variants import trans_frequency
16
+ from pm4py.visualization.transition_system import visualizer as transition_system_visualizer
17
+ gviz = trans_frequency.apply(ts, parameters={"format": examples_conf.TARGET_IMG_FORMAT})
18
+ transition_system_visualizer.view(gviz)
19
+
20
+
21
+ if __name__ == "__main__":
22
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/transform_db_to_ocel.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ import pm4py
3
+ from pm4py.objects.ocel.obj import OCEL
4
+ from pm4py.util import pandas_utils, constants
5
+ from pm4py.util.dt_parsing.variants import strpfromiso
6
+ import os
7
+ import pandas
8
+
9
+
10
+ def extract_invoices(cursor):
11
+ cursor.execute(
12
+ "SELECT CustomerId, InvoiceId, InvoiceDate, BillingAddress, BillingCity, BillingCountry, BillingPostalCode FROM Invoice")
13
+
14
+ invoices = {}
15
+ for res in cursor.fetchall():
16
+ dct = {"ocel:oid": "inv"+str(res[0]), "ocel:type": "invoice", "CustomerId": res[0], "InvoiceId": res[1], "InvoiceDate": strpfromiso.apply(res[2]), "BillingAddress": res[3],
17
+ "BillingCity": res[4], "BillingCountry": res[5], "BillingPostalCode": res[6]}
18
+
19
+ invoices[res[0]] = dct
20
+
21
+ return invoices
22
+
23
+
24
+ def extract_invoice_lines(cursor):
25
+ cursor.execute("SELECT InvoiceLineId, InvoiceId, TrackId, UnitPrice, Quantity FROM InvoiceLine")
26
+
27
+ invoice_lines = {}
28
+ for res in cursor.fetchall():
29
+ invoice_lines[res[0]] = {"ocel:oid": "invline"+str(res[0]), "ocel:type": "invoiceline", "InvoiceLineId": res[0], "InvoiceId": res[1], "TrackId": res[2], "UnitPrice": res[3], "Category": res[4]}
30
+
31
+ return invoice_lines
32
+
33
+
34
+ def extract_customers(cursor):
35
+ cursor.execute("SELECT CustomerId, FirstName, LastName, Company, Address, City, State, Country FROM Customer")
36
+
37
+ customers = {}
38
+ for res in cursor.fetchall():
39
+ customers[res[0]] = {"ocel:oid": "cust"+str(res[0]), "ocel:type": "customer", "CustomerId": res[0], "FirstName": res[1], "LastName": res[2], "Company": res[3], "Address": res[4],
40
+ "City": res[5], "State": res[6], "Country": res[7]}
41
+
42
+ return customers
43
+
44
+
45
+ def extract_employee(cursor):
46
+ cursor.execute("SELECT EmployeeId, LastName, FirstName, Title, ReportsTo, BirthDate, HireDate, Address, City, State, Country, PostalCode, Phone, Fax, Email FROM Employee")
47
+
48
+ employee = {}
49
+
50
+ for res in cursor.fetchall():
51
+ dct: dict[str, str] = {"ocel:oid": "emp"+str(res[0]), "ocel:type": "employee", "EmployeeId": res[0], "LastName": res[1], "FirstName": res[2], "Title": res[3], "ReportsTo": res[4], "BirthDate": strpfromiso.apply(res[5]), "HireDate": strpfromiso.apply(res[6]), "Address": res[7], "City": res[8], "State": res[9], "Country": res[10], "PostalCode": res[11], "Phone": res[12], "Fax": res[13], "Email": res[14]}
52
+
53
+ employee[res[0]] = dct
54
+
55
+ return employee
56
+
57
+
58
+ def execute_script():
59
+ import sqlite3
60
+ conn = sqlite3.connect("../tests/input_data/db/Chinook_Sqlite.sqlite")
61
+ cursor = conn.cursor()
62
+
63
+ invoices = extract_invoices(cursor)
64
+ invoice_lines = extract_invoice_lines(cursor)
65
+ customers = extract_customers(cursor)
66
+ employee = extract_employee(cursor)
67
+
68
+ objects = []
69
+ events = []
70
+ relations = []
71
+
72
+ for i in invoices:
73
+ objects.append(invoices[i])
74
+ for il in invoice_lines:
75
+ objects.append(invoice_lines[il])
76
+ for c in customers:
77
+ objects.append(customers[c])
78
+ for e in employee:
79
+ objects.append(employee[e])
80
+
81
+ inv_line_map = {}
82
+ for i, v in invoice_lines.items():
83
+ if v["InvoiceId"] not in inv_line_map:
84
+ inv_line_map[v["InvoiceId"]] = []
85
+ inv_line_map[v["InvoiceId"]].append(v["InvoiceLineId"])
86
+
87
+ for i in invoices:
88
+ event: dict[str, str] = {"ocel:eid": "evinv"+str(i), "ocel:activity": "Create Invoice", "ocel:timestamp": invoices[i]["InvoiceDate"]}
89
+ events.append(event)
90
+
91
+ relation_inv: dict[str, str] = {"ocel:eid": "evinv"+str(i), "ocel:activity": "Create Invoice", "ocel:timestamp": invoices[i]["InvoiceDate"], "ocel:type": "invoice", "ocel:oid": "inv"+str(i), "ocel:qualifier": ""}
92
+ relations.append(relation_inv)
93
+
94
+ relation_cust: dict[str, str] = {"ocel:eid": "evinv"+str(i), "ocel:activity": "Create Invoice", "ocel:timestamp": invoices[i]["InvoiceDate"], "ocel:type": "customer", "ocel:oid": "cust"+str(i), "ocel:qualifier": ""}
95
+ relations.append(relation_cust)
96
+
97
+ for v in inv_line_map[i]:
98
+ relation_line: dict[str, str] = {"ocel:eid": "evinv"+str(i), "ocel:activity": "Create Invoice", "ocel:timestamp": invoices[i]["InvoiceDate"], "ocel:type": "invoiceline", "ocel:oid": "invline"+str(v), "ocel:qualifier": ""}
99
+ relations.append(relation_line)
100
+
101
+ for e in employee:
102
+ event = {"ocel:eid": "evempbirth"+str(e), "ocel:activity": "Employee Birth", "ocel:timestamp": employee[e]["BirthDate"]}
103
+ events.append(event)
104
+
105
+ relation: dict[str, str] = {"ocel:eid": "evempbirth"+str(e), "ocel:activity": "Employee Birth", "ocel:timestamp": employee[e]["BirthDate"], "ocel:type": "employee", "ocel:oid": "emp"+str(e), "ocel:qualifier": ""}
106
+ relations.append(relation)
107
+
108
+ for e in employee:
109
+ event = {"ocel:eid": "evemphired"+str(e), "ocel:activity": "Employee Hired", "ocel:timestamp": employee[e]["HireDate"]}
110
+ events.append(event)
111
+
112
+ relation = {"ocel:eid": "evemphired"+str(e), "ocel:activity": "Employee Hired", "ocel:timestamp": employee[e]["HireDate"], "ocel:type": "employee", "ocel:oid": "emp"+str(e), "ocel:qualifier": ""}
113
+ relations.append(relation)
114
+
115
+ events: pandas.DataFrame = pandas_utils.instantiate_dataframe(events)
116
+ objects: pandas.DataFrame = pandas_utils.instantiate_dataframe(objects)
117
+ relations: pandas.DataFrame = pandas_utils.instantiate_dataframe(relations)
118
+
119
+ events = events.sort_values("ocel:timestamp")
120
+ relations = relations.sort_values("ocel:timestamp")
121
+
122
+ ocel: OCEL = OCEL()
123
+ ocel.events = events
124
+ ocel.objects = objects
125
+ ocel.relations = relations
126
+
127
+ ocel.events = ocel.events.dropna(subset=["ocel:timestamp"])
128
+ ocel.relations = ocel.relations.dropna(subset=["ocel:timestamp"])
129
+
130
+ pm4py.write_ocel(ocel, "chinook.jsonocel")
131
+ ocel = pm4py.read_ocel("chinook.jsonocel")
132
+ os.remove("chinook.jsonocel")
133
+
134
+
135
+ if __name__ == "__main__":
136
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/transform_db_to_ocel_2.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sqlite3
2
+ import pandas as pd
3
+ from copy import copy
4
+ from dateutil import parser
5
+ from pm4py.util.dt_parsing.variants import strpfromiso
6
+
7
+ import pm4py
8
+ from pm4py.objects.ocel.obj import OCEL
9
+ from pm4py.util import constants, pandas_utils
10
+ import os
11
+ from pandas import DataFrame
12
+ from typing import Iterator
13
+
14
+
15
+ def execute_script():
16
+ conn = sqlite3.connect("../tests/input_data/db/northwind.sqlite")
17
+ employees: DataFrame | Iterator[DataFrame] = pd.read_sql("SELECT EmployeeID, BirthDate, HireDate FROM Employees", conn)
18
+ employees = employees.to_dict(orient="records")
19
+ orders: DataFrame | Iterator[DataFrame] = pd.read_sql("SELECT OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate FROM Orders", conn)
20
+ orders = orders.to_dict(orient="records")
21
+
22
+ events = []
23
+ relations = []
24
+ objects = []
25
+ objects_ids = set()
26
+
27
+ eid: int = 0
28
+ for e in employees:
29
+ oid: str = str(e["EmployeeID"])
30
+ if oid not in objects_ids:
31
+ obj: dict[str, str] = {"ocel:oid": oid, "ocel:type": "Employee"}
32
+ objects.append(obj)
33
+ objects_ids.add(oid)
34
+
35
+ eid += 1
36
+ ev: dict[str, str] = {"ocel:eid": str(eid), "ocel:activity": "Created Employee", "ocel:timestamp": strpfromiso.fix_naivety(parser.parse(e["HireDate"]))}
37
+ events.append(ev)
38
+
39
+ rel: dict[str, str] = copy(ev)
40
+ rel["ocel:oid"] = str(e["EmployeeID"])
41
+ rel["ocel:type"] = "Employee"
42
+ relations.append(rel)
43
+
44
+ for o in orders:
45
+ oid = str(o["OrderID"])
46
+
47
+ if oid not in objects_ids:
48
+ obj = {"ocel:oid": oid, "ocel:type": "Order"}
49
+ objects.append(obj)
50
+ objects_ids.add(oid)
51
+
52
+ eid += 1
53
+ ev = {"ocel:eid": str(eid), "ocel:activity": "Created Order", "ocel:timestamp": strpfromiso.fix_naivety(parser.parse(o["OrderDate"]))}
54
+ events.append(ev)
55
+
56
+ rel1: dict[str, str] = copy(ev)
57
+ rel1["ocel:oid"] = str(o["OrderID"])
58
+ rel1["ocel:type"] = "Order"
59
+ relations.append(rel1)
60
+
61
+ rel2: dict[str, str] = copy(ev)
62
+ rel2["ocel:oid"] = str(o["EmployeeID"])
63
+ rel2["ocel:type"] = "Employee"
64
+ relations.append(rel2)
65
+
66
+ ocel: OCEL = OCEL(events=pandas_utils.instantiate_dataframe(events), objects=pandas_utils.instantiate_dataframe(objects), relations=pandas_utils.instantiate_dataframe(relations))
67
+ pm4py.write_ocel(ocel, "log1.jsonocel")
68
+
69
+ events = None
70
+ relations = None
71
+ objects = None
72
+ objects_ids = None
73
+ events = []
74
+ relations = []
75
+ objects = []
76
+ objects_ids = set()
77
+
78
+ eid = 0
79
+ oid = 0
80
+ for e in employees:
81
+ oid = str(e["EmployeeID"])
82
+ if oid not in objects_ids:
83
+ obj = {"ocel:oid": oid, "ocel:type": "Employee"}
84
+ objects.append(obj)
85
+ objects_ids.add(oid)
86
+
87
+ eid += 1
88
+ ev0: dict[str, str] = {"ocel:eid": str(eid), "ocel:activity": "Employee Birth", "ocel:timestamp": strpfromiso.fix_naivety(parser.parse(e["BirthDate"]))}
89
+ events.append(ev0)
90
+
91
+ eid += 1
92
+ ev = {"ocel:eid": str(eid), "ocel:activity": "Hired Employee", "ocel:timestamp": strpfromiso.fix_naivety(parser.parse(e["HireDate"]))}
93
+ events.append(ev)
94
+
95
+ rel = copy(ev0)
96
+ rel["ocel:oid"] = str(e["EmployeeID"])
97
+ rel["ocel:type"] = "Employee"
98
+ relations.append(rel)
99
+
100
+ rel = copy(ev)
101
+ rel["ocel:oid"] = str(e["EmployeeID"])
102
+ rel["ocel:type"] = "Employee"
103
+ relations.append(rel)
104
+
105
+ for o in orders:
106
+ oid = str(o["OrderID"])
107
+
108
+ if oid not in objects_ids:
109
+ obj = {"ocel:oid": oid, "ocel:type": "Order"}
110
+ objects.append(obj)
111
+ objects_ids.add(oid)
112
+
113
+ eid += 1
114
+ ev = {"ocel:eid": str(eid), "ocel:activity": "Created Order", "ocel:timestamp": strpfromiso.fix_naivety(parser.parse(o["OrderDate"]))}
115
+ events.append(ev)
116
+
117
+
118
+ rel1 = copy(ev)
119
+ rel1["ocel:oid"] = str(o["OrderID"])
120
+ rel1["ocel:type"] = "Order"
121
+ relations.append(rel1)
122
+
123
+ rel2 = copy(ev)
124
+ rel2["ocel:oid"] = str(o["EmployeeID"])
125
+ rel2["ocel:type"] = "Employee"
126
+ relations.append(rel2)
127
+
128
+ if o["ShippedDate"] is not None:
129
+ eid += 1
130
+ ev3: dict[str, str] = {"ocel:eid": str(eid), "ocel:activity": "Order Shipped", "ocel:timestamp": strpfromiso.fix_naivety(parser.parse(o["ShippedDate"]))}
131
+ events.append(ev3)
132
+
133
+ rel3: dict[str, str] = copy(ev3)
134
+ rel3["ocel:oid"] = str(o["OrderID"])
135
+ rel3["ocel:type"] = "Order"
136
+ relations.append(rel3)
137
+
138
+ if o["RequiredDate"] is not None:
139
+ eid += 1
140
+ ev4: dict[str, str] = {"ocel:eid": str(eid), "ocel:activity": "Order Due Date", "ocel:timestamp": strpfromiso.fix_naivety(parser.parse(o["RequiredDate"]))}
141
+ events.append(ev4)
142
+
143
+ rel4: dict[str, str] = copy(ev4)
144
+ rel4["ocel:oid"] = str(o["OrderID"])
145
+ rel4["ocel:type"] = "Order"
146
+ relations.append(rel4)
147
+
148
+ ocel = OCEL(events=pandas_utils.instantiate_dataframe(events), objects=pandas_utils.instantiate_dataframe(objects), relations=pandas_utils.instantiate_dataframe(relations))
149
+ pm4py.write_ocel(ocel, "log2.jsonocel")
150
+
151
+ os.remove("log1.jsonocel")
152
+ os.remove("log2.jsonocel")
153
+
154
+
155
+ if __name__ == "__main__":
156
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/transform_db_to_xes.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dateutil.parser import parse
2
+ from pm4py.objects.log.obj import EventLog, Trace, Event
3
+ from pm4py.util.dt_parsing.variants import strpfromiso
4
+ from pm4py.objects.log.exporter.xes import exporter as xes_exporter
5
+ import pm4py
6
+ import os
7
+
8
+
9
+ def extract_invoices(cursor):
10
+ cursor.execute(
11
+ "SELECT CustomerId, InvoiceId, InvoiceDate, BillingAddress, BillingCity, BillingCountry, BillingPostalCode FROM Invoice")
12
+
13
+ invoices = {}
14
+ for res in cursor.fetchall():
15
+ if res[0] not in invoices:
16
+ invoices[res[0]] = []
17
+ invoices[res[0]].append(
18
+ {"CustomerId": res[0], "InvoiceId": res[1], "InvoiceDate": strpfromiso.fix_naivety(parse(res[2])), "BillingAddress": res[3],
19
+ "BillingCity": res[4], "BillingCountry": res[5], "BillingPostalCode": res[6]})
20
+
21
+ return invoices
22
+
23
+
24
+ def extract_invoice_lines(cursor):
25
+ cursor.execute("SELECT InvoiceLineId, InvoiceId, TrackId, UnitPrice, Quantity FROM InvoiceLine")
26
+
27
+ invoice_lines = {}
28
+ for res in cursor.fetchall():
29
+ if res[1] not in invoice_lines:
30
+ invoice_lines[res[1]] = []
31
+ invoice_lines[res[1]].append({"InvoiceLineId": res[0], "InvoiceId": res[1], "TrackId": res[2], "UnitPrice": res[3], "Category": res[4]})
32
+
33
+ return invoice_lines
34
+
35
+
36
+ def extract_customers(cursor):
37
+ cursor.execute("SELECT CustomerId, FirstName, LastName, Company, Address, City, State, Country FROM Customer")
38
+
39
+ customers = {}
40
+ for res in cursor.fetchall():
41
+ customers[res[0]] = {"CustomerId": res[0], "FirstName": res[1], "LastName": res[2], "Company": res[3], "Address": res[4],
42
+ "City": res[5], "State": res[6], "Country": res[7]}
43
+
44
+ return customers
45
+
46
+
47
+ def execute_script():
48
+ import sqlite3
49
+ conn = sqlite3.connect("../tests/input_data/db/Chinook_Sqlite.sqlite")
50
+ cursor = conn.cursor()
51
+
52
+ invoices = extract_invoices(cursor)
53
+ invoice_lines = extract_invoice_lines(cursor)
54
+ customers = extract_customers(cursor)
55
+
56
+ log: EventLog = EventLog()
57
+ for customer in customers:
58
+ trace: Trace = Trace()
59
+ trace.attributes.update(customers[customer])
60
+ log.append(trace)
61
+ for invoice in invoices[customer]:
62
+ event: Event = Event()
63
+ for k, v in invoice.items():
64
+ event[k] = v
65
+ event["time:timestamp"] = event["InvoiceDate"]
66
+ event["concept:name"] = "Sent Invoice"
67
+ event["invoice_lines"] = []
68
+ for item in invoice_lines[invoice["InvoiceId"]]:
69
+ event["invoice_lines"].append(item)
70
+ trace.append(event)
71
+
72
+ xes_exporter.apply(log, "chinook.xes")
73
+ os.remove("chinook.xes")
74
+
75
+
76
+ if __name__ == "__main__":
77
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/transient_dfg.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pm4py.objects.log.importer.xes import importer as xes_importer
2
+ from pm4py.algo.discovery.dfg import algorithm as dfg_miner
3
+ from pm4py.objects.stochastic_petri import ctmc
4
+ import os
5
+ from pm4py.objects.log.obj import EventLog
6
+
7
+
8
+ def execute_script():
9
+ log: EventLog = xes_importer.apply(os.path.join("..", "tests", "input_data", "running-example.xes"))
10
+ performance_dfg: dict[tuple[str, str], float] = dfg_miner.apply(log, variant=dfg_miner.Variants.PERFORMANCE)
11
+ reach_graph, tang_reach_graph, stochastic_map, q_matrix = ctmc.get_tangible_reachability_and_q_matrix_from_dfg_performance(
12
+ performance_dfg)
13
+ # pick the source state
14
+ state = [x for x in tang_reach_graph.states if x.name == "source1"][0]
15
+ # analyse the distribution over the states of the system starting from the source after 86400.0 seconds (1 day)
16
+ transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(tang_reach_graph, q_matrix, state, 86400.0)
17
+ print(transient_result)
18
+
19
+
20
+ if __name__ == "__main__":
21
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/transient_petri_net.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pm4py.objects.log.importer.xes import importer as xes_importer
2
+ from pm4py.algo.discovery.alpha import algorithm as alpha_miner
3
+ from pm4py.objects.stochastic_petri import ctmc
4
+ import os
5
+ from pm4py.objects.log.obj import EventLog
6
+ from pm4py.objects.petri_net.obj import Marking, PetriNet
7
+
8
+
9
+ def execute_script():
10
+ log: EventLog = xes_importer.apply(os.path.join("..", "tests", "input_data", "running-example.xes"))
11
+ net: PetriNet
12
+ im: Marking
13
+ fm: Marking
14
+ net, im, fm = alpha_miner.apply(log)
15
+ # the alpha miner in this case returns a sound workflow net!
16
+ # get the tangible reachability graph and the Q-matrix
17
+ reach_graph, tang_reach_graph, stochastic_map, q_matrix = ctmc.get_tangible_reachability_and_q_matrix_from_log_net(
18
+ log, net, im, fm)
19
+ print(reach_graph.states)
20
+ # pick the source state
21
+ state = [x for x in tang_reach_graph.states if x.name.startswith("registerrequest") or x.name.startswith("reinitiaterequest")][0]
22
+ # analyse the distribution over the states of the system starting from the source after 86400.0 seconds (1 day)
23
+ transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(tang_reach_graph, q_matrix, state, 86400.0)
24
+ print(transient_result)
25
+
26
+
27
+ if __name__ == "__main__":
28
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/transition_system_test.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pm4py.objects.log.importer.xes import importer as xes_importer
2
+ from pm4py.algo.discovery.transition_system import algorithm as ts_discovery
3
+ from examples import examples_conf
4
+ import os
5
+ import importlib.util
6
+ from pm4py.objects.log.obj import EventLog
7
+ from pm4py.objects.transition_system.obj import TransitionSystem
8
+
9
+
10
+ def execute_script():
11
+ # log_path = "C:/Users/bas/Documents/tue/svn/private/logs/ilp_test_2_abcd_acbd.xes"
12
+ log_path: str = os.path.join("..", "tests", "input_data", "running-example.xes")
13
+ log: EventLog = xes_importer.apply(log_path)
14
+ ts: TransitionSystem = ts_discovery.apply(log, parameters={"include_data": True})
15
+
16
+ if importlib.util.find_spec("graphviz"):
17
+ from pm4py.visualization.transition_system import visualizer as ts_vis
18
+ viz = ts_vis.apply(ts, parameters={ts_vis.Variants.VIEW_BASED.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
19
+ ts_vis.view(viz)
20
+
21
+ for state in ts.states:
22
+ print(state.name, "ingoing=", len(state.data["ingoing_events"]), "outgoing=",
23
+ len(state.data["outgoing_events"]))
24
+ for trans in ts.transitions:
25
+ print(trans.name, trans.from_state.name, trans.to_state.name, "frequency=", len(trans.data["events"]))
26
+
27
+
28
+ if __name__ == '__main__':
29
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/tree_manual_generation.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pm4py
2
+ from pm4py.objects.process_tree.obj import ProcessTree, Operator
3
+ from examples import examples_conf
4
+ import importlib.util
5
+
6
+
7
+ def execute_script():
8
+ root: ProcessTree = ProcessTree(operator=Operator.SEQUENCE)
9
+
10
+ choice: ProcessTree = ProcessTree(operator=Operator.XOR, parent=root)
11
+ parallel: ProcessTree = ProcessTree(operator=Operator.PARALLEL, parent=root)
12
+
13
+ root.children.append(choice)
14
+ root.children.append(parallel)
15
+
16
+ leaf_A: ProcessTree = ProcessTree(label="A", parent=choice)
17
+ leaf_B: ProcessTree = ProcessTree(label="B", parent=choice)
18
+ leaf_C: ProcessTree = ProcessTree(label="C", parent=choice)
19
+
20
+ choice.children.append(leaf_A)
21
+ choice.children.append(leaf_B)
22
+ choice.children.append(leaf_C)
23
+
24
+ leaf_D: ProcessTree = ProcessTree(label="D", parent=parallel)
25
+ leaf_E: ProcessTree = ProcessTree(label="E", parent=parallel)
26
+ leaf_F: ProcessTree = ProcessTree(label="F", parent=parallel)
27
+
28
+ parallel.children.append(leaf_D)
29
+ parallel.children.append(leaf_E)
30
+ parallel.children.append(leaf_F)
31
+
32
+ if importlib.util.find_spec("graphviz"):
33
+ pm4py.view_process_tree(root, format=examples_conf.TARGET_IMG_FORMAT)
34
+
35
+ # remove leaf_C from choice
36
+ choice.children.remove(leaf_C)
37
+
38
+ # remove the leaf with label "E" from parallel
39
+ parallel.children.remove(
40
+ [parallel.children[i] for i in range(len(parallel.children)) if parallel.children[i].label == "E"][0])
41
+
42
+ if importlib.util.find_spec("graphviz"):
43
+ pm4py.view_process_tree(root, format=examples_conf.TARGET_IMG_FORMAT)
44
+
45
+
46
+ if __name__ == "__main__":
47
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/tree_playout.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pm4py.objects.log.importer.xes import importer as xes_importer
2
+ from pm4py.algo.discovery.inductive import algorithm as inductive_miner
3
+ from pm4py.algo.simulation.playout.process_tree import algorithm as tree_playout
4
+ import os
5
+ from pm4py.objects.log.obj import EventLog
6
+ from pm4py.objects.process_tree.obj import ProcessTree
7
+
8
+
9
+ def execute_script():
10
+ log: EventLog = xes_importer.apply(os.path.join("..", "tests", "input_data", "running-example.xes"))
11
+ tree: ProcessTree = inductive_miner.apply(log)
12
+ new_log_1: EventLog = tree_playout.apply(tree)
13
+ print(len(new_log_1))
14
+ new_tree_1: ProcessTree = inductive_miner.apply(new_log_1)
15
+ print(new_tree_1)
16
+ new_log_2: EventLog = tree_playout.apply(tree, variant=tree_playout.Variants.EXTENSIVE)
17
+ print(len(new_log_2))
18
+ new_tree_2: ProcessTree = inductive_miner.apply(new_log_2)
19
+ print(new_tree_2)
20
+
21
+
22
+ if __name__ == "__main__":
23
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/trie.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import pm4py
4
+ from pm4py.algo.transformation import log_to_trie
5
+ from examples import examples_conf
6
+ import importlib.util
7
+ import pandas
8
+ from pm4py.objects.trie.obj import Trie
9
+
10
+
11
+ def execute_script():
12
+ log: pandas.DataFrame = pm4py.read_xes(os.path.join("..", "tests", "input_data", "running-example.xes"))
13
+ trie: Trie = log_to_trie.algorithm.apply(log)
14
+
15
+ if importlib.util.find_spec("graphviz"):
16
+ from pm4py.visualization.trie import visualizer
17
+ gviz = visualizer.apply(trie, parameters={"format": examples_conf.TARGET_IMG_FORMAT})
18
+ visualizer.view(gviz)
19
+
20
+
21
+ if __name__ == "__main__":
22
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/validation_ocel20_relational.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pm4py.objects.ocel.validation import ocel20_rel_validation
2
+ from typing import Collection
3
+
4
+
5
+ def execute_script():
6
+ file_path: str = "../tests/input_data/ocel/ocel20_example.sqlite"
7
+
8
+ try:
9
+ satisfied: Collection[str]
10
+ unsatisfied: Collection[str]
11
+ satisfied, unsatisfied = ocel20_rel_validation.apply(file_path)
12
+ print("satisfied", satisfied)
13
+ print("unsatisfied", unsatisfied)
14
+ except:
15
+ print("Impossible to validate the OCEL!")
16
+
17
+
18
+ if __name__ == "__main__":
19
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/validation_ocel20_xml.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pm4py.objects.ocel.validation import xmlocel
2
+
3
+
4
+ def execute_script():
5
+ file_path: str = "../tests/input_data/ocel/ocel20_example.xmlocel"
6
+ validation_path: str = "../tests/input_data/ocel/ocel2-validation.xsd"
7
+
8
+ try:
9
+ is_valid = xmlocel.apply(file_path, validation_path)
10
+ print(is_valid)
11
+ except:
12
+ print("Impossible to validate the OCEL!")
13
+
14
+
15
+ if __name__ == "__main__":
16
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/variants_duration_vis.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pm4py
2
+ from pm4py.visualization.variants_duration import visualizer
3
+ import pandas
4
+
5
+
6
+ def execute_script():
7
+ log: pandas.DataFrame = pm4py.read_xes("../tests/input_data/receipt.xes")
8
+
9
+ # visualize the variants durations aligning on the start
10
+ gviz = visualizer.apply(log, parameters={"format": "svg", "alignment_criteria": "start"})
11
+ visualizer.view(gviz)
12
+
13
+ # visualize the variants durations aligning on the end
14
+ gviz = visualizer.apply(log, parameters={"format": "svg", "alignment_criteria": "end"})
15
+ visualizer.view(gviz)
16
+
17
+ # visualize the variants aligning on (the first occurrence of) a given activity
18
+ gviz = visualizer.apply(log, parameters={"format": "svg", "alignment_criteria": "T02 Check confirmation of receipt", "max_variants": 10})
19
+ visualizer.view(gviz)
20
+
21
+
22
+ if __name__ == "__main__":
23
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/variants_paths_duration.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pm4py
2
+ import pandas
3
+
4
+
5
+ def execute_script():
6
+ log: pandas.DataFrame = pm4py.read_xes("../tests/input_data/receipt.xes")
7
+ var_paths_durs: pandas.DataFrame = pm4py.get_variants_paths_duration(log)
8
+ print(var_paths_durs.columns)
9
+
10
+ # gets for each variant the average times (between all the cases of the given variant)
11
+ # between the activities 'Confirmation of receipt' and 'T02 Check confirmation of receipt'
12
+ df1: pandas.DataFrame = var_paths_durs[(var_paths_durs["concept:name"] == "Confirmation of receipt") & (var_paths_durs["concept:name_2"] == "T02 Check confirmation of receipt")]
13
+ print(df1[["@@variant_column", "@@flow_time"]])
14
+
15
+ # gets the paths which are repeated in some variants, along with the number of variants for which they are repeated
16
+ df2: pandas.DataFrame = var_paths_durs[var_paths_durs["@@cumulative_occ_path_column"] == 1]
17
+ print(df2.groupby(["concept:name", "concept:name_2"]).size())
18
+
19
+
20
+ if __name__ == "__main__":
21
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/visualization_align_table.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pm4py.objects.log.importer.xes import importer
3
+ from pm4py.algo.discovery.inductive import algorithm as inductive_miner
4
+ from pm4py.algo.conformance.alignments.petri_net import algorithm as alignments
5
+ from pm4py.objects.conversion.process_tree import converter as process_tree_converter
6
+ from examples import examples_conf
7
+ import importlib.util
8
+ from pm4py.objects.log.obj import EventLog
9
+ from pm4py.objects.petri_net.obj import Marking, PetriNet
10
+ from pm4py.objects.process_tree.obj import ProcessTree
11
+ from typing import Any
12
+
13
+
14
+ def execute_script():
15
+ log: EventLog = importer.apply(os.path.join("..", "tests", "input_data", "running-example.xes"))
16
+ process_tree: ProcessTree = inductive_miner.apply(log)
17
+ net: PetriNet
18
+ im: Marking
19
+ fm: Marking
20
+ net, im, fm = process_tree_converter.apply(process_tree)
21
+ aligned_traces: dict[str, Any] | list[dict[str, Any]] = alignments.apply(log, net, im, fm)
22
+
23
+ if importlib.util.find_spec("graphviz"):
24
+ from pm4py.visualization.align_table import visualizer
25
+ gviz = visualizer.apply(log, aligned_traces,
26
+ parameters={visualizer.Variants.CLASSIC.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
27
+ visualizer.view(gviz)
28
+
29
+
30
+ if __name__ == "__main__":
31
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/visualization_processtree.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pm4py.objects.log.importer.xes import importer
2
+ from pm4py.algo.discovery.inductive import algorithm as inductive_miner
3
+ from examples import examples_conf
4
+ import os
5
+ import importlib.util
6
+ from pm4py.objects.log.obj import EventLog
7
+ from pm4py.objects.process_tree.obj import ProcessTree
8
+
9
+
10
+ def execute_script():
11
+ log: EventLog = importer.apply(os.path.join("..", "tests", "input_data", "running-example.xes"))
12
+ tree: ProcessTree = inductive_miner.apply(log)
13
+
14
+ if importlib.util.find_spec("graphviz"):
15
+ from pm4py.visualization.process_tree import visualizer as pt_vis_factory
16
+ from pm4py.visualization.process_tree import visualizer as pt_visualizer
17
+
18
+ gviz1 = pt_vis_factory.apply(tree, parameters={"format": examples_conf.TARGET_IMG_FORMAT})
19
+ # pt_vis_factory.view(gviz1)
20
+ gviz2 = pt_visualizer.apply(tree, parameters={pt_visualizer.Variants.WO_DECORATION.value.Parameters.FORMAT: examples_conf.TARGET_IMG_FORMAT})
21
+ pt_visualizer.view(gviz2)
22
+
23
+
24
+ if __name__ == "__main__":
25
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/windows_key_mouse_logger.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pm4py.streaming.stream.live_event_stream import LiveEventStream
2
+ from pm4py.streaming.connectors.windows.click_key_logger import WindowsEventLogger
3
+ from pm4py.streaming.util.event_stream_printer import EventStreamPrinter
4
+ import time
5
+
6
+
7
+ def execute_script():
8
+ stream: LiveEventStream = LiveEventStream()
9
+ wel = WindowsEventLogger(stream, screenshots_folder="output")
10
+ printer: EventStreamPrinter = EventStreamPrinter()
11
+ stream.register(printer)
12
+ stream.start()
13
+ wel.start()
14
+
15
+ print("listening")
16
+
17
+ # listen only for 5 seconds
18
+ time.sleep(5)
19
+
20
+ wel.stop()
21
+ stream.stop()
22
+
23
+ print("stopped")
24
+
25
+
26
+ if __name__ == "__main__":
27
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/woflan.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pm4py.objects.log.importer.xes import importer as xes_importer
2
+ from pm4py.algo.discovery.alpha import algorithm as alpha_miner
3
+ from pm4py.algo.analysis.woflan import algorithm as woflan
4
+ import os
5
+ from pm4py.objects.log.obj import EventLog
6
+ from pm4py.objects.petri_net.obj import Marking, PetriNet
7
+
8
+
9
+ def execute_script():
10
+ log: EventLog = xes_importer.apply(os.path.join("..", "tests", "input_data", "running-example.xes"))
11
+ net: PetriNet
12
+ im: Marking
13
+ fm: Marking
14
+ net, im, fm = alpha_miner.apply(log)
15
+ is_sound, diagn = woflan.apply(net, im, fm, parameters={"print_diagnostics": True, "return_diagnostics": True})
16
+ print("is_sound", is_sound)
17
+ print(diagn)
18
+
19
+
20
+ if __name__ == "__main__":
21
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/examples/workalendar_example.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pm4py.util.business_hours import BusinessHours
2
+ from pm4py.util.dt_parsing.variants import strpfromiso
3
+ import datetime
4
+ from workalendar.europe import Italy
5
+ from pm4py.util import constants
6
+
7
+
8
+ def execute_script():
9
+ ts1: int = 100000000
10
+ ts2: int = 110000000
11
+ d1 = strpfromiso.fix_naivety(datetime.datetime.fromtimestamp(ts1))
12
+ d2 = strpfromiso.fix_naivety(datetime.datetime.fromtimestamp(ts2))
13
+ print(ts2-ts1)
14
+ # default business hours: all the days of the week except Saturday and Sunday are working days.
15
+ bh1: BusinessHours = BusinessHours(d1, d2, business_hour_slots=constants.DEFAULT_BUSINESS_HOUR_SLOTS)
16
+ print(bh1.get_seconds())
17
+ # let's calculate the business hours using a proper work calendar.
18
+ bh2: BusinessHours = BusinessHours(d1, d2, business_hour_slots=constants.DEFAULT_BUSINESS_HOUR_SLOTS, workcalendar=Italy())
19
+ print(bh2.get_seconds())
20
+
21
+
22
+ if __name__ == "__main__":
23
+ execute_script()
source_data/pinned/pm4py-process/tag-2.7.23.11/files/HOWTO_LINT.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ A quick way to fix most formatting issues (including “line too long” E501) across all Python files in a project is to use an *auto-formatter* such as **Black** or **autopep8**. These tools parse your Python files and automatically rewrite them so that they conform to PEP 8 (and other stylistic guidelines).
2
+
3
+ Below are two popular options:
4
+
5
+ ---
6
+
7
+ ## 1. **Using Black**
8
+
9
+ **Black** is a popular opinionated code formatter. It enforces consistent style (including line lengths) for your entire project.
10
+
11
+ 1. **Install Black** (if you haven’t already):
12
+ ```bash
13
+ pip install black
14
+ ```
15
+ 2. **Run Black** on your project directory:
16
+ ```bash
17
+ cd pm4py
18
+ black --line-length 79 .
19
+ ```
20
+ - `--line-length 79` matches the PEP 8 recommended max line length of 79 characters (which also aligns with E501).
21
+ - If you prefer a different line length (e.g., 88, which is Black’s default), adjust the `--line-length` accordingly.
22
+
23
+ Black will automatically reformat all `.py` files in the current directory (and subdirectories) to ensure lines do not exceed `--line-length`, among other style fixes.
24
+
25
+ ---
26
+
27
+ ## 2. **Using autopep8**
28
+
29
+ **autopep8** is another tool specifically designed to fix style issues reported by [pep8/pycodestyle](https://pypi.org/project/pycodestyle/). It can address line-length issues (E501) as well as many other common PEP 8 deviations.
30
+
31
+ 1. **Install autopep8**:
32
+ ```bash
33
+ pip install autopep8
34
+ ```
35
+ 2. **Run autopep8** recursively on your project:
36
+ ```bash
37
+ cd pm4py
38
+ autopep8 --in-place --recursive --max-line-length 79 .
39
+ ```
40
+ - `--in-place` modifies the files *in place* (rather than printing to stdout).
41
+ - `--recursive` applies the fix to all Python files in subfolders as well.
42
+ - `--max-line-length 79` sets the desired maximum line length.
43
+
44
+ > **Tip**: You can add `--aggressive --aggressive` to make autopep8 apply more extensive changes:
45
+ > ```bash
46
+ > autopep8 --in-place --recursive --aggressive --aggressive --max-line-length 79 .
47
+ > ```
48
+
49
+ **In Summary:**
50
+ - **Black** (opinionated but modern) can format all files in a single command:
51
+ ```bash
52
+ black --line-length 79 .
53
+ ```
54
+ - **autopep8** (closer to PEP 8) can specifically fix E501 line length errors (and more):
55
+ ```bash
56
+ autopep8 --in-place --recursive --max-line-length 79 .
57
+ ```
source_data/pinned/pm4py-process/tag-2.7.23.11/files/bundle.py ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # Hard-coded bundler: inputs ./micropm4py/, outputs ./bundled_package.py
3
+
4
+ from __future__ import annotations
5
+
6
+ import base64
7
+ import hashlib
8
+ import io
9
+ import lzma
10
+ import os
11
+ import sys
12
+ import time
13
+ import zipfile
14
+ from pathlib import Path
15
+ from string import Template
16
+
17
+ os.chdir("..")
18
+
19
+ PACKAGE_DIR = Path("pm4py") # folder containing __init__.py
20
+ OUTPUT_FILE = Path("bundled_package.py")
21
+ DEFAULT_MODE = "auto" # "auto" | "module" | "none"
22
+ ENTRYPOINT = None # e.g. "micropm4py.cli:main" or None
23
+
24
+
25
+ BUNDLE_TEMPLATE = Template(r"""# -*- coding: utf-8 -*-
26
+ # Generated by a hard-coded bundler on $timestamp
27
+ # Package: $pkg_name
28
+ # WARNING: This file is auto-generated. Edits may be overwritten.
29
+
30
+ import base64
31
+ import importlib
32
+ import io
33
+ import lzma
34
+ import os
35
+ import runpy
36
+ import sys
37
+ import tempfile
38
+ import time
39
+
40
+ _EMBEDDED_ZIP_LZMA_B85 = $zip_lzma_b85_literal
41
+ _PKG_NAME = $pkg_name_literal
42
+ _DEFAULT_MODE = $default_mode_literal # "auto" | "module" | "none"
43
+ _ENTRYPOINT = $entrypoint_literal # e.g. "pkg.module:main" or None
44
+
45
+ def _ensure_zip_on_sys_path():
46
+ digest = "sha256-" + $digest_literal
47
+ tempdir = tempfile.gettempdir()
48
+ zip_path = os.path.join(tempdir, f"{_PKG_NAME}-{digest}.pyz")
49
+
50
+ if not os.path.exists(zip_path):
51
+ data = lzma.decompress(base64.a85decode(_EMBEDDED_ZIP_LZMA_B85))
52
+ tmppath = zip_path + ".tmp-" + str(int(time.time() * 1000))
53
+ with open(tmppath, "wb") as f:
54
+ f.write(data)
55
+ try:
56
+ os.replace(tmppath, zip_path)
57
+ except Exception:
58
+ try:
59
+ os.rename(tmppath, zip_path)
60
+ finally:
61
+ try:
62
+ if os.path.exists(tmppath):
63
+ os.remove(tmppath)
64
+ except Exception:
65
+ pass
66
+
67
+ if zip_path not in sys.path:
68
+ sys.path.insert(0, zip_path)
69
+
70
+ def _maybe_run_entrypoint():
71
+ if _ENTRYPOINT:
72
+ mod, _, func = _ENTRYPOINT.partition(":")
73
+ if not mod or not func:
74
+ raise SystemExit(f"Invalid entrypoint {_ENTRYPOINT!r}; expected 'module:callable'")
75
+ module = importlib.import_module(mod)
76
+ target = getattr(module, func, None)
77
+ if target is None:
78
+ raise SystemExit(f"Entrypoint function {func!r} not found in module {mod!r}")
79
+ target()
80
+ return True
81
+
82
+ if _DEFAULT_MODE in ("module", "auto"):
83
+ try:
84
+ importlib.import_module(_PKG_NAME + ".__main__")
85
+ runpy.run_module(_PKG_NAME, run_name="__main__")
86
+ return True
87
+ except ModuleNotFoundError:
88
+ if _DEFAULT_MODE == "module":
89
+ raise SystemExit(f"Package {_PKG_NAME!r} has no __main__.py to run.")
90
+ return False
91
+
92
+ _ensure_zip_on_sys_path()
93
+
94
+ def bundled_contains(module_name: str) -> bool:
95
+ try:
96
+ importlib.import_module(module_name)
97
+ return True
98
+ except Exception:
99
+ return False
100
+
101
+ if __name__ == "__main__":
102
+ ran = _maybe_run_entrypoint()
103
+ if not ran and sys.stdout.isatty():
104
+ print(f"[bundle] Embedded package {_PKG_NAME!r} is on sys.path.")
105
+ print(f" - Import it: >>> import {_PKG_NAME}")
106
+ print(" - Or set an entrypoint inside this file and re-run.")
107
+ """)
108
+
109
+ def _require_pkg_dir(pkg_dir: Path) -> str:
110
+ if not pkg_dir.exists() or not pkg_dir.is_dir():
111
+ sys.exit(f"ERROR: package directory not found: {pkg_dir}")
112
+ init_py = pkg_dir / "__init__.py"
113
+ if not init_py.exists():
114
+ sys.exit(f"ERROR: {pkg_dir} is not a package (missing __init__.py).")
115
+ return pkg_dir.name
116
+
117
+ def _zip_package_with_parent(pkg_dir: Path) -> bytes:
118
+ parent = pkg_dir.parent
119
+ buf = io.BytesIO()
120
+ with zipfile.ZipFile(buf, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as zf:
121
+ for path in pkg_dir.rglob("*"):
122
+ if path.is_dir():
123
+ continue
124
+ arcname = path.relative_to(parent)
125
+ size = path.stat().st_size
126
+ print(f"[bundle] add {arcname} ({size} bytes)")
127
+ zf.write(path, arcname=str(arcname))
128
+ return buf.getvalue()
129
+
130
+ def _a85_literal(b: bytes, wrap: int = 120) -> str:
131
+ s = base64.a85encode(b, adobe=False).decode("ascii")
132
+ if wrap:
133
+ chunks = [s[i:i+wrap] for i in range(0, len(s), wrap)]
134
+ inner = "\n ".join(repr(chunk) for chunk in chunks)
135
+ return "(\n " + inner + "\n)"
136
+ return repr(s)
137
+
138
+ def _py_str(s: str) -> str:
139
+ return repr(s)
140
+
141
+ def _sha256(b: bytes) -> str:
142
+ import hashlib
143
+ return hashlib.sha256(b).hexdigest()
144
+
145
+ def main():
146
+ pkg_dir = PACKAGE_DIR.resolve()
147
+ pkg_name = _require_pkg_dir(pkg_dir)
148
+
149
+ zip_bytes = _zip_package_with_parent(pkg_dir)
150
+
151
+ # verify archive has expected top-level path
152
+ with zipfile.ZipFile(io.BytesIO(zip_bytes), "r") as zf:
153
+ expect = f"{pkg_name}/__init__.py"
154
+ if expect not in zf.namelist():
155
+ sys.exit(f"INTERNAL ERROR: expected {expect} in archive")
156
+
157
+ compressed_zip_bytes = lzma.compress(zip_bytes, preset=9)
158
+
159
+ out_text = BUNDLE_TEMPLATE.substitute(
160
+ timestamp=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
161
+ pkg_name=pkg_name,
162
+ pkg_name_literal=_py_str(pkg_name),
163
+ default_mode_literal=_py_str(DEFAULT_MODE),
164
+ entrypoint_literal=_py_str(ENTRYPOINT) if ENTRYPOINT else "None",
165
+ digest_literal=_py_str(_sha256(zip_bytes)),
166
+ zip_lzma_b85_literal=_a85_literal(compressed_zip_bytes),
167
+ )
168
+
169
+ out_path = OUTPUT_FILE.resolve()
170
+ out_path.write_text(out_text, encoding="utf-8")
171
+
172
+ # make executable on POSIX; harmless on Windows
173
+ try:
174
+ mode = out_path.stat().st_mode
175
+ out_path.chmod(mode | 0o111)
176
+ except Exception:
177
+ pass
178
+
179
+ print(f"Bundled {pkg_name!r} -> {out_path}")
180
+
181
+ if __name__ == "__main__":
182
+ main()
source_data/pinned/pm4py-process/tag-2.7.23.11/files/flake8.ini ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # .flake8
2
+ [flake8]
3
+ ignore = E501, F401, F403, F405, W503, W504, F841
source_data/pinned/pm4py-process/tag-2.7.23.11/files/flake8_score.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import sys
3
+
4
+
5
+ def lint_package_with_score(package_path, config_path=None, threshold=8):
6
+ """
7
+ Lint a Python package at the given path using flake8, compute a
8
+ 'quality score' based on the number of lint errors, and exit
9
+ with code 0 if score >= threshold, or 1 otherwise.
10
+
11
+ Args:
12
+ package_path (str): Path to the Python package or directory to lint.
13
+ config_path (str, optional): Path to a .flake8 config file.
14
+ threshold (int, optional): The score threshold. Default is 8.
15
+ """
16
+ # Build the flake8 command
17
+ command = ["flake8", package_path]
18
+
19
+ if config_path:
20
+ command.extend(["--config", config_path])
21
+
22
+ # Run flake8 and capture output
23
+ process = subprocess.run(command, capture_output=True, text=True)
24
+
25
+ # Print raw flake8 output
26
+ if process.stdout:
27
+ print("Flake8 STDOUT:\n", process.stdout)
28
+ if process.stderr:
29
+ print("Flake8 STDERR:\n", process.stderr, file=sys.stderr)
30
+
31
+ # Count the number of errors or warnings (each line in stdout usually represents one finding)
32
+ # You may need to adapt parsing logic if you have a different flake8 output format or plugins
33
+ lint_output_lines = process.stdout.strip().split('\n')
34
+
35
+ # If flake8 found absolutely nothing, the above split may return [''] instead of []
36
+ # so let's filter empty lines carefully.
37
+ lint_output_lines = [line for line in lint_output_lines if line.strip()]
38
+
39
+ num_errors = len(lint_output_lines)
40
+
41
+ # Define a simple "quality score" formula
42
+ score = max(1000 - num_errors, 0)
43
+
44
+ # Print the derived metrics
45
+ print(f"Number of lint findings (errors/warnings): {num_errors}")
46
+ print(f"Derived Quality Score: {score} (Threshold = {threshold})")
47
+
48
+ # Decide exit status based on whether we meet/exceed our threshold
49
+ if score >= threshold:
50
+ print("Quality threshold met or exceeded. Exiting with code 0.")
51
+ sys.exit(0)
52
+ else:
53
+ print("Quality threshold not reached. Exiting with code 1.")
54
+ sys.exit(1)
55
+
56
+
57
+ if __name__ == "__main__":
58
+ package_path = "../pm4py"
59
+ config_file = "flake8.ini"
60
+ quality_threshold = 200
61
+
62
+ lint_package_with_score(package_path, config_path=config_file, threshold=quality_threshold)
source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ /event_data.slides.html
2
+ /running_example_csv_exported_as_xes.xes
3
+ /running_example_exported.csv
4
+ /running_example_exported.csv
5
+ /running_example_xes_exported_as_csv.csv
source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/1_event_data.ipynb ADDED
@@ -0,0 +1,1176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {
6
+ "slideshow": {
7
+ "slide_type": "slide"
8
+ }
9
+ },
10
+ "source": [
11
+ "# Handling Event Data\n",
12
+ "*by: Sebastiaan J. van Zelst*"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "markdown",
17
+ "metadata": {
18
+ "slideshow": {
19
+ "slide_type": "notes"
20
+ }
21
+ },
22
+ "source": [
23
+ "Process mining exploits Event Logs to generate knowledge of a process.\n",
24
+ "A wide variety of information systems, e.g., SAP, ORACLE, SalesForce, etc., allow us to extract, in one way or the other,\n",
25
+ "event logs similar to the example event logs.\n",
26
+ "All the examples we show in this notebook and all algorithms implemented in pm4py assume that we have already extracted\n",
27
+ "the event data into an appropriate event log format.\n",
28
+ "Hence, the core of pm4py does not support any data extraction features.\n",
29
+ "\n",
30
+ "In order to support interoperability between different process mining tools and libraries, two standard data formats are\n",
31
+ "used to capture event logs, i.e., Comma Separated Value (CSV) files and eXtensible Event Stream (XES) files.\n",
32
+ "CSV files resemble the example tables shown in the previous section, i.e., Table 1 and Table 2. Each line in such a file\n",
33
+ "describes an event that occurred. The columns represent the same type of data, as shown in the examples, e.g., the case\n",
34
+ "for which the event occurred, the activity, the timestamp, the resource executing the activity, etc.\n",
35
+ "The XES file format is an XML-based format that allows us to describe process behavior.\n",
36
+ "We will not go into specific details w.r.t. the format of XES files, i.e., we refer to http://xes-standard.org/ for an\n",
37
+ "overview.\n",
38
+ "\n",
39
+ "In this tutorial, we will use an oftenly used dummy example event log to explain the basic process mining operations.\n",
40
+ "The process that we are considering is a simplified process related to customer complaint handling, i.e., taken from the\n",
41
+ "book of van der Aalst (https://www.springer.com/de/book/9783662498507). The process, and the event data we are going to\n",
42
+ "use, looks as follows."
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "markdown",
47
+ "metadata": {
48
+ "slideshow": {
49
+ "slide_type": "slide"
50
+ }
51
+ },
52
+ "source": [
53
+ "![Running example BPMN-based process model describing the behavior of the simple process that we use in this tutorial](img/bpmn_running_example.png)"
54
+ ]
55
+ },
56
+ {
57
+ "cell_type": "markdown",
58
+ "metadata": {
59
+ "slideshow": {
60
+ "slide_type": "slide"
61
+ }
62
+ },
63
+ "source": [
64
+ "## Importing CSV Files"
65
+ ]
66
+ },
67
+ {
68
+ "cell_type": "markdown",
69
+ "metadata": {
70
+ "slideshow": {
71
+ "slide_type": "notes"
72
+ }
73
+ },
74
+ "source": [
75
+ "Let’s get started!\n",
76
+ "We have prepared a small sample event log, containing behavior similar equal to the process model in Figure 3.\n",
77
+ "You can find the sample event log [here](data/running_example.csv).\n",
78
+ "\n",
79
+ "We are going to load the event data, and, we are going to count how many cases are present in the event log, as well as\n",
80
+ "the number of events. Note that, for all this, we are effectively using a third-party library called pandas.\n",
81
+ "We do so because pandas is the de-facto standard of loading/manipulating csv-based data.\n",
82
+ "Hence, any process mining algorithm implemented in pm4py, using an event log as an input, can work directly with a\n",
83
+ "pandas file!\n"
84
+ ]
85
+ },
86
+ {
87
+ "cell_type": "code",
88
+ "execution_count": 1,
89
+ "metadata": {
90
+ "pycharm": {
91
+ "name": "#%%\n"
92
+ },
93
+ "slideshow": {
94
+ "slide_type": "subslide"
95
+ }
96
+ },
97
+ "outputs": [
98
+ {
99
+ "data": {
100
+ "text/plain": " case_id activity timestamp costs org:resource\n0 3 register request 2010-12-30 14:32:00+01:00 50 Pete\n1 3 examine casually 2010-12-30 15:06:00+01:00 400 Mike\n2 3 check ticket 2010-12-30 16:34:00+01:00 100 Ellen\n3 3 decide 2011-01-06 09:18:00+01:00 200 Sara\n4 3 reinitiate request 2011-01-06 12:18:00+01:00 200 Sara\n5 3 examine thoroughly 2011-01-06 13:06:00+01:00 400 Sean\n6 3 check ticket 2011-01-08 11:43:00+01:00 100 Pete\n7 3 decide 2011-01-09 09:55:00+01:00 200 Sara\n8 3 pay compensation 2011-01-15 10:45:00+01:00 200 Ellen\n9 2 register request 2010-12-30 11:32:00+01:00 50 Mike\n10 2 check ticket 2010-12-30 12:12:00+01:00 100 Mike\n11 2 examine casually 2010-12-30 14:16:00+01:00 400 Sean\n12 2 decide 2011-01-05 11:22:00+01:00 200 Sara\n13 2 pay compensation 2011-01-08 12:05:00+01:00 200 Ellen\n14 1 register request 2010-12-30 11:02:00+01:00 50 Pete\n15 1 examine thoroughly 2010-12-31 10:06:00+01:00 400 Sue\n16 1 check ticket 2011-01-05 15:12:00+01:00 100 Mike\n17 1 decide 2011-01-06 11:18:00+01:00 200 Sara\n18 1 reject request 2011-01-07 14:24:00+01:00 200 Pete\n19 6 register request 2011-01-06 15:02:00+01:00 50 Mike\n20 6 examine casually 2011-01-06 16:06:00+01:00 400 Ellen\n21 6 check ticket 2011-01-07 16:22:00+01:00 100 Mike\n22 6 decide 2011-01-07 16:52:00+01:00 200 Sara\n23 6 pay compensation 2011-01-16 11:47:00+01:00 200 Mike\n24 5 register request 2011-01-06 09:02:00+01:00 50 Ellen\n25 5 examine casually 2011-01-07 10:16:00+01:00 400 Mike\n26 5 check ticket 2011-01-08 11:22:00+01:00 100 Pete\n27 5 decide 2011-01-10 13:28:00+01:00 200 Sara\n28 5 reinitiate request 2011-01-11 16:18:00+01:00 200 Sara\n29 5 check ticket 2011-01-14 14:33:00+01:00 100 Ellen\n30 5 examine casually 2011-01-16 15:50:00+01:00 400 Mike\n31 5 decide 2011-01-19 11:18:00+01:00 200 Sara\n32 5 reinitiate request 2011-01-20 12:48:00+01:00 200 Sara\n33 5 examine casually 2011-01-21 09:06:00+01:00 400 Sue\n34 5 check ticket 2011-01-21 11:34:00+01:00 100 Pete\n35 5 decide 2011-01-23 13:12:00+01:00 200 Sara\n36 5 reject request 2011-01-24 14:56:00+01:00 200 Mike\n37 4 register request 2011-01-06 15:02:00+01:00 50 Pete\n38 4 check ticket 2011-01-07 12:06:00+01:00 100 Mike\n39 4 examine thoroughly 2011-01-08 14:43:00+01:00 400 Sean\n40 4 decide 2011-01-09 12:02:00+01:00 200 Sara\n41 4 reject request 2011-01-12 15:44:00+01:00 200 Ellen",
101
+ "text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>case_id</th>\n <th>activity</th>\n <th>timestamp</th>\n <th>costs</th>\n <th>org:resource</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>3</td>\n <td>register request</td>\n <td>2010-12-30 14:32:00+01:00</td>\n <td>50</td>\n <td>Pete</td>\n </tr>\n <tr>\n <th>1</th>\n <td>3</td>\n <td>examine casually</td>\n <td>2010-12-30 15:06:00+01:00</td>\n <td>400</td>\n <td>Mike</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n <td>check ticket</td>\n <td>2010-12-30 16:34:00+01:00</td>\n <td>100</td>\n <td>Ellen</td>\n </tr>\n <tr>\n <th>3</th>\n <td>3</td>\n <td>decide</td>\n <td>2011-01-06 09:18:00+01:00</td>\n <td>200</td>\n <td>Sara</td>\n </tr>\n <tr>\n <th>4</th>\n <td>3</td>\n <td>reinitiate request</td>\n <td>2011-01-06 12:18:00+01:00</td>\n <td>200</td>\n <td>Sara</td>\n </tr>\n <tr>\n <th>5</th>\n <td>3</td>\n <td>examine thoroughly</td>\n <td>2011-01-06 13:06:00+01:00</td>\n <td>400</td>\n <td>Sean</td>\n </tr>\n <tr>\n <th>6</th>\n <td>3</td>\n <td>check ticket</td>\n <td>2011-01-08 11:43:00+01:00</td>\n <td>100</td>\n <td>Pete</td>\n </tr>\n <tr>\n <th>7</th>\n <td>3</td>\n <td>decide</td>\n <td>2011-01-09 09:55:00+01:00</td>\n <td>200</td>\n <td>Sara</td>\n </tr>\n <tr>\n <th>8</th>\n <td>3</td>\n <td>pay compensation</td>\n <td>2011-01-15 10:45:00+01:00</td>\n <td>200</td>\n <td>Ellen</td>\n </tr>\n <tr>\n <th>9</th>\n <td>2</td>\n <td>register request</td>\n <td>2010-12-30 11:32:00+01:00</td>\n <td>50</td>\n <td>Mike</td>\n </tr>\n <tr>\n <th>10</th>\n <td>2</td>\n <td>check ticket</td>\n <td>2010-12-30 12:12:00+01:00</td>\n <td>100</td>\n <td>Mike</td>\n </tr>\n <tr>\n <th>11</th>\n <td>2</td>\n <td>examine casually</td>\n <td>2010-12-30 14:16:00+01:00</td>\n <td>400</td>\n <td>Sean</td>\n </tr>\n <tr>\n <th>12</th>\n <td>2</td>\n <td>decide</td>\n <td>2011-01-05 11:22:00+01:00</td>\n <td>200</td>\n <td>Sara</td>\n </tr>\n <tr>\n <th>13</th>\n <td>2</td>\n <td>pay compensation</td>\n <td>2011-01-08 12:05:00+01:00</td>\n <td>200</td>\n <td>Ellen</td>\n </tr>\n <tr>\n <th>14</th>\n <td>1</td>\n <td>register request</td>\n <td>2010-12-30 11:02:00+01:00</td>\n <td>50</td>\n <td>Pete</td>\n </tr>\n <tr>\n <th>15</th>\n <td>1</td>\n <td>examine thoroughly</td>\n <td>2010-12-31 10:06:00+01:00</td>\n <td>400</td>\n <td>Sue</td>\n </tr>\n <tr>\n <th>16</th>\n <td>1</td>\n <td>check ticket</td>\n <td>2011-01-05 15:12:00+01:00</td>\n <td>100</td>\n <td>Mike</td>\n </tr>\n <tr>\n <th>17</th>\n <td>1</td>\n <td>decide</td>\n <td>2011-01-06 11:18:00+01:00</td>\n <td>200</td>\n <td>Sara</td>\n </tr>\n <tr>\n <th>18</th>\n <td>1</td>\n <td>reject request</td>\n <td>2011-01-07 14:24:00+01:00</td>\n <td>200</td>\n <td>Pete</td>\n </tr>\n <tr>\n <th>19</th>\n <td>6</td>\n <td>register request</td>\n <td>2011-01-06 15:02:00+01:00</td>\n <td>50</td>\n <td>Mike</td>\n </tr>\n <tr>\n <th>20</th>\n <td>6</td>\n <td>examine casually</td>\n <td>2011-01-06 16:06:00+01:00</td>\n <td>400</td>\n <td>Ellen</td>\n </tr>\n <tr>\n <th>21</th>\n <td>6</td>\n <td>check ticket</td>\n <td>2011-01-07 16:22:00+01:00</td>\n <td>100</td>\n <td>Mike</td>\n </tr>\n <tr>\n <th>22</th>\n <td>6</td>\n <td>decide</td>\n <td>2011-01-07 16:52:00+01:00</td>\n <td>200</td>\n <td>Sara</td>\n </tr>\n <tr>\n <th>23</th>\n <td>6</td>\n <td>pay compensation</td>\n <td>2011-01-16 11:47:00+01:00</td>\n <td>200</td>\n <td>Mike</td>\n </tr>\n <tr>\n <th>24</th>\n <td>5</td>\n <td>register request</td>\n <td>2011-01-06 09:02:00+01:00</td>\n <td>50</td>\n <td>Ellen</td>\n </tr>\n <tr>\n <th>25</th>\n <td>5</td>\n <td>examine casually</td>\n <td>2011-01-07 10:16:00+01:00</td>\n <td>400</td>\n <td>Mike</td>\n </tr>\n <tr>\n <th>26</th>\n <td>5</td>\n <td>check ticket</td>\n <td>2011-01-08 11:22:00+01:00</td>\n <td>100</td>\n <td>Pete</td>\n </tr>\n <tr>\n <th>27</th>\n <td>5</td>\n <td>decide</td>\n <td>2011-01-10 13:28:00+01:00</td>\n <td>200</td>\n <td>Sara</td>\n </tr>\n <tr>\n <th>28</th>\n <td>5</td>\n <td>reinitiate request</td>\n <td>2011-01-11 16:18:00+01:00</td>\n <td>200</td>\n <td>Sara</td>\n </tr>\n <tr>\n <th>29</th>\n <td>5</td>\n <td>check ticket</td>\n <td>2011-01-14 14:33:00+01:00</td>\n <td>100</td>\n <td>Ellen</td>\n </tr>\n <tr>\n <th>30</th>\n <td>5</td>\n <td>examine casually</td>\n <td>2011-01-16 15:50:00+01:00</td>\n <td>400</td>\n <td>Mike</td>\n </tr>\n <tr>\n <th>31</th>\n <td>5</td>\n <td>decide</td>\n <td>2011-01-19 11:18:00+01:00</td>\n <td>200</td>\n <td>Sara</td>\n </tr>\n <tr>\n <th>32</th>\n <td>5</td>\n <td>reinitiate request</td>\n <td>2011-01-20 12:48:00+01:00</td>\n <td>200</td>\n <td>Sara</td>\n </tr>\n <tr>\n <th>33</th>\n <td>5</td>\n <td>examine casually</td>\n <td>2011-01-21 09:06:00+01:00</td>\n <td>400</td>\n <td>Sue</td>\n </tr>\n <tr>\n <th>34</th>\n <td>5</td>\n <td>check ticket</td>\n <td>2011-01-21 11:34:00+01:00</td>\n <td>100</td>\n <td>Pete</td>\n </tr>\n <tr>\n <th>35</th>\n <td>5</td>\n <td>decide</td>\n <td>2011-01-23 13:12:00+01:00</td>\n <td>200</td>\n <td>Sara</td>\n </tr>\n <tr>\n <th>36</th>\n <td>5</td>\n <td>reject request</td>\n <td>2011-01-24 14:56:00+01:00</td>\n <td>200</td>\n <td>Mike</td>\n </tr>\n <tr>\n <th>37</th>\n <td>4</td>\n <td>register request</td>\n <td>2011-01-06 15:02:00+01:00</td>\n <td>50</td>\n <td>Pete</td>\n </tr>\n <tr>\n <th>38</th>\n <td>4</td>\n <td>check ticket</td>\n <td>2011-01-07 12:06:00+01:00</td>\n <td>100</td>\n <td>Mike</td>\n </tr>\n <tr>\n <th>39</th>\n <td>4</td>\n <td>examine thoroughly</td>\n <td>2011-01-08 14:43:00+01:00</td>\n <td>400</td>\n <td>Sean</td>\n </tr>\n <tr>\n <th>40</th>\n <td>4</td>\n <td>decide</td>\n <td>2011-01-09 12:02:00+01:00</td>\n <td>200</td>\n <td>Sara</td>\n </tr>\n <tr>\n <th>41</th>\n <td>4</td>\n <td>reject request</td>\n <td>2011-01-12 15:44:00+01:00</td>\n <td>200</td>\n <td>Ellen</td>\n </tr>\n </tbody>\n</table>\n</div>"
102
+ },
103
+ "execution_count": 1,
104
+ "metadata": {},
105
+ "output_type": "execute_result"
106
+ }
107
+ ],
108
+ "source": [
109
+ "import pandas as pd\n",
110
+ "\n",
111
+ "df = pd.read_csv('data/running_example.csv', sep=';')\n",
112
+ "df"
113
+ ]
114
+ },
115
+ {
116
+ "cell_type": "markdown",
117
+ "metadata": {
118
+ "slideshow": {
119
+ "slide_type": "notes"
120
+ }
121
+ },
122
+ "source": [
123
+ "Let's inspect the small event log.\n",
124
+ "The first line (i.e., row) specifies the name of each column (i.e., event attribute).\n",
125
+ "Observe that, in the data table described by the file, we have 5 columns, being: *case_id*, *activity*,\n",
126
+ "*timestamp*, *costs* and *org:resource*.\n",
127
+ "The first column represents the *case identifier*, i.e., allowing us to identify what activity has been logged in the\n",
128
+ "context of what instance of the process.\n",
129
+ "The second column (*activity*) records the activity that has been performed.\n",
130
+ "The third column shows at what point in time the activity was recorded (*timestamp*).\n",
131
+ "In this example data, additional information is present as well.\n",
132
+ "In this case, the fourth column tracks the costs of the activity (*costs* attribute), whereas the fifth row tracks what\n",
133
+ "resource has performed the activity (*org:resource*).\n",
134
+ "\n",
135
+ "Observe that, row 2-10 show the events that have been recorded for the process identified by *case identifier* 3.\n",
136
+ "We observe that first a register request activity was performed, followed by the examine casually, check ticket, decide,\n",
137
+ "reinitiate request, examine thoroughly, check ticket,decide, and finally, pay compensation activities.\n",
138
+ "Note that, in this case, the recorded process instance behaves as described by the model depicted in Figure 3.\n",
139
+ "\n",
140
+ "Let's investigate some basic statistics of our log, e.g., the total number of cases described and the total number of events."
141
+ ]
142
+ },
143
+ {
144
+ "cell_type": "code",
145
+ "execution_count": 3,
146
+ "metadata": {
147
+ "pycharm": {
148
+ "name": "#%%\n"
149
+ },
150
+ "slideshow": {
151
+ "slide_type": "subslide"
152
+ }
153
+ },
154
+ "outputs": [
155
+ {
156
+ "data": {
157
+ "text/plain": [
158
+ "6"
159
+ ]
160
+ },
161
+ "execution_count": 3,
162
+ "metadata": {},
163
+ "output_type": "execute_result"
164
+ }
165
+ ],
166
+ "source": [
167
+ "# number of cases\n",
168
+ "len(df['case_id'].unique())"
169
+ ]
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ "execution_count": 4,
174
+ "metadata": {
175
+ "pycharm": {
176
+ "name": "#%%\n"
177
+ },
178
+ "slideshow": {
179
+ "slide_type": "subslide"
180
+ }
181
+ },
182
+ "outputs": [
183
+ {
184
+ "data": {
185
+ "text/plain": [
186
+ "42"
187
+ ]
188
+ },
189
+ "execution_count": 4,
190
+ "metadata": {},
191
+ "output_type": "execute_result"
192
+ }
193
+ ],
194
+ "source": [
195
+ "# number of events\n",
196
+ "len(df)\n"
197
+ ]
198
+ },
199
+ {
200
+ "cell_type": "markdown",
201
+ "metadata": {
202
+ "slideshow": {
203
+ "slide_type": "slide"
204
+ }
205
+ },
206
+ "source": [
207
+ "### Formatting Data Frames"
208
+ ]
209
+ },
210
+ {
211
+ "cell_type": "markdown",
212
+ "metadata": {
213
+ "slideshow": {
214
+ "slide_type": "notes"
215
+ }
216
+ },
217
+ "source": [
218
+ "Now we have loaded our first event log, it is time to put some pm4py into the mix.\n",
219
+ "pm4py uses standardized column names to represent the *case identifier*, the *activity name* and the timstamp.\n",
220
+ "These are, respectively, ```case:concept:name```, ```concept:name``` and ```time:timestamp```.\n",
221
+ "Hence, to make pm4py work with the provided csv file, we need to rename the ```case_id```, ```activity``` and ```timestamp``` columns.\n",
222
+ "pm4py provides a dedicated utility function for this:"
223
+ ]
224
+ },
225
+ {
226
+ "cell_type": "code",
227
+ "execution_count": 5,
228
+ "metadata": {
229
+ "pycharm": {
230
+ "name": "#%%\n"
231
+ },
232
+ "slideshow": {
233
+ "slide_type": "subslide"
234
+ }
235
+ },
236
+ "outputs": [
237
+ {
238
+ "data": {
239
+ "text/html": [
240
+ "<div>\n",
241
+ "<style scoped>\n",
242
+ " .dataframe tbody tr th:only-of-type {\n",
243
+ " vertical-align: middle;\n",
244
+ " }\n",
245
+ "\n",
246
+ " .dataframe tbody tr th {\n",
247
+ " vertical-align: top;\n",
248
+ " }\n",
249
+ "\n",
250
+ " .dataframe thead th {\n",
251
+ " text-align: right;\n",
252
+ " }\n",
253
+ "</style>\n",
254
+ "<table border=\"1\" class=\"dataframe\">\n",
255
+ " <thead>\n",
256
+ " <tr style=\"text-align: right;\">\n",
257
+ " <th></th>\n",
258
+ " <th>case:concept:name</th>\n",
259
+ " <th>concept:name</th>\n",
260
+ " <th>time:timestamp</th>\n",
261
+ " <th>costs</th>\n",
262
+ " <th>org:resource</th>\n",
263
+ " <th>@@index</th>\n",
264
+ " </tr>\n",
265
+ " </thead>\n",
266
+ " <tbody>\n",
267
+ " <tr>\n",
268
+ " <th>14</th>\n",
269
+ " <td>1</td>\n",
270
+ " <td>register request</td>\n",
271
+ " <td>2010-12-30 10:02:00+00:00</td>\n",
272
+ " <td>50</td>\n",
273
+ " <td>Pete</td>\n",
274
+ " <td>14</td>\n",
275
+ " </tr>\n",
276
+ " <tr>\n",
277
+ " <th>15</th>\n",
278
+ " <td>1</td>\n",
279
+ " <td>examine thoroughly</td>\n",
280
+ " <td>2010-12-31 09:06:00+00:00</td>\n",
281
+ " <td>400</td>\n",
282
+ " <td>Sue</td>\n",
283
+ " <td>15</td>\n",
284
+ " </tr>\n",
285
+ " <tr>\n",
286
+ " <th>16</th>\n",
287
+ " <td>1</td>\n",
288
+ " <td>check ticket</td>\n",
289
+ " <td>2011-01-05 14:12:00+00:00</td>\n",
290
+ " <td>100</td>\n",
291
+ " <td>Mike</td>\n",
292
+ " <td>16</td>\n",
293
+ " </tr>\n",
294
+ " <tr>\n",
295
+ " <th>17</th>\n",
296
+ " <td>1</td>\n",
297
+ " <td>decide</td>\n",
298
+ " <td>2011-01-06 10:18:00+00:00</td>\n",
299
+ " <td>200</td>\n",
300
+ " <td>Sara</td>\n",
301
+ " <td>17</td>\n",
302
+ " </tr>\n",
303
+ " <tr>\n",
304
+ " <th>18</th>\n",
305
+ " <td>1</td>\n",
306
+ " <td>reject request</td>\n",
307
+ " <td>2011-01-07 13:24:00+00:00</td>\n",
308
+ " <td>200</td>\n",
309
+ " <td>Pete</td>\n",
310
+ " <td>18</td>\n",
311
+ " </tr>\n",
312
+ " <tr>\n",
313
+ " <th>9</th>\n",
314
+ " <td>2</td>\n",
315
+ " <td>register request</td>\n",
316
+ " <td>2010-12-30 10:32:00+00:00</td>\n",
317
+ " <td>50</td>\n",
318
+ " <td>Mike</td>\n",
319
+ " <td>9</td>\n",
320
+ " </tr>\n",
321
+ " <tr>\n",
322
+ " <th>10</th>\n",
323
+ " <td>2</td>\n",
324
+ " <td>check ticket</td>\n",
325
+ " <td>2010-12-30 11:12:00+00:00</td>\n",
326
+ " <td>100</td>\n",
327
+ " <td>Mike</td>\n",
328
+ " <td>10</td>\n",
329
+ " </tr>\n",
330
+ " <tr>\n",
331
+ " <th>11</th>\n",
332
+ " <td>2</td>\n",
333
+ " <td>examine casually</td>\n",
334
+ " <td>2010-12-30 13:16:00+00:00</td>\n",
335
+ " <td>400</td>\n",
336
+ " <td>Sean</td>\n",
337
+ " <td>11</td>\n",
338
+ " </tr>\n",
339
+ " <tr>\n",
340
+ " <th>12</th>\n",
341
+ " <td>2</td>\n",
342
+ " <td>decide</td>\n",
343
+ " <td>2011-01-05 10:22:00+00:00</td>\n",
344
+ " <td>200</td>\n",
345
+ " <td>Sara</td>\n",
346
+ " <td>12</td>\n",
347
+ " </tr>\n",
348
+ " <tr>\n",
349
+ " <th>13</th>\n",
350
+ " <td>2</td>\n",
351
+ " <td>pay compensation</td>\n",
352
+ " <td>2011-01-08 11:05:00+00:00</td>\n",
353
+ " <td>200</td>\n",
354
+ " <td>Ellen</td>\n",
355
+ " <td>13</td>\n",
356
+ " </tr>\n",
357
+ " <tr>\n",
358
+ " <th>0</th>\n",
359
+ " <td>3</td>\n",
360
+ " <td>register request</td>\n",
361
+ " <td>2010-12-30 13:32:00+00:00</td>\n",
362
+ " <td>50</td>\n",
363
+ " <td>Pete</td>\n",
364
+ " <td>0</td>\n",
365
+ " </tr>\n",
366
+ " <tr>\n",
367
+ " <th>1</th>\n",
368
+ " <td>3</td>\n",
369
+ " <td>examine casually</td>\n",
370
+ " <td>2010-12-30 14:06:00+00:00</td>\n",
371
+ " <td>400</td>\n",
372
+ " <td>Mike</td>\n",
373
+ " <td>1</td>\n",
374
+ " </tr>\n",
375
+ " <tr>\n",
376
+ " <th>2</th>\n",
377
+ " <td>3</td>\n",
378
+ " <td>check ticket</td>\n",
379
+ " <td>2010-12-30 15:34:00+00:00</td>\n",
380
+ " <td>100</td>\n",
381
+ " <td>Ellen</td>\n",
382
+ " <td>2</td>\n",
383
+ " </tr>\n",
384
+ " <tr>\n",
385
+ " <th>3</th>\n",
386
+ " <td>3</td>\n",
387
+ " <td>decide</td>\n",
388
+ " <td>2011-01-06 08:18:00+00:00</td>\n",
389
+ " <td>200</td>\n",
390
+ " <td>Sara</td>\n",
391
+ " <td>3</td>\n",
392
+ " </tr>\n",
393
+ " <tr>\n",
394
+ " <th>4</th>\n",
395
+ " <td>3</td>\n",
396
+ " <td>reinitiate request</td>\n",
397
+ " <td>2011-01-06 11:18:00+00:00</td>\n",
398
+ " <td>200</td>\n",
399
+ " <td>Sara</td>\n",
400
+ " <td>4</td>\n",
401
+ " </tr>\n",
402
+ " <tr>\n",
403
+ " <th>5</th>\n",
404
+ " <td>3</td>\n",
405
+ " <td>examine thoroughly</td>\n",
406
+ " <td>2011-01-06 12:06:00+00:00</td>\n",
407
+ " <td>400</td>\n",
408
+ " <td>Sean</td>\n",
409
+ " <td>5</td>\n",
410
+ " </tr>\n",
411
+ " <tr>\n",
412
+ " <th>6</th>\n",
413
+ " <td>3</td>\n",
414
+ " <td>check ticket</td>\n",
415
+ " <td>2011-01-08 10:43:00+00:00</td>\n",
416
+ " <td>100</td>\n",
417
+ " <td>Pete</td>\n",
418
+ " <td>6</td>\n",
419
+ " </tr>\n",
420
+ " <tr>\n",
421
+ " <th>7</th>\n",
422
+ " <td>3</td>\n",
423
+ " <td>decide</td>\n",
424
+ " <td>2011-01-09 08:55:00+00:00</td>\n",
425
+ " <td>200</td>\n",
426
+ " <td>Sara</td>\n",
427
+ " <td>7</td>\n",
428
+ " </tr>\n",
429
+ " <tr>\n",
430
+ " <th>8</th>\n",
431
+ " <td>3</td>\n",
432
+ " <td>pay compensation</td>\n",
433
+ " <td>2011-01-15 09:45:00+00:00</td>\n",
434
+ " <td>200</td>\n",
435
+ " <td>Ellen</td>\n",
436
+ " <td>8</td>\n",
437
+ " </tr>\n",
438
+ " <tr>\n",
439
+ " <th>37</th>\n",
440
+ " <td>4</td>\n",
441
+ " <td>register request</td>\n",
442
+ " <td>2011-01-06 14:02:00+00:00</td>\n",
443
+ " <td>50</td>\n",
444
+ " <td>Pete</td>\n",
445
+ " <td>37</td>\n",
446
+ " </tr>\n",
447
+ " <tr>\n",
448
+ " <th>38</th>\n",
449
+ " <td>4</td>\n",
450
+ " <td>check ticket</td>\n",
451
+ " <td>2011-01-07 11:06:00+00:00</td>\n",
452
+ " <td>100</td>\n",
453
+ " <td>Mike</td>\n",
454
+ " <td>38</td>\n",
455
+ " </tr>\n",
456
+ " <tr>\n",
457
+ " <th>39</th>\n",
458
+ " <td>4</td>\n",
459
+ " <td>examine thoroughly</td>\n",
460
+ " <td>2011-01-08 13:43:00+00:00</td>\n",
461
+ " <td>400</td>\n",
462
+ " <td>Sean</td>\n",
463
+ " <td>39</td>\n",
464
+ " </tr>\n",
465
+ " <tr>\n",
466
+ " <th>40</th>\n",
467
+ " <td>4</td>\n",
468
+ " <td>decide</td>\n",
469
+ " <td>2011-01-09 11:02:00+00:00</td>\n",
470
+ " <td>200</td>\n",
471
+ " <td>Sara</td>\n",
472
+ " <td>40</td>\n",
473
+ " </tr>\n",
474
+ " <tr>\n",
475
+ " <th>41</th>\n",
476
+ " <td>4</td>\n",
477
+ " <td>reject request</td>\n",
478
+ " <td>2011-01-12 14:44:00+00:00</td>\n",
479
+ " <td>200</td>\n",
480
+ " <td>Ellen</td>\n",
481
+ " <td>41</td>\n",
482
+ " </tr>\n",
483
+ " <tr>\n",
484
+ " <th>24</th>\n",
485
+ " <td>5</td>\n",
486
+ " <td>register request</td>\n",
487
+ " <td>2011-01-06 08:02:00+00:00</td>\n",
488
+ " <td>50</td>\n",
489
+ " <td>Ellen</td>\n",
490
+ " <td>24</td>\n",
491
+ " </tr>\n",
492
+ " <tr>\n",
493
+ " <th>25</th>\n",
494
+ " <td>5</td>\n",
495
+ " <td>examine casually</td>\n",
496
+ " <td>2011-01-07 09:16:00+00:00</td>\n",
497
+ " <td>400</td>\n",
498
+ " <td>Mike</td>\n",
499
+ " <td>25</td>\n",
500
+ " </tr>\n",
501
+ " <tr>\n",
502
+ " <th>26</th>\n",
503
+ " <td>5</td>\n",
504
+ " <td>check ticket</td>\n",
505
+ " <td>2011-01-08 10:22:00+00:00</td>\n",
506
+ " <td>100</td>\n",
507
+ " <td>Pete</td>\n",
508
+ " <td>26</td>\n",
509
+ " </tr>\n",
510
+ " <tr>\n",
511
+ " <th>27</th>\n",
512
+ " <td>5</td>\n",
513
+ " <td>decide</td>\n",
514
+ " <td>2011-01-10 12:28:00+00:00</td>\n",
515
+ " <td>200</td>\n",
516
+ " <td>Sara</td>\n",
517
+ " <td>27</td>\n",
518
+ " </tr>\n",
519
+ " <tr>\n",
520
+ " <th>28</th>\n",
521
+ " <td>5</td>\n",
522
+ " <td>reinitiate request</td>\n",
523
+ " <td>2011-01-11 15:18:00+00:00</td>\n",
524
+ " <td>200</td>\n",
525
+ " <td>Sara</td>\n",
526
+ " <td>28</td>\n",
527
+ " </tr>\n",
528
+ " <tr>\n",
529
+ " <th>29</th>\n",
530
+ " <td>5</td>\n",
531
+ " <td>check ticket</td>\n",
532
+ " <td>2011-01-14 13:33:00+00:00</td>\n",
533
+ " <td>100</td>\n",
534
+ " <td>Ellen</td>\n",
535
+ " <td>29</td>\n",
536
+ " </tr>\n",
537
+ " <tr>\n",
538
+ " <th>30</th>\n",
539
+ " <td>5</td>\n",
540
+ " <td>examine casually</td>\n",
541
+ " <td>2011-01-16 14:50:00+00:00</td>\n",
542
+ " <td>400</td>\n",
543
+ " <td>Mike</td>\n",
544
+ " <td>30</td>\n",
545
+ " </tr>\n",
546
+ " <tr>\n",
547
+ " <th>31</th>\n",
548
+ " <td>5</td>\n",
549
+ " <td>decide</td>\n",
550
+ " <td>2011-01-19 10:18:00+00:00</td>\n",
551
+ " <td>200</td>\n",
552
+ " <td>Sara</td>\n",
553
+ " <td>31</td>\n",
554
+ " </tr>\n",
555
+ " <tr>\n",
556
+ " <th>32</th>\n",
557
+ " <td>5</td>\n",
558
+ " <td>reinitiate request</td>\n",
559
+ " <td>2011-01-20 11:48:00+00:00</td>\n",
560
+ " <td>200</td>\n",
561
+ " <td>Sara</td>\n",
562
+ " <td>32</td>\n",
563
+ " </tr>\n",
564
+ " <tr>\n",
565
+ " <th>33</th>\n",
566
+ " <td>5</td>\n",
567
+ " <td>examine casually</td>\n",
568
+ " <td>2011-01-21 08:06:00+00:00</td>\n",
569
+ " <td>400</td>\n",
570
+ " <td>Sue</td>\n",
571
+ " <td>33</td>\n",
572
+ " </tr>\n",
573
+ " <tr>\n",
574
+ " <th>34</th>\n",
575
+ " <td>5</td>\n",
576
+ " <td>check ticket</td>\n",
577
+ " <td>2011-01-21 10:34:00+00:00</td>\n",
578
+ " <td>100</td>\n",
579
+ " <td>Pete</td>\n",
580
+ " <td>34</td>\n",
581
+ " </tr>\n",
582
+ " <tr>\n",
583
+ " <th>35</th>\n",
584
+ " <td>5</td>\n",
585
+ " <td>decide</td>\n",
586
+ " <td>2011-01-23 12:12:00+00:00</td>\n",
587
+ " <td>200</td>\n",
588
+ " <td>Sara</td>\n",
589
+ " <td>35</td>\n",
590
+ " </tr>\n",
591
+ " <tr>\n",
592
+ " <th>36</th>\n",
593
+ " <td>5</td>\n",
594
+ " <td>reject request</td>\n",
595
+ " <td>2011-01-24 13:56:00+00:00</td>\n",
596
+ " <td>200</td>\n",
597
+ " <td>Mike</td>\n",
598
+ " <td>36</td>\n",
599
+ " </tr>\n",
600
+ " <tr>\n",
601
+ " <th>19</th>\n",
602
+ " <td>6</td>\n",
603
+ " <td>register request</td>\n",
604
+ " <td>2011-01-06 14:02:00+00:00</td>\n",
605
+ " <td>50</td>\n",
606
+ " <td>Mike</td>\n",
607
+ " <td>19</td>\n",
608
+ " </tr>\n",
609
+ " <tr>\n",
610
+ " <th>20</th>\n",
611
+ " <td>6</td>\n",
612
+ " <td>examine casually</td>\n",
613
+ " <td>2011-01-06 15:06:00+00:00</td>\n",
614
+ " <td>400</td>\n",
615
+ " <td>Ellen</td>\n",
616
+ " <td>20</td>\n",
617
+ " </tr>\n",
618
+ " <tr>\n",
619
+ " <th>21</th>\n",
620
+ " <td>6</td>\n",
621
+ " <td>check ticket</td>\n",
622
+ " <td>2011-01-07 15:22:00+00:00</td>\n",
623
+ " <td>100</td>\n",
624
+ " <td>Mike</td>\n",
625
+ " <td>21</td>\n",
626
+ " </tr>\n",
627
+ " <tr>\n",
628
+ " <th>22</th>\n",
629
+ " <td>6</td>\n",
630
+ " <td>decide</td>\n",
631
+ " <td>2011-01-07 15:52:00+00:00</td>\n",
632
+ " <td>200</td>\n",
633
+ " <td>Sara</td>\n",
634
+ " <td>22</td>\n",
635
+ " </tr>\n",
636
+ " <tr>\n",
637
+ " <th>23</th>\n",
638
+ " <td>6</td>\n",
639
+ " <td>pay compensation</td>\n",
640
+ " <td>2011-01-16 10:47:00+00:00</td>\n",
641
+ " <td>200</td>\n",
642
+ " <td>Mike</td>\n",
643
+ " <td>23</td>\n",
644
+ " </tr>\n",
645
+ " </tbody>\n",
646
+ "</table>\n",
647
+ "</div>"
648
+ ],
649
+ "text/plain": [
650
+ " case:concept:name concept:name time:timestamp costs \\\n",
651
+ "14 1 register request 2010-12-30 10:02:00+00:00 50 \n",
652
+ "15 1 examine thoroughly 2010-12-31 09:06:00+00:00 400 \n",
653
+ "16 1 check ticket 2011-01-05 14:12:00+00:00 100 \n",
654
+ "17 1 decide 2011-01-06 10:18:00+00:00 200 \n",
655
+ "18 1 reject request 2011-01-07 13:24:00+00:00 200 \n",
656
+ "9 2 register request 2010-12-30 10:32:00+00:00 50 \n",
657
+ "10 2 check ticket 2010-12-30 11:12:00+00:00 100 \n",
658
+ "11 2 examine casually 2010-12-30 13:16:00+00:00 400 \n",
659
+ "12 2 decide 2011-01-05 10:22:00+00:00 200 \n",
660
+ "13 2 pay compensation 2011-01-08 11:05:00+00:00 200 \n",
661
+ "0 3 register request 2010-12-30 13:32:00+00:00 50 \n",
662
+ "1 3 examine casually 2010-12-30 14:06:00+00:00 400 \n",
663
+ "2 3 check ticket 2010-12-30 15:34:00+00:00 100 \n",
664
+ "3 3 decide 2011-01-06 08:18:00+00:00 200 \n",
665
+ "4 3 reinitiate request 2011-01-06 11:18:00+00:00 200 \n",
666
+ "5 3 examine thoroughly 2011-01-06 12:06:00+00:00 400 \n",
667
+ "6 3 check ticket 2011-01-08 10:43:00+00:00 100 \n",
668
+ "7 3 decide 2011-01-09 08:55:00+00:00 200 \n",
669
+ "8 3 pay compensation 2011-01-15 09:45:00+00:00 200 \n",
670
+ "37 4 register request 2011-01-06 14:02:00+00:00 50 \n",
671
+ "38 4 check ticket 2011-01-07 11:06:00+00:00 100 \n",
672
+ "39 4 examine thoroughly 2011-01-08 13:43:00+00:00 400 \n",
673
+ "40 4 decide 2011-01-09 11:02:00+00:00 200 \n",
674
+ "41 4 reject request 2011-01-12 14:44:00+00:00 200 \n",
675
+ "24 5 register request 2011-01-06 08:02:00+00:00 50 \n",
676
+ "25 5 examine casually 2011-01-07 09:16:00+00:00 400 \n",
677
+ "26 5 check ticket 2011-01-08 10:22:00+00:00 100 \n",
678
+ "27 5 decide 2011-01-10 12:28:00+00:00 200 \n",
679
+ "28 5 reinitiate request 2011-01-11 15:18:00+00:00 200 \n",
680
+ "29 5 check ticket 2011-01-14 13:33:00+00:00 100 \n",
681
+ "30 5 examine casually 2011-01-16 14:50:00+00:00 400 \n",
682
+ "31 5 decide 2011-01-19 10:18:00+00:00 200 \n",
683
+ "32 5 reinitiate request 2011-01-20 11:48:00+00:00 200 \n",
684
+ "33 5 examine casually 2011-01-21 08:06:00+00:00 400 \n",
685
+ "34 5 check ticket 2011-01-21 10:34:00+00:00 100 \n",
686
+ "35 5 decide 2011-01-23 12:12:00+00:00 200 \n",
687
+ "36 5 reject request 2011-01-24 13:56:00+00:00 200 \n",
688
+ "19 6 register request 2011-01-06 14:02:00+00:00 50 \n",
689
+ "20 6 examine casually 2011-01-06 15:06:00+00:00 400 \n",
690
+ "21 6 check ticket 2011-01-07 15:22:00+00:00 100 \n",
691
+ "22 6 decide 2011-01-07 15:52:00+00:00 200 \n",
692
+ "23 6 pay compensation 2011-01-16 10:47:00+00:00 200 \n",
693
+ "\n",
694
+ " org:resource @@index \n",
695
+ "14 Pete 14 \n",
696
+ "15 Sue 15 \n",
697
+ "16 Mike 16 \n",
698
+ "17 Sara 17 \n",
699
+ "18 Pete 18 \n",
700
+ "9 Mike 9 \n",
701
+ "10 Mike 10 \n",
702
+ "11 Sean 11 \n",
703
+ "12 Sara 12 \n",
704
+ "13 Ellen 13 \n",
705
+ "0 Pete 0 \n",
706
+ "1 Mike 1 \n",
707
+ "2 Ellen 2 \n",
708
+ "3 Sara 3 \n",
709
+ "4 Sara 4 \n",
710
+ "5 Sean 5 \n",
711
+ "6 Pete 6 \n",
712
+ "7 Sara 7 \n",
713
+ "8 Ellen 8 \n",
714
+ "37 Pete 37 \n",
715
+ "38 Mike 38 \n",
716
+ "39 Sean 39 \n",
717
+ "40 Sara 40 \n",
718
+ "41 Ellen 41 \n",
719
+ "24 Ellen 24 \n",
720
+ "25 Mike 25 \n",
721
+ "26 Pete 26 \n",
722
+ "27 Sara 27 \n",
723
+ "28 Sara 28 \n",
724
+ "29 Ellen 29 \n",
725
+ "30 Mike 30 \n",
726
+ "31 Sara 31 \n",
727
+ "32 Sara 32 \n",
728
+ "33 Sue 33 \n",
729
+ "34 Pete 34 \n",
730
+ "35 Sara 35 \n",
731
+ "36 Mike 36 \n",
732
+ "19 Mike 19 \n",
733
+ "20 Ellen 20 \n",
734
+ "21 Mike 21 \n",
735
+ "22 Sara 22 \n",
736
+ "23 Mike 23 "
737
+ ]
738
+ },
739
+ "execution_count": 5,
740
+ "metadata": {},
741
+ "output_type": "execute_result"
742
+ }
743
+ ],
744
+ "source": [
745
+ "import pm4py\n",
746
+ "log = pm4py.format_dataframe(df, case_id='case_id',activity_key='activity',\n",
747
+ " timestamp_key='timestamp')\n",
748
+ "log\n"
749
+ ]
750
+ },
751
+ {
752
+ "cell_type": "markdown",
753
+ "metadata": {
754
+ "pycharm": {
755
+ "name": "#%% md\n"
756
+ },
757
+ "slideshow": {
758
+ "slide_type": "notes"
759
+ }
760
+ },
761
+ "source": [
762
+ "Observe that the column names are updated as expected.\n",
763
+ "\n",
764
+ "Let us assume that we are not only interested in the number of events and cases, yet, we also want to figure out what\n",
765
+ "activities occur first, and what activities occur last in the traces described by the event log.\n",
766
+ "pm4py has a specific built-in function for this, i.e., ```pm4py.get_start_activities()``` and ```pm4py.get_end_activities()``` respectively."
767
+ ]
768
+ },
769
+ {
770
+ "cell_type": "code",
771
+ "execution_count": 6,
772
+ "metadata": {
773
+ "pycharm": {
774
+ "name": "#%%\n"
775
+ },
776
+ "slideshow": {
777
+ "slide_type": "subslide"
778
+ }
779
+ },
780
+ "outputs": [
781
+ {
782
+ "data": {
783
+ "text/plain": [
784
+ "{'register request': 6}"
785
+ ]
786
+ },
787
+ "execution_count": 6,
788
+ "metadata": {},
789
+ "output_type": "execute_result"
790
+ }
791
+ ],
792
+ "source": [
793
+ "pm4py.get_start_activities(log)"
794
+ ]
795
+ },
796
+ {
797
+ "cell_type": "code",
798
+ "execution_count": 7,
799
+ "metadata": {
800
+ "pycharm": {
801
+ "name": "#%%\n"
802
+ },
803
+ "slideshow": {
804
+ "slide_type": "subslide"
805
+ }
806
+ },
807
+ "outputs": [
808
+ {
809
+ "data": {
810
+ "text/plain": [
811
+ "{'pay compensation': 3, 'reject request': 3}"
812
+ ]
813
+ },
814
+ "execution_count": 7,
815
+ "metadata": {},
816
+ "output_type": "execute_result"
817
+ }
818
+ ],
819
+ "source": [
820
+ "pm4py.get_end_activities(log)"
821
+ ]
822
+ },
823
+ {
824
+ "cell_type": "markdown",
825
+ "metadata": {
826
+ "slideshow": {
827
+ "slide_type": "notes"
828
+ }
829
+ },
830
+ "source": [
831
+ "The ```pm4py.get_start_activities()``` and ```pm4py.get_end_activities()``` both return a dictionary containing the activities\n",
832
+ "as a key, and, the number of observations (i.e., number of traces in which they occur first, respectively, last) in\n",
833
+ "the event log.\n",
834
+ "\n",
835
+ "pm4py exploits a built-in pandas function to detect the format of the timestamps in the input data automatically.\n",
836
+ "However, pandas looks at the timestamp values in each row in isolation.\n",
837
+ "In some cases, this can lead to problems.\n",
838
+ "For example, if the provided value is 2020-01-18, i.e., first the year, then the month, and then the day of the date,\n",
839
+ "in some cases, a value of 2020-02-01 may be interpreted wrongly as January 2nd, i.e., rather than February 1st.\n",
840
+ "To alleviate this problem, an additional parameter can be provided to the ```format_dataframe()``` method, i.e.,\n",
841
+ "the timest_format parameter. The default Python timestamp format codes can be used to provide the timestamp format.\n",
842
+ "In this example, the timestamp format is ```%Y-%m-%d %H:%M:%S%z```.\n",
843
+ "In general, we advise to always specify the timestamp format."
844
+ ]
845
+ },
846
+ {
847
+ "cell_type": "markdown",
848
+ "metadata": {
849
+ "pycharm": {
850
+ "name": "#%% md\n"
851
+ },
852
+ "slideshow": {
853
+ "slide_type": "slide"
854
+ }
855
+ },
856
+ "source": [
857
+ "## Importing XES Files"
858
+ ]
859
+ },
860
+ {
861
+ "cell_type": "markdown",
862
+ "metadata": {
863
+ "slideshow": {
864
+ "slide_type": "notes"
865
+ }
866
+ },
867
+ "source": [
868
+ "Next to CSV files, event data can also be stored in an XML-based format, i.e., in XES files.\n",
869
+ "In an XES file, we can describe a containment relation, i.e., a log contains a number of traces, which in turn contain several events.\n",
870
+ "Furthermore, an object, i.e., a log, trace, or event, is allowed to have attributes.\n",
871
+ "The advantage is that certain data attributes that are constant for a log or a trace, can be stored at that level.\n",
872
+ "For example, assume that we only know the total costs of a case, rather than the costs of the individual events.\n",
873
+ "If we want to store this information in a CSV file, we either need to replicate this information (i.e., we can only\n",
874
+ "store data in rows, which directly refer to events), or, we need to explicitly define that certain columns only get a\n",
875
+ "value once, i.e., referring to case-level attributes.\n",
876
+ "The XES standard more naturally supports the storage of this type of information.\n",
877
+ "Click [here](data/running_example.xes) to obtain the .xes file of the running_example.\n",
878
+ "\n",
879
+ "Importing an XES file is fairly straightforward.\n",
880
+ "pm4py has a special read_xes()-function that can parse a given xes file and load it in pm4py, i.e., as an Event Log object.\n",
881
+ "Consider the following code snippet, in which we show how to import an XES event log.\n",
882
+ "Like the previous example, the script outputs activities that can start and end a trace."
883
+ ]
884
+ },
885
+ {
886
+ "cell_type": "code",
887
+ "execution_count": 12,
888
+ "metadata": {
889
+ "pycharm": {
890
+ "name": "#%%\n"
891
+ },
892
+ "slideshow": {
893
+ "slide_type": "subslide"
894
+ }
895
+ },
896
+ "outputs": [
897
+ {
898
+ "data": {
899
+ "application/vnd.jupyter.widget-view+json": {
900
+ "model_id": "a356969d9a9b4ffa928c5670f630d3fc",
901
+ "version_major": 2,
902
+ "version_minor": 0
903
+ },
904
+ "text/plain": [
905
+ "parsing log, completed traces :: 0%| | 0/6 [00:00<?, ?it/s]"
906
+ ]
907
+ },
908
+ "metadata": {},
909
+ "output_type": "display_data"
910
+ },
911
+ {
912
+ "data": {
913
+ "text/plain": [
914
+ "{'register request': 6}"
915
+ ]
916
+ },
917
+ "execution_count": 12,
918
+ "metadata": {},
919
+ "output_type": "execute_result"
920
+ }
921
+ ],
922
+ "source": [
923
+ "log_xes = pm4py.read_xes('data/running_example.xes', return_legacy_log_object=True)\n",
924
+ "pm4py.get_start_activities(log_xes)"
925
+ ]
926
+ },
927
+ {
928
+ "cell_type": "code",
929
+ "execution_count": 13,
930
+ "metadata": {
931
+ "pycharm": {
932
+ "name": "#%%\n"
933
+ },
934
+ "slideshow": {
935
+ "slide_type": "subslide"
936
+ }
937
+ },
938
+ "outputs": [
939
+ {
940
+ "data": {
941
+ "text/plain": [
942
+ "{'pay compensation': 3, 'reject request': 3}"
943
+ ]
944
+ },
945
+ "execution_count": 13,
946
+ "metadata": {},
947
+ "output_type": "execute_result"
948
+ }
949
+ ],
950
+ "source": [
951
+ "pm4py.get_end_activities(log_xes)\n"
952
+ ]
953
+ },
954
+ {
955
+ "cell_type": "markdown",
956
+ "metadata": {
957
+ "slideshow": {
958
+ "slide_type": "slide"
959
+ }
960
+ },
961
+ "source": [
962
+ "## Exporting Event Data"
963
+ ]
964
+ },
965
+ {
966
+ "cell_type": "markdown",
967
+ "metadata": {
968
+ "slideshow": {
969
+ "slide_type": "notes"
970
+ }
971
+ },
972
+ "source": [
973
+ "Now we have seen how to import event data into pm4py, let’s take a look at the opposite, i.e., exporting event data.\n",
974
+ "Exporting of event logs can be very useful, e.g., we might want to convert a .csv file into a ```.xes``` file or we might\n",
975
+ "want to filter out certain (noisy) cases and save the filtered event log. Like importing, exporting of event data is\n",
976
+ "possible in two ways, i.e., exporting to ```csv``` (using ```pandas```) and exporting event logs to xes. In the upcoming\n",
977
+ "sections, we show how to export an event log stored as a ```pandas data frame``` into a ```csv``` file, a ```pandas data frame``` as an\n",
978
+ "```xes file```, a pm4py ```event log object``` as a ```csv file``` and finally, a pm4py ```event log object``` as an ```xes file```."
979
+ ]
980
+ },
981
+ {
982
+ "cell_type": "markdown",
983
+ "metadata": {
984
+ "slideshow": {
985
+ "slide_type": "slide"
986
+ }
987
+ },
988
+ "source": [
989
+ "### Storing a Pandas Data Frame as a csv file"
990
+ ]
991
+ },
992
+ {
993
+ "cell_type": "markdown",
994
+ "metadata": {
995
+ "slideshow": {
996
+ "slide_type": "notes"
997
+ }
998
+ },
999
+ "source": [
1000
+ "Storing an event log that is represented as a pandas dataframe is straightforward, i.e., we can directly use the ```to_csv```\n",
1001
+ " ([full reference here](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_csv.html)) function\n",
1002
+ " of the pandas DataFrame object. Consider the following example snippet of code, in which we show this functionality."
1003
+ ]
1004
+ },
1005
+ {
1006
+ "cell_type": "code",
1007
+ "execution_count": 14,
1008
+ "metadata": {
1009
+ "pycharm": {
1010
+ "name": "#%%\n"
1011
+ },
1012
+ "slideshow": {
1013
+ "slide_type": "subslide"
1014
+ }
1015
+ },
1016
+ "outputs": [],
1017
+ "source": [
1018
+ "log.to_csv('running_example_exported.csv')"
1019
+ ]
1020
+ },
1021
+ {
1022
+ "cell_type": "markdown",
1023
+ "metadata": {
1024
+ "slideshow": {
1025
+ "slide_type": "slide"
1026
+ }
1027
+ },
1028
+ "source": [
1029
+ "### Storing a Pandas DataFrame as a .xes file"
1030
+ ]
1031
+ },
1032
+ {
1033
+ "cell_type": "markdown",
1034
+ "metadata": {
1035
+ "slideshow": {
1036
+ "slide_type": "notes"
1037
+ }
1038
+ },
1039
+ "source": [
1040
+ "It is also possible to store a pandas data frame to a xes file. This is simply done by calling the ```pm4py.write_xes()```\n",
1041
+ "function. You can pass the dataframe as an input parameter to the function, i.e., pm4py handles the internal conversion\n",
1042
+ "of the dataframe to an event log object prior to writing it to disk. Note that this construct only works if you have\n",
1043
+ "formatted the data frame, i.e., as highlighted earlier in the importing CSV section."
1044
+ ]
1045
+ },
1046
+ {
1047
+ "cell_type": "code",
1048
+ "execution_count": null,
1049
+ "metadata": {
1050
+ "pycharm": {
1051
+ "is_executing": true,
1052
+ "name": "#%%\n"
1053
+ },
1054
+ "slideshow": {
1055
+ "slide_type": "subslide"
1056
+ }
1057
+ },
1058
+ "outputs": [],
1059
+ "source": [
1060
+ "pm4py.write_xes(log, 'running_example_csv_exported_as_xes.xes')\n"
1061
+ ]
1062
+ },
1063
+ {
1064
+ "cell_type": "markdown",
1065
+ "metadata": {
1066
+ "slideshow": {
1067
+ "slide_type": "slide"
1068
+ }
1069
+ },
1070
+ "source": [
1071
+ "### Storing an Event Log object as a .csv file"
1072
+ ]
1073
+ },
1074
+ {
1075
+ "cell_type": "markdown",
1076
+ "metadata": {
1077
+ "pycharm": {
1078
+ "name": "#%% md\n"
1079
+ },
1080
+ "slideshow": {
1081
+ "slide_type": "notes"
1082
+ }
1083
+ },
1084
+ "source": [
1085
+ "In some cases, we might want to store an event log object, e.g., obtained by importing a .xes file, as a csv file.\n",
1086
+ "For example, certain (commercial) process mining tools only support csv importing. \n",
1087
+ "For this purpose, pm4py offers conversion functionality that allows you to convert your event log object into a data frame,\n",
1088
+ "which you can subsequently export using pandas.\n"
1089
+ ]
1090
+ },
1091
+ {
1092
+ "cell_type": "code",
1093
+ "execution_count": 16,
1094
+ "metadata": {
1095
+ "pycharm": {
1096
+ "name": "#%%\n"
1097
+ },
1098
+ "slideshow": {
1099
+ "slide_type": "subslide"
1100
+ }
1101
+ },
1102
+ "outputs": [],
1103
+ "source": [
1104
+ "df = pm4py.convert_to_dataframe(log_xes)\n",
1105
+ "df.to_csv('running_example_xes_exported_as_csv.csv')\n"
1106
+ ]
1107
+ },
1108
+ {
1109
+ "cell_type": "markdown",
1110
+ "metadata": {
1111
+ "pycharm": {
1112
+ "name": "#%% md\n"
1113
+ },
1114
+ "slideshow": {
1115
+ "slide_type": "slide"
1116
+ }
1117
+ },
1118
+ "source": [
1119
+ "### Storing an Event Log Object as a .xes File"
1120
+ ]
1121
+ },
1122
+ {
1123
+ "cell_type": "markdown",
1124
+ "metadata": {
1125
+ "pycharm": {
1126
+ "name": "#%% md\n"
1127
+ },
1128
+ "slideshow": {
1129
+ "slide_type": "notes"
1130
+ }
1131
+ },
1132
+ "source": [
1133
+ "Storing an event log object as a .xes file is rather straightforward. In pm4py, the write_xes() method allows us to do so.\n",
1134
+ "Consider the simple example script below in which we show an example of this functionality."
1135
+ ]
1136
+ },
1137
+ {
1138
+ "cell_type": "code",
1139
+ "execution_count": null,
1140
+ "metadata": {
1141
+ "pycharm": {
1142
+ "name": "#%%\n"
1143
+ },
1144
+ "slideshow": {
1145
+ "slide_type": "subslide"
1146
+ }
1147
+ },
1148
+ "outputs": [],
1149
+ "source": [
1150
+ "pm4py.write_xes(log_xes, 'running_example_exported.xes')"
1151
+ ]
1152
+ }
1153
+ ],
1154
+ "metadata": {
1155
+ "celltoolbar": "Slideshow",
1156
+ "kernelspec": {
1157
+ "display_name": "Python 3",
1158
+ "language": "python",
1159
+ "name": "python3"
1160
+ },
1161
+ "language_info": {
1162
+ "codemirror_mode": {
1163
+ "name": "ipython",
1164
+ "version": 3
1165
+ },
1166
+ "file_extension": ".py",
1167
+ "mimetype": "text/x-python",
1168
+ "name": "python",
1169
+ "nbconvert_exporter": "python",
1170
+ "pygments_lexer": "ipython3",
1171
+ "version": "3.8.5"
1172
+ }
1173
+ },
1174
+ "nbformat": 4,
1175
+ "nbformat_minor": 1
1176
+ }
source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/2_event_data_filtering.ipynb ADDED
@@ -0,0 +1,964 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {
6
+ "collapsed": true,
7
+ "pycharm": {
8
+ "name": "#%% md\n"
9
+ },
10
+ "slideshow": {
11
+ "slide_type": "slide"
12
+ }
13
+ },
14
+ "source": [
15
+ "# Event Data Filtering\n",
16
+ "*by: Sebastiaan J. van Zelst*"
17
+ ]
18
+ },
19
+ {
20
+ "cell_type": "markdown",
21
+ "metadata": {
22
+ "pycharm": {
23
+ "name": "#%% md\n"
24
+ },
25
+ "slideshow": {
26
+ "slide_type": "notes"
27
+ }
28
+ },
29
+ "source": [
30
+ "Like any data-driven field, the successful application of process mining needs *data munging and crunching*.\n",
31
+ "In pm4py, you can munge and crunch your data in two ways, i.e., you can write ```lambda``` functions and apply them on\n",
32
+ "your event log, or, you can apply pre-built filtering and transformation functions.\n",
33
+ "Hence, in this turtorial, we briefly explain how to filter event data in various different ways in pm4py."
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "markdown",
38
+ "metadata": {
39
+ "pycharm": {
40
+ "name": "#%% md\n"
41
+ },
42
+ "slideshow": {
43
+ "slide_type": "slide"
44
+ }
45
+ },
46
+ "source": [
47
+ "## Generic Lambda Functions"
48
+ ]
49
+ },
50
+ {
51
+ "cell_type": "markdown",
52
+ "metadata": {
53
+ "pycharm": {
54
+ "name": "#%% md\n"
55
+ },
56
+ "slideshow": {
57
+ "slide_type": "notes"
58
+ }
59
+ },
60
+ "source": [
61
+ "In a nutshell, a lambda function allows you to specify a function that needs to be applied on a given element.\n",
62
+ "As a simple example, consider the following snippet:"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": 59,
68
+ "metadata": {
69
+ "pycharm": {
70
+ "name": "#%%\n"
71
+ },
72
+ "slideshow": {
73
+ "slide_type": "subslide"
74
+ }
75
+ },
76
+ "outputs": [
77
+ {
78
+ "data": {
79
+ "text/plain": "10"
80
+ },
81
+ "execution_count": 59,
82
+ "metadata": {},
83
+ "output_type": "execute_result"
84
+ }
85
+ ],
86
+ "source": [
87
+ "f = lambda x: 2 * x\n",
88
+ "f(5)"
89
+ ]
90
+ },
91
+ {
92
+ "cell_type": "markdown",
93
+ "metadata": {
94
+ "pycharm": {
95
+ "name": "#%% md\n"
96
+ },
97
+ "slideshow": {
98
+ "slide_type": "notes"
99
+ }
100
+ },
101
+ "source": [
102
+ "In the code, we assign a ```lambda``` function to variable ```f```.\n",
103
+ "The function specifies that on each possible input it receives, the resulting function that is applied is a multiplication by 2.\n",
104
+ "Hence ```f(1)=2```, ```f(2)=4```, etc."
105
+ ]
106
+ },
107
+ {
108
+ "cell_type": "markdown",
109
+ "metadata": {
110
+ "pycharm": {
111
+ "name": "#%% md\n"
112
+ },
113
+ "slideshow": {
114
+ "slide_type": "notes"
115
+ }
116
+ },
117
+ "source": [
118
+ "Note that, invoking ```f``` only works if we provide an argument that can be combined with the ```* 2``` operation.\n",
119
+ "For example, for ```strings```, the ```* 2``` operation concatenates the input argument with itself:"
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "execution_count": 60,
125
+ "metadata": {
126
+ "pycharm": {
127
+ "name": "#%%\n"
128
+ },
129
+ "slideshow": {
130
+ "slide_type": "subslide"
131
+ }
132
+ },
133
+ "outputs": [
134
+ {
135
+ "data": {
136
+ "text/plain": "'PetePete'"
137
+ },
138
+ "execution_count": 60,
139
+ "metadata": {},
140
+ "output_type": "execute_result"
141
+ }
142
+ ],
143
+ "source": [
144
+ "f('Pete')"
145
+ ]
146
+ },
147
+ {
148
+ "cell_type": "markdown",
149
+ "metadata": {
150
+ "pycharm": {
151
+ "name": "#%% md\n"
152
+ },
153
+ "slideshow": {
154
+ "slide_type": "slide"
155
+ }
156
+ },
157
+ "source": [
158
+ "## Filter and Map"
159
+ ]
160
+ },
161
+ {
162
+ "cell_type": "markdown",
163
+ "metadata": {
164
+ "pycharm": {
165
+ "name": "#%% md\n"
166
+ },
167
+ "slideshow": {
168
+ "slide_type": "notes"
169
+ }
170
+ },
171
+ "source": [
172
+ "Lambda functions allow us to write short, type-independent functions.\n",
173
+ "Given a list of objects, Python provides two core functions that can apply a given lambda function on each element of\n",
174
+ "the given list (in fact, any iterable):"
175
+ ]
176
+ },
177
+ {
178
+ "cell_type": "markdown",
179
+ "metadata": {
180
+ "slideshow": {
181
+ "slide_type": "subslide"
182
+ }
183
+ },
184
+ "source": [
185
+ "- ```filter(f,l)```\n",
186
+ " - apply the given lambda function ```f``` as a filter on the iterable ```l```.\n",
187
+ "- ```map(f,l)```\n",
188
+ " - apply the given lambda function ```f``` as a transformation on the iterable ```l```."
189
+ ]
190
+ },
191
+ {
192
+ "cell_type": "markdown",
193
+ "metadata": {
194
+ "pycharm": {
195
+ "name": "#%% md\n"
196
+ },
197
+ "slideshow": {
198
+ "slide_type": "notes"
199
+ }
200
+ },
201
+ "source": [
202
+ "For more information, study the concept of ‘higher order functions’ in Python, e.g., as introduced [here](https://www.codespeedy.com/higher-order-functions-in-python-map-filter-sorted-reduce/).\n",
203
+ "Let's consider a few simple examples."
204
+ ]
205
+ },
206
+ {
207
+ "cell_type": "code",
208
+ "execution_count": 61,
209
+ "metadata": {
210
+ "pycharm": {
211
+ "name": "#%%\n"
212
+ },
213
+ "slideshow": {
214
+ "slide_type": "subslide"
215
+ }
216
+ },
217
+ "outputs": [
218
+ {
219
+ "data": {
220
+ "text/plain": "<filter at 0x1fc59e9a4f0>"
221
+ },
222
+ "execution_count": 61,
223
+ "metadata": {},
224
+ "output_type": "execute_result"
225
+ }
226
+ ],
227
+ "source": [
228
+ "l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n",
229
+ "filter(lambda n: n >= 5, l)"
230
+ ]
231
+ },
232
+ {
233
+ "cell_type": "markdown",
234
+ "metadata": {
235
+ "pycharm": {
236
+ "name": "#%% md\n"
237
+ },
238
+ "slideshow": {
239
+ "slide_type": "notes"
240
+ }
241
+ },
242
+ "source": [
243
+ "The previous example needs little to no explanation, i.e., the filter retains all numbers in the list greater or equal to five.\n",
244
+ "However, what is interesting, is the fact that the resulting objects are not a list (or an iterables), rather a ```filter``` object.\n",
245
+ "Such an objects can be easily transformed to a list by wrapping it with a ```list()``` cast:"
246
+ ]
247
+ },
248
+ {
249
+ "cell_type": "code",
250
+ "execution_count": 62,
251
+ "metadata": {
252
+ "pycharm": {
253
+ "name": "#%%\n"
254
+ },
255
+ "slideshow": {
256
+ "slide_type": "subslide"
257
+ }
258
+ },
259
+ "outputs": [
260
+ {
261
+ "data": {
262
+ "text/plain": "[5, 6, 7, 8, 9, 10]"
263
+ },
264
+ "execution_count": 62,
265
+ "metadata": {},
266
+ "output_type": "execute_result"
267
+ }
268
+ ],
269
+ "source": [
270
+ "list(filter(lambda n: n >= 5, l))"
271
+ ]
272
+ },
273
+ {
274
+ "cell_type": "markdown",
275
+ "metadata": {
276
+ "pycharm": {
277
+ "name": "#%% md\n"
278
+ },
279
+ "slideshow": {
280
+ "slide_type": "notes"
281
+ }
282
+ },
283
+ "source": [
284
+ "The same holds for the ```map()``` function:"
285
+ ]
286
+ },
287
+ {
288
+ "cell_type": "code",
289
+ "execution_count": 63,
290
+ "metadata": {
291
+ "pycharm": {
292
+ "name": "#%%\n"
293
+ },
294
+ "slideshow": {
295
+ "slide_type": "subslide"
296
+ }
297
+ },
298
+ "outputs": [
299
+ {
300
+ "data": {
301
+ "text/plain": "<map at 0x1fc59e7adf0>"
302
+ },
303
+ "execution_count": 63,
304
+ "metadata": {},
305
+ "output_type": "execute_result"
306
+ }
307
+ ],
308
+ "source": [
309
+ "map(lambda n: n * 3, l)"
310
+ ]
311
+ },
312
+ {
313
+ "cell_type": "code",
314
+ "execution_count": 64,
315
+ "metadata": {
316
+ "pycharm": {
317
+ "name": "#%%\n"
318
+ },
319
+ "slideshow": {
320
+ "slide_type": "subslide"
321
+ }
322
+ },
323
+ "outputs": [
324
+ {
325
+ "data": {
326
+ "text/plain": "[3, 6, 9, 12, 15, 18, 21, 24, 27, 30]"
327
+ },
328
+ "execution_count": 64,
329
+ "metadata": {},
330
+ "output_type": "execute_result"
331
+ }
332
+ ],
333
+ "source": [
334
+ "list(map(lambda n: n * 3, l))"
335
+ ]
336
+ },
337
+ {
338
+ "cell_type": "markdown",
339
+ "metadata": {
340
+ "pycharm": {
341
+ "name": "#%% md\n"
342
+ },
343
+ "slideshow": {
344
+ "slide_type": "notes"
345
+ }
346
+ },
347
+ "source": [
348
+ "Observe that, the previous map function simply muliplies each element of list ```l``` by three."
349
+ ]
350
+ },
351
+ {
352
+ "cell_type": "markdown",
353
+ "metadata": {
354
+ "pycharm": {
355
+ "name": "#%% md\n"
356
+ },
357
+ "slideshow": {
358
+ "slide_type": "slide"
359
+ }
360
+ },
361
+ "source": [
362
+ "## Lambda-Based Filtering in pm4py"
363
+ ]
364
+ },
365
+ {
366
+ "cell_type": "markdown",
367
+ "metadata": {
368
+ "slideshow": {
369
+ "slide_type": "notes"
370
+ }
371
+ },
372
+ "source": [
373
+ "In pm4py, event log objects mimic lists of traces, which in turn, mimic lists of events.\n",
374
+ "Clearly, ```lambda``` functions can therefore be applied to event logs and traces.\n",
375
+ "However, as we have shown in the previous example, after applying such a lamda-based filter, the resulting object is no longer an event log.\n",
376
+ "Furthermore, casting a filter object or map object to an event log in ```pm4py``` is a bit more involved, i.e., it is\n",
377
+ "not so trivial as ```list(filter(...))``` in the previous example.\n",
378
+ "This is due to the fact that various meta-data is stored in the event log object as well.\n",
379
+ "To this end, pm4py offers wrapper functions that make sure that after applying your higher-order function with a lambda function,\n",
380
+ "the resulting object is again an Event Log object.\n",
381
+ "In the upcoming scripts, we'll take a look at some lambda-based fitlering.\n",
382
+ "First, let's inspect the length of each trace in our running example log by applying a generic map function"
383
+ ]
384
+ },
385
+ {
386
+ "cell_type": "code",
387
+ "execution_count": 65,
388
+ "metadata": {
389
+ "pycharm": {
390
+ "name": "#%%\n"
391
+ },
392
+ "slideshow": {
393
+ "slide_type": "subslide"
394
+ }
395
+ },
396
+ "outputs": [
397
+ {
398
+ "data": {
399
+ "text/plain": "parsing log, completed traces :: 0%| | 0/6 [00:00<?, ?it/s]",
400
+ "application/vnd.jupyter.widget-view+json": {
401
+ "version_major": 2,
402
+ "version_minor": 0,
403
+ "model_id": "f7c29377364e465f953bc55686df17c3"
404
+ }
405
+ },
406
+ "metadata": {},
407
+ "output_type": "display_data"
408
+ },
409
+ {
410
+ "data": {
411
+ "text/plain": "[9, 5, 5, 5, 13, 5]"
412
+ },
413
+ "execution_count": 65,
414
+ "metadata": {},
415
+ "output_type": "execute_result"
416
+ }
417
+ ],
418
+ "source": [
419
+ "import pm4py\n",
420
+ "\n",
421
+ "log = pm4py.read_xes('data/running_example.xes', return_legacy_log_object=True)\n",
422
+ "# inspect the length of each trace using a generic map function\n",
423
+ "list(map(lambda t: len(t), log))"
424
+ ]
425
+ },
426
+ {
427
+ "cell_type": "markdown",
428
+ "metadata": {
429
+ "pycharm": {
430
+ "name": "#%% md\n"
431
+ },
432
+ "slideshow": {
433
+ "slide_type": "notes"
434
+ }
435
+ },
436
+ "source": [
437
+ "As we can see, there are four traces describing a trace of length 5, one trace of length 9 and one trace of length 13.\n",
438
+ "Let's retain all traces that have a lenght greater than 5."
439
+ ]
440
+ },
441
+ {
442
+ "cell_type": "code",
443
+ "execution_count": 66,
444
+ "metadata": {
445
+ "pycharm": {
446
+ "name": "#%%\n"
447
+ },
448
+ "slideshow": {
449
+ "slide_type": "subslide"
450
+ }
451
+ },
452
+ "outputs": [
453
+ {
454
+ "data": {
455
+ "text/plain": "[9, 13]"
456
+ },
457
+ "execution_count": 66,
458
+ "metadata": {},
459
+ "output_type": "execute_result"
460
+ }
461
+ ],
462
+ "source": [
463
+ "lf = pm4py.filter_log(lambda t: len(t) > 5, log)\n",
464
+ "list(map(lambda t: len(t), lf))"
465
+ ]
466
+ },
467
+ {
468
+ "cell_type": "markdown",
469
+ "metadata": {
470
+ "pycharm": {
471
+ "name": "#%% md\n"
472
+ },
473
+ "slideshow": {
474
+ "slide_type": "notes"
475
+ }
476
+ },
477
+ "source": [
478
+ "The traces of length 9 and 13 have repeated behavior in them, i.e., the *reinitiate request* activity has been performed at least once:"
479
+ ]
480
+ },
481
+ {
482
+ "cell_type": "code",
483
+ "execution_count": 67,
484
+ "metadata": {
485
+ "pycharm": {
486
+ "name": "#%%\n"
487
+ },
488
+ "slideshow": {
489
+ "slide_type": "subslide"
490
+ }
491
+ },
492
+ "outputs": [
493
+ {
494
+ "data": {
495
+ "text/plain": "[(9, 1), (5, 0), (5, 0), (5, 0), (13, 2), (5, 0)]"
496
+ },
497
+ "execution_count": 67,
498
+ "metadata": {},
499
+ "output_type": "execute_result"
500
+ }
501
+ ],
502
+ "source": [
503
+ "list(map(lambda t: (len(t), len(list(filter(lambda e: e['concept:name'] == 'reinitiate request', t)))), log))"
504
+ ]
505
+ },
506
+ {
507
+ "cell_type": "markdown",
508
+ "metadata": {
509
+ "pycharm": {
510
+ "name": "#%% md\n"
511
+ },
512
+ "slideshow": {
513
+ "slide_type": "notes"
514
+ }
515
+ },
516
+ "source": [
517
+ "Observe that the map function maps each trace onto a tuple.\n",
518
+ "The first element describes the length of the trace.\n",
519
+ "The second element describes the number of occurrences of the activity *register request*.\n",
520
+ "Observe that we obtain said counter by filtering the trace, i.e., by retaining only those events that describe the\n",
521
+ "*reinitiate request* activity and counting the length of the resulting list.\n",
522
+ "Note that the traces describe a list of events, and, events are implementing a dictionary.\n",
523
+ "In this case, the activity name is captured by the ```concept:name``` attribute."
524
+ ]
525
+ },
526
+ {
527
+ "cell_type": "markdown",
528
+ "metadata": {
529
+ "pycharm": {
530
+ "name": "#%% md\n"
531
+ },
532
+ "slideshow": {
533
+ "slide_type": "notes"
534
+ }
535
+ },
536
+ "source": [
537
+ "In general, PM4PY supports the following *generic filtering functions*:"
538
+ ]
539
+ },
540
+ {
541
+ "cell_type": "markdown",
542
+ "metadata": {
543
+ "slideshow": {
544
+ "slide_type": "subslide"
545
+ }
546
+ },
547
+ "source": [
548
+ "- ```pm4py.filter_log(f, log)```\n",
549
+ " - filter the log according to a function ```f```.\n",
550
+ "- ```pm4py.filter_trace(f,trace)```\n",
551
+ " - filter the trace according to function ```f```.\n",
552
+ "- ```pm4py.sort_log(log, key, reverse)```\n",
553
+ " - sort the event log according to a given ```key```, reversed order if ```reverse==True```.\n",
554
+ "- ```pm4py.sort_trace(trace, key, reverse)```\n",
555
+ " - sort the trace according to a given ```key```, reversed order if ```reverse==True```."
556
+ ]
557
+ },
558
+ {
559
+ "cell_type": "markdown",
560
+ "metadata": {
561
+ "pycharm": {
562
+ "name": "#%% md\n"
563
+ },
564
+ "slideshow": {
565
+ "slide_type": "notes"
566
+ }
567
+ },
568
+ "source": [
569
+ "Let's see these functions in action:"
570
+ ]
571
+ },
572
+ {
573
+ "cell_type": "code",
574
+ "execution_count": 68,
575
+ "metadata": {
576
+ "pycharm": {
577
+ "name": "#%%\n"
578
+ },
579
+ "slideshow": {
580
+ "slide_type": "subslide"
581
+ }
582
+ },
583
+ "outputs": [
584
+ {
585
+ "name": "stdout",
586
+ "output_type": "stream",
587
+ "text": [
588
+ "6\n",
589
+ "2\n"
590
+ ]
591
+ }
592
+ ],
593
+ "source": [
594
+ "print(len(log))\n",
595
+ "lf = pm4py.filter_log(lambda t: len(t) > 5, log)\n",
596
+ "print(len(lf))"
597
+ ]
598
+ },
599
+ {
600
+ "cell_type": "code",
601
+ "execution_count": 69,
602
+ "metadata": {
603
+ "pycharm": {
604
+ "name": "#%%\n"
605
+ },
606
+ "slideshow": {
607
+ "slide_type": "subslide"
608
+ }
609
+ },
610
+ "outputs": [
611
+ {
612
+ "name": "stdout",
613
+ "output_type": "stream",
614
+ "text": [
615
+ "9\n",
616
+ "2\n"
617
+ ]
618
+ }
619
+ ],
620
+ "source": [
621
+ "print(len(log[0])) #log[0] fetches the 1st trace\n",
622
+ "tf = pm4py.filter_trace(lambda e: e['concept:name'] in {'register request', 'pay compensation'}, log[0])\n",
623
+ "print(len(tf))"
624
+ ]
625
+ },
626
+ {
627
+ "cell_type": "code",
628
+ "execution_count": 70,
629
+ "metadata": {
630
+ "pycharm": {
631
+ "name": "#%%\n"
632
+ },
633
+ "slideshow": {
634
+ "slide_type": "subslide"
635
+ }
636
+ },
637
+ "outputs": [
638
+ {
639
+ "name": "stdout",
640
+ "output_type": "stream",
641
+ "text": [
642
+ "9\n",
643
+ "5\n",
644
+ "13\n"
645
+ ]
646
+ }
647
+ ],
648
+ "source": [
649
+ "print(len(log[0]))\n",
650
+ "ls = pm4py.sort_log(log, lambda t: len(t))\n",
651
+ "print(len(ls[0]))\n",
652
+ "ls = pm4py.sort_log(log, lambda t: len(t), reverse=True)\n",
653
+ "print(len(ls[0]))"
654
+ ]
655
+ },
656
+ {
657
+ "cell_type": "markdown",
658
+ "metadata": {
659
+ "pycharm": {
660
+ "name": "#%% md\n"
661
+ },
662
+ "slideshow": {
663
+ "slide_type": "slide"
664
+ }
665
+ },
666
+ "source": [
667
+ "## Specific Filters"
668
+ ]
669
+ },
670
+ {
671
+ "cell_type": "markdown",
672
+ "metadata": {
673
+ "pycharm": {
674
+ "name": "#%% md\n"
675
+ },
676
+ "slideshow": {
677
+ "slide_type": "notes"
678
+ }
679
+ },
680
+ "source": [
681
+ "There are various pre-built filters in PM4Py, which make commonly needed process mining filtering functionality a lot easier.\n",
682
+ "In the upcoming overview, we briefly give present these functions.\n",
683
+ "We describe how to call them, their main input parameters and their return objects.\n",
684
+ "Note that, all of the filters work on both DataFrames and pm4py event log objects."
685
+ ]
686
+ },
687
+ {
688
+ "cell_type": "markdown",
689
+ "metadata": {
690
+ "slideshow": {
691
+ "slide_type": "subslide"
692
+ }
693
+ },
694
+ "source": [
695
+ "### Start Activities\n",
696
+ "- ```filter_start_activities(log, activities, retain=True)```\n",
697
+ " - retains (or drops) the traces that contain the given activity as the final event."
698
+ ]
699
+ },
700
+ {
701
+ "cell_type": "code",
702
+ "execution_count": 71,
703
+ "metadata": {
704
+ "pycharm": {
705
+ "name": "#%%\n"
706
+ },
707
+ "slideshow": {
708
+ "slide_type": "subslide"
709
+ }
710
+ },
711
+ "outputs": [
712
+ {
713
+ "data": {
714
+ "text/plain": "[{'attributes': {'concept:name': '3'}, 'events': [{'concept:name': 'register request', 'org:resource': 'Pete', 'time:timestamp': datetime.datetime(2010, 12, 30, 14, 32, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600))), 'Activity': 'register request', 'Resource': 'Pete', 'Costs': '50'}, '..', {'concept:name': 'pay compensation', 'org:resource': 'Ellen', 'time:timestamp': datetime.datetime(2011, 1, 15, 10, 45, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600))), 'Activity': 'pay compensation', 'Resource': 'Ellen', 'Costs': '200'}]}, '....', {'attributes': {'concept:name': '4'}, 'events': [{'concept:name': 'register request', 'org:resource': 'Pete', 'time:timestamp': datetime.datetime(2011, 1, 6, 15, 2, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600))), 'Activity': 'register request', 'Resource': 'Pete', 'Costs': '50'}, '..', {'concept:name': 'reject request', 'org:resource': 'Ellen', 'time:timestamp': datetime.datetime(2011, 1, 12, 15, 44, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600))), 'Activity': 'reject request', 'Resource': 'Ellen', 'Costs': '200'}]}]"
715
+ },
716
+ "execution_count": 71,
717
+ "metadata": {},
718
+ "output_type": "execute_result"
719
+ }
720
+ ],
721
+ "source": [
722
+ "pm4py.filter_start_activities(log, {'register request'})"
723
+ ]
724
+ },
725
+ {
726
+ "cell_type": "code",
727
+ "execution_count": 72,
728
+ "metadata": {
729
+ "pycharm": {
730
+ "name": "#%%\n"
731
+ },
732
+ "slideshow": {
733
+ "slide_type": "subslide"
734
+ }
735
+ },
736
+ "outputs": [
737
+ {
738
+ "data": {
739
+ "text/plain": "[]"
740
+ },
741
+ "execution_count": 72,
742
+ "metadata": {},
743
+ "output_type": "execute_result"
744
+ }
745
+ ],
746
+ "source": [
747
+ "pm4py.filter_start_activities(log, {'register request TYPO!'})"
748
+ ]
749
+ },
750
+ {
751
+ "cell_type": "code",
752
+ "execution_count": 73,
753
+ "metadata": {
754
+ "pycharm": {
755
+ "name": "#%%\n"
756
+ },
757
+ "slideshow": {
758
+ "slide_type": "subslide"
759
+ }
760
+ },
761
+ "outputs": [
762
+ {
763
+ "data": {
764
+ "text/plain": " case:concept:name concept:name time:timestamp costs \\\n14 1 register request 2010-12-30 10:02:00+00:00 50 \n15 1 examine thoroughly 2010-12-31 09:06:00+00:00 400 \n16 1 check ticket 2011-01-05 14:12:00+00:00 100 \n17 1 decide 2011-01-06 10:18:00+00:00 200 \n18 1 reject request 2011-01-07 13:24:00+00:00 200 \n9 2 register request 2010-12-30 10:32:00+00:00 50 \n10 2 check ticket 2010-12-30 11:12:00+00:00 100 \n11 2 examine casually 2010-12-30 13:16:00+00:00 400 \n12 2 decide 2011-01-05 10:22:00+00:00 200 \n13 2 pay compensation 2011-01-08 11:05:00+00:00 200 \n0 3 register request 2010-12-30 13:32:00+00:00 50 \n1 3 examine casually 2010-12-30 14:06:00+00:00 400 \n2 3 check ticket 2010-12-30 15:34:00+00:00 100 \n3 3 decide 2011-01-06 08:18:00+00:00 200 \n4 3 reinitiate request 2011-01-06 11:18:00+00:00 200 \n5 3 examine thoroughly 2011-01-06 12:06:00+00:00 400 \n6 3 check ticket 2011-01-08 10:43:00+00:00 100 \n7 3 decide 2011-01-09 08:55:00+00:00 200 \n8 3 pay compensation 2011-01-15 09:45:00+00:00 200 \n37 4 register request 2011-01-06 14:02:00+00:00 50 \n38 4 check ticket 2011-01-07 11:06:00+00:00 100 \n39 4 examine thoroughly 2011-01-08 13:43:00+00:00 400 \n40 4 decide 2011-01-09 11:02:00+00:00 200 \n41 4 reject request 2011-01-12 14:44:00+00:00 200 \n24 5 register request 2011-01-06 08:02:00+00:00 50 \n25 5 examine casually 2011-01-07 09:16:00+00:00 400 \n26 5 check ticket 2011-01-08 10:22:00+00:00 100 \n27 5 decide 2011-01-10 12:28:00+00:00 200 \n28 5 reinitiate request 2011-01-11 15:18:00+00:00 200 \n29 5 check ticket 2011-01-14 13:33:00+00:00 100 \n30 5 examine casually 2011-01-16 14:50:00+00:00 400 \n31 5 decide 2011-01-19 10:18:00+00:00 200 \n32 5 reinitiate request 2011-01-20 11:48:00+00:00 200 \n33 5 examine casually 2011-01-21 08:06:00+00:00 400 \n34 5 check ticket 2011-01-21 10:34:00+00:00 100 \n35 5 decide 2011-01-23 12:12:00+00:00 200 \n36 5 reject request 2011-01-24 13:56:00+00:00 200 \n19 6 register request 2011-01-06 14:02:00+00:00 50 \n20 6 examine casually 2011-01-06 15:06:00+00:00 400 \n21 6 check ticket 2011-01-07 15:22:00+00:00 100 \n22 6 decide 2011-01-07 15:52:00+00:00 200 \n23 6 pay compensation 2011-01-16 10:47:00+00:00 200 \n\n org:resource @@index \n14 Pete 14 \n15 Sue 15 \n16 Mike 16 \n17 Sara 17 \n18 Pete 18 \n9 Mike 9 \n10 Mike 10 \n11 Sean 11 \n12 Sara 12 \n13 Ellen 13 \n0 Pete 0 \n1 Mike 1 \n2 Ellen 2 \n3 Sara 3 \n4 Sara 4 \n5 Sean 5 \n6 Pete 6 \n7 Sara 7 \n8 Ellen 8 \n37 Pete 37 \n38 Mike 38 \n39 Sean 39 \n40 Sara 40 \n41 Ellen 41 \n24 Ellen 24 \n25 Mike 25 \n26 Pete 26 \n27 Sara 27 \n28 Sara 28 \n29 Ellen 29 \n30 Mike 30 \n31 Sara 31 \n32 Sara 32 \n33 Sue 33 \n34 Pete 34 \n35 Sara 35 \n36 Mike 36 \n19 Mike 19 \n20 Ellen 20 \n21 Mike 21 \n22 Sara 22 \n23 Mike 23 ",
765
+ "text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>case:concept:name</th>\n <th>concept:name</th>\n <th>time:timestamp</th>\n <th>costs</th>\n <th>org:resource</th>\n <th>@@index</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>14</th>\n <td>1</td>\n <td>register request</td>\n <td>2010-12-30 10:02:00+00:00</td>\n <td>50</td>\n <td>Pete</td>\n <td>14</td>\n </tr>\n <tr>\n <th>15</th>\n <td>1</td>\n <td>examine thoroughly</td>\n <td>2010-12-31 09:06:00+00:00</td>\n <td>400</td>\n <td>Sue</td>\n <td>15</td>\n </tr>\n <tr>\n <th>16</th>\n <td>1</td>\n <td>check ticket</td>\n <td>2011-01-05 14:12:00+00:00</td>\n <td>100</td>\n <td>Mike</td>\n <td>16</td>\n </tr>\n <tr>\n <th>17</th>\n <td>1</td>\n <td>decide</td>\n <td>2011-01-06 10:18:00+00:00</td>\n <td>200</td>\n <td>Sara</td>\n <td>17</td>\n </tr>\n <tr>\n <th>18</th>\n <td>1</td>\n <td>reject request</td>\n <td>2011-01-07 13:24:00+00:00</td>\n <td>200</td>\n <td>Pete</td>\n <td>18</td>\n </tr>\n <tr>\n <th>9</th>\n <td>2</td>\n <td>register request</td>\n <td>2010-12-30 10:32:00+00:00</td>\n <td>50</td>\n <td>Mike</td>\n <td>9</td>\n </tr>\n <tr>\n <th>10</th>\n <td>2</td>\n <td>check ticket</td>\n <td>2010-12-30 11:12:00+00:00</td>\n <td>100</td>\n <td>Mike</td>\n <td>10</td>\n </tr>\n <tr>\n <th>11</th>\n <td>2</td>\n <td>examine casually</td>\n <td>2010-12-30 13:16:00+00:00</td>\n <td>400</td>\n <td>Sean</td>\n <td>11</td>\n </tr>\n <tr>\n <th>12</th>\n <td>2</td>\n <td>decide</td>\n <td>2011-01-05 10:22:00+00:00</td>\n <td>200</td>\n <td>Sara</td>\n <td>12</td>\n </tr>\n <tr>\n <th>13</th>\n <td>2</td>\n <td>pay compensation</td>\n <td>2011-01-08 11:05:00+00:00</td>\n <td>200</td>\n <td>Ellen</td>\n <td>13</td>\n </tr>\n <tr>\n <th>0</th>\n <td>3</td>\n <td>register request</td>\n <td>2010-12-30 13:32:00+00:00</td>\n <td>50</td>\n <td>Pete</td>\n <td>0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>3</td>\n <td>examine casually</td>\n <td>2010-12-30 14:06:00+00:00</td>\n <td>400</td>\n <td>Mike</td>\n <td>1</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n <td>check ticket</td>\n <td>2010-12-30 15:34:00+00:00</td>\n <td>100</td>\n <td>Ellen</td>\n <td>2</td>\n </tr>\n <tr>\n <th>3</th>\n <td>3</td>\n <td>decide</td>\n <td>2011-01-06 08:18:00+00:00</td>\n <td>200</td>\n <td>Sara</td>\n <td>3</td>\n </tr>\n <tr>\n <th>4</th>\n <td>3</td>\n <td>reinitiate request</td>\n <td>2011-01-06 11:18:00+00:00</td>\n <td>200</td>\n <td>Sara</td>\n <td>4</td>\n </tr>\n <tr>\n <th>5</th>\n <td>3</td>\n <td>examine thoroughly</td>\n <td>2011-01-06 12:06:00+00:00</td>\n <td>400</td>\n <td>Sean</td>\n <td>5</td>\n </tr>\n <tr>\n <th>6</th>\n <td>3</td>\n <td>check ticket</td>\n <td>2011-01-08 10:43:00+00:00</td>\n <td>100</td>\n <td>Pete</td>\n <td>6</td>\n </tr>\n <tr>\n <th>7</th>\n <td>3</td>\n <td>decide</td>\n <td>2011-01-09 08:55:00+00:00</td>\n <td>200</td>\n <td>Sara</td>\n <td>7</td>\n </tr>\n <tr>\n <th>8</th>\n <td>3</td>\n <td>pay compensation</td>\n <td>2011-01-15 09:45:00+00:00</td>\n <td>200</td>\n <td>Ellen</td>\n <td>8</td>\n </tr>\n <tr>\n <th>37</th>\n <td>4</td>\n <td>register request</td>\n <td>2011-01-06 14:02:00+00:00</td>\n <td>50</td>\n <td>Pete</td>\n <td>37</td>\n </tr>\n <tr>\n <th>38</th>\n <td>4</td>\n <td>check ticket</td>\n <td>2011-01-07 11:06:00+00:00</td>\n <td>100</td>\n <td>Mike</td>\n <td>38</td>\n </tr>\n <tr>\n <th>39</th>\n <td>4</td>\n <td>examine thoroughly</td>\n <td>2011-01-08 13:43:00+00:00</td>\n <td>400</td>\n <td>Sean</td>\n <td>39</td>\n </tr>\n <tr>\n <th>40</th>\n <td>4</td>\n <td>decide</td>\n <td>2011-01-09 11:02:00+00:00</td>\n <td>200</td>\n <td>Sara</td>\n <td>40</td>\n </tr>\n <tr>\n <th>41</th>\n <td>4</td>\n <td>reject request</td>\n <td>2011-01-12 14:44:00+00:00</td>\n <td>200</td>\n <td>Ellen</td>\n <td>41</td>\n </tr>\n <tr>\n <th>24</th>\n <td>5</td>\n <td>register request</td>\n <td>2011-01-06 08:02:00+00:00</td>\n <td>50</td>\n <td>Ellen</td>\n <td>24</td>\n </tr>\n <tr>\n <th>25</th>\n <td>5</td>\n <td>examine casually</td>\n <td>2011-01-07 09:16:00+00:00</td>\n <td>400</td>\n <td>Mike</td>\n <td>25</td>\n </tr>\n <tr>\n <th>26</th>\n <td>5</td>\n <td>check ticket</td>\n <td>2011-01-08 10:22:00+00:00</td>\n <td>100</td>\n <td>Pete</td>\n <td>26</td>\n </tr>\n <tr>\n <th>27</th>\n <td>5</td>\n <td>decide</td>\n <td>2011-01-10 12:28:00+00:00</td>\n <td>200</td>\n <td>Sara</td>\n <td>27</td>\n </tr>\n <tr>\n <th>28</th>\n <td>5</td>\n <td>reinitiate request</td>\n <td>2011-01-11 15:18:00+00:00</td>\n <td>200</td>\n <td>Sara</td>\n <td>28</td>\n </tr>\n <tr>\n <th>29</th>\n <td>5</td>\n <td>check ticket</td>\n <td>2011-01-14 13:33:00+00:00</td>\n <td>100</td>\n <td>Ellen</td>\n <td>29</td>\n </tr>\n <tr>\n <th>30</th>\n <td>5</td>\n <td>examine casually</td>\n <td>2011-01-16 14:50:00+00:00</td>\n <td>400</td>\n <td>Mike</td>\n <td>30</td>\n </tr>\n <tr>\n <th>31</th>\n <td>5</td>\n <td>decide</td>\n <td>2011-01-19 10:18:00+00:00</td>\n <td>200</td>\n <td>Sara</td>\n <td>31</td>\n </tr>\n <tr>\n <th>32</th>\n <td>5</td>\n <td>reinitiate request</td>\n <td>2011-01-20 11:48:00+00:00</td>\n <td>200</td>\n <td>Sara</td>\n <td>32</td>\n </tr>\n <tr>\n <th>33</th>\n <td>5</td>\n <td>examine casually</td>\n <td>2011-01-21 08:06:00+00:00</td>\n <td>400</td>\n <td>Sue</td>\n <td>33</td>\n </tr>\n <tr>\n <th>34</th>\n <td>5</td>\n <td>check ticket</td>\n <td>2011-01-21 10:34:00+00:00</td>\n <td>100</td>\n <td>Pete</td>\n <td>34</td>\n </tr>\n <tr>\n <th>35</th>\n <td>5</td>\n <td>decide</td>\n <td>2011-01-23 12:12:00+00:00</td>\n <td>200</td>\n <td>Sara</td>\n <td>35</td>\n </tr>\n <tr>\n <th>36</th>\n <td>5</td>\n <td>reject request</td>\n <td>2011-01-24 13:56:00+00:00</td>\n <td>200</td>\n <td>Mike</td>\n <td>36</td>\n </tr>\n <tr>\n <th>19</th>\n <td>6</td>\n <td>register request</td>\n <td>2011-01-06 14:02:00+00:00</td>\n <td>50</td>\n <td>Mike</td>\n <td>19</td>\n </tr>\n <tr>\n <th>20</th>\n <td>6</td>\n <td>examine casually</td>\n <td>2011-01-06 15:06:00+00:00</td>\n <td>400</td>\n <td>Ellen</td>\n <td>20</td>\n </tr>\n <tr>\n <th>21</th>\n <td>6</td>\n <td>check ticket</td>\n <td>2011-01-07 15:22:00+00:00</td>\n <td>100</td>\n <td>Mike</td>\n <td>21</td>\n </tr>\n <tr>\n <th>22</th>\n <td>6</td>\n <td>decide</td>\n <td>2011-01-07 15:52:00+00:00</td>\n <td>200</td>\n <td>Sara</td>\n <td>22</td>\n </tr>\n <tr>\n <th>23</th>\n <td>6</td>\n <td>pay compensation</td>\n <td>2011-01-16 10:47:00+00:00</td>\n <td>200</td>\n <td>Mike</td>\n <td>23</td>\n </tr>\n </tbody>\n</table>\n</div>"
766
+ },
767
+ "execution_count": 73,
768
+ "metadata": {},
769
+ "output_type": "execute_result"
770
+ }
771
+ ],
772
+ "source": [
773
+ "import pandas\n",
774
+ "\n",
775
+ "ldf = pm4py.format_dataframe(pandas.read_csv('data/running_example.csv', sep=';'), case_id='case_id',\n",
776
+ " activity_key='activity', timestamp_key='timestamp')\n",
777
+ "pm4py.filter_start_activities(ldf, {'register request'})"
778
+ ]
779
+ },
780
+ {
781
+ "cell_type": "code",
782
+ "execution_count": 74,
783
+ "metadata": {
784
+ "pycharm": {
785
+ "name": "#%%\n"
786
+ },
787
+ "slideshow": {
788
+ "slide_type": "subslide"
789
+ }
790
+ },
791
+ "outputs": [
792
+ {
793
+ "data": {
794
+ "text/plain": "Empty DataFrame\nColumns: [case:concept:name, concept:name, time:timestamp, costs, org:resource, @@index]\nIndex: []",
795
+ "text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>case:concept:name</th>\n <th>concept:name</th>\n <th>time:timestamp</th>\n <th>costs</th>\n <th>org:resource</th>\n <th>@@index</th>\n </tr>\n </thead>\n <tbody>\n </tbody>\n</table>\n</div>"
796
+ },
797
+ "execution_count": 74,
798
+ "metadata": {},
799
+ "output_type": "execute_result"
800
+ }
801
+ ],
802
+ "source": [
803
+ "pm4py.filter_start_activities(ldf, {'register request TYPO!'})"
804
+ ]
805
+ },
806
+ {
807
+ "cell_type": "markdown",
808
+ "metadata": {
809
+ "pycharm": {
810
+ "name": "#%% md\n"
811
+ },
812
+ "slideshow": {
813
+ "slide_type": "slide"
814
+ }
815
+ },
816
+ "source": [
817
+ "### End Activities\n",
818
+ "- ```filter_end_activities(log, activities, retain=True)```\n",
819
+ " - retains (or drops) the traces that contain the given activity as the final event."
820
+ ]
821
+ },
822
+ {
823
+ "cell_type": "markdown",
824
+ "metadata": {
825
+ "pycharm": {
826
+ "name": "#%% md\n"
827
+ },
828
+ "slideshow": {
829
+ "slide_type": "subslide"
830
+ }
831
+ },
832
+ "source": [
833
+ "For example, we can retain the number of cases that end with a \"payment of the compensation\":"
834
+ ]
835
+ },
836
+ {
837
+ "cell_type": "code",
838
+ "execution_count": 75,
839
+ "metadata": {
840
+ "pycharm": {
841
+ "name": "#%%\n"
842
+ },
843
+ "slideshow": {
844
+ "slide_type": "subslide"
845
+ }
846
+ },
847
+ "outputs": [
848
+ {
849
+ "data": {
850
+ "text/plain": "3"
851
+ },
852
+ "execution_count": 75,
853
+ "metadata": {},
854
+ "output_type": "execute_result"
855
+ }
856
+ ],
857
+ "source": [
858
+ "len(pm4py.filter_end_activities(log, 'pay compensation'))"
859
+ ]
860
+ },
861
+ {
862
+ "cell_type": "markdown",
863
+ "source": [
864
+ "### Event Attribute Values"
865
+ ],
866
+ "metadata": {
867
+ "collapsed": false
868
+ }
869
+ },
870
+ {
871
+ "cell_type": "markdown",
872
+ "source": [
873
+ "- ```filter_event_attribute_values(log, attribute_key, values, level=\"case\", retain=True)```\n",
874
+ " - retains (or drops) traces (or events) based on a given collection of ```values``` that need to be matched for the\n",
875
+ " given ```attribute_key```. If ```level=='case'```, complete traces are matched (or dropped if ```retain==False```) that\n",
876
+ " have at least one event that describes a specifeid value for the given attribute. If ```level=='event'```, only events\n",
877
+ " that match are retained (or dropped)."
878
+ ],
879
+ "metadata": {
880
+ "collapsed": false,
881
+ "pycharm": {
882
+ "name": "#%% md\n"
883
+ }
884
+ }
885
+ },
886
+ {
887
+ "cell_type": "code",
888
+ "execution_count": 87,
889
+ "outputs": [
890
+ {
891
+ "data": {
892
+ "text/plain": "[['Pete', 'Mike', 'Ellen', 'Sara', 'Sara', 'Sean', 'Pete', 'Sara', 'Ellen'],\n ['Mike', 'Mike', 'Sean', 'Sara', 'Ellen'],\n ['Pete', 'Sue', 'Mike', 'Sara', 'Pete'],\n ['Mike', 'Ellen', 'Mike', 'Sara', 'Mike'],\n ['Ellen',\n 'Mike',\n 'Pete',\n 'Sara',\n 'Sara',\n 'Ellen',\n 'Mike',\n 'Sara',\n 'Sara',\n 'Sue',\n 'Pete',\n 'Sara',\n 'Mike'],\n ['Pete', 'Mike', 'Sean', 'Sara', 'Ellen']]"
893
+ },
894
+ "execution_count": 87,
895
+ "metadata": {},
896
+ "output_type": "execute_result"
897
+ }
898
+ ],
899
+ "source": [
900
+ "# retain any case that has either Peter or Mike working on it\n",
901
+ "lf = pm4py.filter_event_attribute_values(log, 'org:resource', {'Pete', 'Mike'})\n",
902
+ "list(map(lambda t: list(map(lambda e: e['org:resource'], t)), lf))"
903
+ ],
904
+ "metadata": {
905
+ "collapsed": false,
906
+ "pycharm": {
907
+ "name": "#%%\n"
908
+ }
909
+ }
910
+ },
911
+ {
912
+ "cell_type": "code",
913
+ "execution_count": 88,
914
+ "outputs": [
915
+ {
916
+ "data": {
917
+ "text/plain": "[['Pete', 'Mike', 'Pete'],\n ['Mike', 'Mike'],\n ['Pete', 'Mike', 'Pete'],\n ['Mike', 'Mike', 'Mike'],\n ['Mike', 'Pete', 'Mike', 'Pete', 'Mike'],\n ['Pete', 'Mike']]"
918
+ },
919
+ "execution_count": 88,
920
+ "metadata": {},
921
+ "output_type": "execute_result"
922
+ }
923
+ ],
924
+ "source": [
925
+ "# retain only those events that have Pete or Mik working on it\n",
926
+ "lf = pm4py.filter_event_attribute_values(log, 'org:resource', {'Pete', 'Mike'}, level='event')\n",
927
+ "list(map(lambda t: list(map(lambda e: e['org:resource'], t)), lf))\n"
928
+ ],
929
+ "metadata": {
930
+ "collapsed": false,
931
+ "pycharm": {
932
+ "name": "#%%\n"
933
+ }
934
+ }
935
+ }
936
+ ],
937
+ "metadata": {
938
+ "celltoolbar": "Slideshow",
939
+ "kernelspec": {
940
+ "display_name": "Python 3",
941
+ "language": "python",
942
+ "name": "python3"
943
+ },
944
+ "language_info": {
945
+ "codemirror_mode": {
946
+ "name": "ipython",
947
+ "version": 3
948
+ },
949
+ "file_extension": ".py",
950
+ "mimetype": "text/x-python",
951
+ "name": "python",
952
+ "nbconvert_exporter": "python",
953
+ "pygments_lexer": "ipython3",
954
+ "version": "3.8.5"
955
+ },
956
+ "rise": {
957
+ "enable_chalkboard": true,
958
+ "footer": "<h1>footer<h1>",
959
+ "overlay": "<div><h1>pm4py</h1></div><div><h2>Event Data Filtering</h2></div>"
960
+ }
961
+ },
962
+ "nbformat": 4,
963
+ "nbformat_minor": 1
964
+ }
source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/3_process_discovery.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/4_conformance_checking.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/5_advanced_examples.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/data/receipt.xes ADDED
The diff for this file is too large to render. See raw diff
 
source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/data/running_example.csv ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ case_id;activity;timestamp;costs;org:resource
2
+ 3;register request;2010-12-30 14:32:00+01:00;50;Pete
3
+ 3;examine casually;2010-12-30 15:06:00+01:00;400;Mike
4
+ 3;check ticket;2010-12-30 16:34:00+01:00;100;Ellen
5
+ 3;decide;2011-01-06 09:18:00+01:00;200;Sara
6
+ 3;reinitiate request;2011-01-06 12:18:00+01:00;200;Sara
7
+ 3;examine thoroughly;2011-01-06 13:06:00+01:00;400;Sean
8
+ 3;check ticket;2011-01-08 11:43:00+01:00;100;Pete
9
+ 3;decide;2011-01-09 09:55:00+01:00;200;Sara
10
+ 3;pay compensation;2011-01-15 10:45:00+01:00;200;Ellen
11
+ 2;register request;2010-12-30 11:32:00+01:00;50;Mike
12
+ 2;check ticket;2010-12-30 12:12:00+01:00;100;Mike
13
+ 2;examine casually;2010-12-30 14:16:00+01:00;400;Sean
14
+ 2;decide;2011-01-05 11:22:00+01:00;200;Sara
15
+ 2;pay compensation;2011-01-08 12:05:00+01:00;200;Ellen
16
+ 1;register request;2010-12-30 11:02:00+01:00;50;Pete
17
+ 1;examine thoroughly;2010-12-31 10:06:00+01:00;400;Sue
18
+ 1;check ticket;2011-01-05 15:12:00+01:00;100;Mike
19
+ 1;decide;2011-01-06 11:18:00+01:00;200;Sara
20
+ 1;reject request;2011-01-07 14:24:00+01:00;200;Pete
21
+ 6;register request;2011-01-06 15:02:00+01:00;50;Mike
22
+ 6;examine casually;2011-01-06 16:06:00+01:00;400;Ellen
23
+ 6;check ticket;2011-01-07 16:22:00+01:00;100;Mike
24
+ 6;decide;2011-01-07 16:52:00+01:00;200;Sara
25
+ 6;pay compensation;2011-01-16 11:47:00+01:00;200;Mike
26
+ 5;register request;2011-01-06 09:02:00+01:00;50;Ellen
27
+ 5;examine casually;2011-01-07 10:16:00+01:00;400;Mike
28
+ 5;check ticket;2011-01-08 11:22:00+01:00;100;Pete
29
+ 5;decide;2011-01-10 13:28:00+01:00;200;Sara
30
+ 5;reinitiate request;2011-01-11 16:18:00+01:00;200;Sara
31
+ 5;check ticket;2011-01-14 14:33:00+01:00;100;Ellen
32
+ 5;examine casually;2011-01-16 15:50:00+01:00;400;Mike
33
+ 5;decide;2011-01-19 11:18:00+01:00;200;Sara
34
+ 5;reinitiate request;2011-01-20 12:48:00+01:00;200;Sara
35
+ 5;examine casually;2011-01-21 09:06:00+01:00;400;Sue
36
+ 5;check ticket;2011-01-21 11:34:00+01:00;100;Pete
37
+ 5;decide;2011-01-23 13:12:00+01:00;200;Sara
38
+ 5;reject request;2011-01-24 14:56:00+01:00;200;Mike
39
+ 4;register request;2011-01-06 15:02:00+01:00;50;Pete
40
+ 4;check ticket;2011-01-07 12:06:00+01:00;100;Mike
41
+ 4;examine thoroughly;2011-01-08 14:43:00+01:00;400;Sean
42
+ 4;decide;2011-01-09 12:02:00+01:00;200;Sara
43
+ 4;reject request;2011-01-12 15:44:00+01:00;200;Ellen
source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/data/running_example.xes ADDED
@@ -0,0 +1,373 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <log>
3
+ <extension name="Concept" prefix="concept" uri="http://code.deckfour.org/xes/concept.xesext"/>
4
+ <extension name="Time" prefix="time" uri="http://code.deckfour.org/xes/time.xesext"/>
5
+ <extension name="Organizational" prefix="org" uri="http://code.deckfour.org/xes/org.xesext"/>
6
+ <global scope="trace">
7
+ <string key="concept:name" value="name"/>
8
+ </global>
9
+ <global scope="event">
10
+ <string key="concept:name" value="name"/>
11
+ <string key="org:resource" value="resource"/>
12
+ <date key="time:timestamp" value="2011-04-13T14:02:31.199+02:00"/>
13
+ <string key="Activity" value="string"/>
14
+ <string key="Resource" value="string"/>
15
+ <string key="Costs" value="string"/>
16
+ </global>
17
+ <classifier name="Activity" keys="Activity"/>
18
+ <classifier name="activity classifier" keys="Activity"/>
19
+ <trace>
20
+ <string key="concept:name" value="3"/>
21
+ <event>
22
+ <string key="concept:name" value="register request"/>
23
+ <string key="org:resource" value="Pete"/>
24
+ <date key="time:timestamp" value="2010-12-30T14:32:00.000+01:00"/>
25
+ <string key="Activity" value="register request"/>
26
+ <string key="Resource" value="Pete"/>
27
+ <string key="Costs" value="50"/>
28
+ </event>
29
+ <event>
30
+ <string key="concept:name" value="examine casually"/>
31
+ <string key="org:resource" value="Mike"/>
32
+ <date key="time:timestamp" value="2010-12-30T15:06:00.000+01:00"/>
33
+ <string key="Activity" value="examine casually"/>
34
+ <string key="Resource" value="Mike"/>
35
+ <string key="Costs" value="400"/>
36
+ </event>
37
+ <event>
38
+ <string key="concept:name" value="check ticket"/>
39
+ <string key="org:resource" value="Ellen"/>
40
+ <date key="time:timestamp" value="2010-12-30T16:34:00.000+01:00"/>
41
+ <string key="Activity" value="check ticket"/>
42
+ <string key="Resource" value="Ellen"/>
43
+ <string key="Costs" value="100"/>
44
+ </event>
45
+ <event>
46
+ <string key="concept:name" value="decide"/>
47
+ <string key="org:resource" value="Sara"/>
48
+ <date key="time:timestamp" value="2011-01-06T09:18:00.000+01:00"/>
49
+ <string key="Activity" value="decide"/>
50
+ <string key="Resource" value="Sara"/>
51
+ <string key="Costs" value="200"/>
52
+ </event>
53
+ <event>
54
+ <string key="concept:name" value="reinitiate request"/>
55
+ <string key="org:resource" value="Sara"/>
56
+ <date key="time:timestamp" value="2011-01-06T12:18:00.000+01:00"/>
57
+ <string key="Activity" value="reinitiate request"/>
58
+ <string key="Resource" value="Sara"/>
59
+ <string key="Costs" value="200"/>
60
+ </event>
61
+ <event>
62
+ <string key="concept:name" value="examine thoroughly"/>
63
+ <string key="org:resource" value="Sean"/>
64
+ <date key="time:timestamp" value="2011-01-06T13:06:00.000+01:00"/>
65
+ <string key="Activity" value="examine thoroughly"/>
66
+ <string key="Resource" value="Sean"/>
67
+ <string key="Costs" value="400"/>
68
+ </event>
69
+ <event>
70
+ <string key="concept:name" value="check ticket"/>
71
+ <string key="org:resource" value="Pete"/>
72
+ <date key="time:timestamp" value="2011-01-08T11:43:00.000+01:00"/>
73
+ <string key="Activity" value="check ticket"/>
74
+ <string key="Resource" value="Pete"/>
75
+ <string key="Costs" value="100"/>
76
+ </event>
77
+ <event>
78
+ <string key="concept:name" value="decide"/>
79
+ <string key="org:resource" value="Sara"/>
80
+ <date key="time:timestamp" value="2011-01-09T09:55:00.000+01:00"/>
81
+ <string key="Activity" value="decide"/>
82
+ <string key="Resource" value="Sara"/>
83
+ <string key="Costs" value="200"/>
84
+ </event>
85
+ <event>
86
+ <string key="concept:name" value="pay compensation"/>
87
+ <string key="org:resource" value="Ellen"/>
88
+ <date key="time:timestamp" value="2011-01-15T10:45:00.000+01:00"/>
89
+ <string key="Activity" value="pay compensation"/>
90
+ <string key="Resource" value="Ellen"/>
91
+ <string key="Costs" value="200"/>
92
+ </event>
93
+ </trace>
94
+ <trace>
95
+ <string key="concept:name" value="2"/>
96
+ <event>
97
+ <string key="concept:name" value="register request"/>
98
+ <string key="org:resource" value="Mike"/>
99
+ <date key="time:timestamp" value="2010-12-30T11:32:00.000+01:00"/>
100
+ <string key="Activity" value="register request"/>
101
+ <string key="Resource" value="Mike"/>
102
+ <string key="Costs" value="50"/>
103
+ </event>
104
+ <event>
105
+ <string key="concept:name" value="check ticket"/>
106
+ <string key="org:resource" value="Mike"/>
107
+ <date key="time:timestamp" value="2010-12-30T12:12:00.000+01:00"/>
108
+ <string key="Activity" value="check ticket"/>
109
+ <string key="Resource" value="Mike"/>
110
+ <string key="Costs" value="100"/>
111
+ </event>
112
+ <event>
113
+ <string key="concept:name" value="examine casually"/>
114
+ <string key="org:resource" value="Sean"/>
115
+ <date key="time:timestamp" value="2010-12-30T14:16:00.000+01:00"/>
116
+ <string key="Activity" value="examine casually"/>
117
+ <string key="Resource" value="Sean"/>
118
+ <string key="Costs" value="400"/>
119
+ </event>
120
+ <event>
121
+ <string key="concept:name" value="decide"/>
122
+ <string key="org:resource" value="Sara"/>
123
+ <date key="time:timestamp" value="2011-01-05T11:22:00.000+01:00"/>
124
+ <string key="Activity" value="decide"/>
125
+ <string key="Resource" value="Sara"/>
126
+ <string key="Costs" value="200"/>
127
+ </event>
128
+ <event>
129
+ <string key="concept:name" value="pay compensation"/>
130
+ <string key="org:resource" value="Ellen"/>
131
+ <date key="time:timestamp" value="2011-01-08T12:05:00.000+01:00"/>
132
+ <string key="Activity" value="pay compensation"/>
133
+ <string key="Resource" value="Ellen"/>
134
+ <string key="Costs" value="200"/>
135
+ </event>
136
+ </trace>
137
+ <trace>
138
+ <string key="concept:name" value="1"/>
139
+ <event>
140
+ <string key="concept:name" value="register request"/>
141
+ <string key="org:resource" value="Pete"/>
142
+ <date key="time:timestamp" value="2010-12-30T11:02:00.000+01:00"/>
143
+ <string key="Activity" value="register request"/>
144
+ <string key="Resource" value="Pete"/>
145
+ <string key="Costs" value="50"/>
146
+ </event>
147
+ <event>
148
+ <string key="concept:name" value="examine thoroughly"/>
149
+ <string key="org:resource" value="Sue"/>
150
+ <date key="time:timestamp" value="2010-12-31T10:06:00.000+01:00"/>
151
+ <string key="Activity" value="examine thoroughly"/>
152
+ <string key="Resource" value="Sue"/>
153
+ <string key="Costs" value="400"/>
154
+ </event>
155
+ <event>
156
+ <string key="concept:name" value="check ticket"/>
157
+ <string key="org:resource" value="Mike"/>
158
+ <date key="time:timestamp" value="2011-01-05T15:12:00.000+01:00"/>
159
+ <string key="Activity" value="check ticket"/>
160
+ <string key="Resource" value="Mike"/>
161
+ <string key="Costs" value="100"/>
162
+ </event>
163
+ <event>
164
+ <string key="concept:name" value="decide"/>
165
+ <string key="org:resource" value="Sara"/>
166
+ <date key="time:timestamp" value="2011-01-06T11:18:00.000+01:00"/>
167
+ <string key="Activity" value="decide"/>
168
+ <string key="Resource" value="Sara"/>
169
+ <string key="Costs" value="200"/>
170
+ </event>
171
+ <event>
172
+ <string key="concept:name" value="reject request"/>
173
+ <string key="org:resource" value="Pete"/>
174
+ <date key="time:timestamp" value="2011-01-07T14:24:00.000+01:00"/>
175
+ <string key="Activity" value="reject request"/>
176
+ <string key="Resource" value="Pete"/>
177
+ <string key="Costs" value="200"/>
178
+ </event>
179
+ </trace>
180
+ <trace>
181
+ <string key="concept:name" value="6"/>
182
+ <event>
183
+ <string key="concept:name" value="register request"/>
184
+ <string key="org:resource" value="Mike"/>
185
+ <date key="time:timestamp" value="2011-01-06T15:02:00.000+01:00"/>
186
+ <string key="Activity" value="register request"/>
187
+ <string key="Resource" value="Mike"/>
188
+ <string key="Costs" value="50"/>
189
+ </event>
190
+ <event>
191
+ <string key="concept:name" value="examine casually"/>
192
+ <string key="org:resource" value="Ellen"/>
193
+ <date key="time:timestamp" value="2011-01-06T16:06:00.000+01:00"/>
194
+ <string key="Activity" value="examine casually"/>
195
+ <string key="Resource" value="Ellen"/>
196
+ <string key="Costs" value="400"/>
197
+ </event>
198
+ <event>
199
+ <string key="concept:name" value="check ticket"/>
200
+ <string key="org:resource" value="Mike"/>
201
+ <date key="time:timestamp" value="2011-01-07T16:22:00.000+01:00"/>
202
+ <string key="Activity" value="check ticket"/>
203
+ <string key="Resource" value="Mike"/>
204
+ <string key="Costs" value="100"/>
205
+ </event>
206
+ <event>
207
+ <string key="concept:name" value="decide"/>
208
+ <string key="org:resource" value="Sara"/>
209
+ <date key="time:timestamp" value="2011-01-07T16:52:00.000+01:00"/>
210
+ <string key="Activity" value="decide"/>
211
+ <string key="Resource" value="Sara"/>
212
+ <string key="Costs" value="200"/>
213
+ </event>
214
+ <event>
215
+ <string key="concept:name" value="pay compensation"/>
216
+ <string key="org:resource" value="Mike"/>
217
+ <date key="time:timestamp" value="2011-01-16T11:47:00.000+01:00"/>
218
+ <string key="Activity" value="pay compensation"/>
219
+ <string key="Resource" value="Mike"/>
220
+ <string key="Costs" value="200"/>
221
+ </event>
222
+ </trace>
223
+ <trace>
224
+ <string key="concept:name" value="5"/>
225
+ <event>
226
+ <string key="concept:name" value="register request"/>
227
+ <string key="org:resource" value="Ellen"/>
228
+ <date key="time:timestamp" value="2011-01-06T09:02:00.000+01:00"/>
229
+ <string key="Activity" value="register request"/>
230
+ <string key="Resource" value="Ellen"/>
231
+ <string key="Costs" value="50"/>
232
+ </event>
233
+ <event>
234
+ <string key="concept:name" value="examine casually"/>
235
+ <string key="org:resource" value="Mike"/>
236
+ <date key="time:timestamp" value="2011-01-07T10:16:00.000+01:00"/>
237
+ <string key="Activity" value="examine casually"/>
238
+ <string key="Resource" value="Mike"/>
239
+ <string key="Costs" value="400"/>
240
+ </event>
241
+ <event>
242
+ <string key="concept:name" value="check ticket"/>
243
+ <string key="org:resource" value="Pete"/>
244
+ <date key="time:timestamp" value="2011-01-08T11:22:00.000+01:00"/>
245
+ <string key="Activity" value="check ticket"/>
246
+ <string key="Resource" value="Pete"/>
247
+ <string key="Costs" value="100"/>
248
+ </event>
249
+ <event>
250
+ <string key="concept:name" value="decide"/>
251
+ <string key="org:resource" value="Sara"/>
252
+ <date key="time:timestamp" value="2011-01-10T13:28:00.000+01:00"/>
253
+ <string key="Activity" value="decide"/>
254
+ <string key="Resource" value="Sara"/>
255
+ <string key="Costs" value="200"/>
256
+ </event>
257
+ <event>
258
+ <string key="concept:name" value="reinitiate request"/>
259
+ <string key="org:resource" value="Sara"/>
260
+ <date key="time:timestamp" value="2011-01-11T16:18:00.000+01:00"/>
261
+ <string key="Activity" value="reinitiate request"/>
262
+ <string key="Resource" value="Sara"/>
263
+ <string key="Costs" value="200"/>
264
+ </event>
265
+ <event>
266
+ <string key="concept:name" value="check ticket"/>
267
+ <string key="org:resource" value="Ellen"/>
268
+ <date key="time:timestamp" value="2011-01-14T14:33:00.000+01:00"/>
269
+ <string key="Activity" value="check ticket"/>
270
+ <string key="Resource" value="Ellen"/>
271
+ <string key="Costs" value="100"/>
272
+ </event>
273
+ <event>
274
+ <string key="concept:name" value="examine casually"/>
275
+ <string key="org:resource" value="Mike"/>
276
+ <date key="time:timestamp" value="2011-01-16T15:50:00.000+01:00"/>
277
+ <string key="Activity" value="examine casually"/>
278
+ <string key="Resource" value="Mike"/>
279
+ <string key="Costs" value="400"/>
280
+ </event>
281
+ <event>
282
+ <string key="concept:name" value="decide"/>
283
+ <string key="org:resource" value="Sara"/>
284
+ <date key="time:timestamp" value="2011-01-19T11:18:00.000+01:00"/>
285
+ <string key="Activity" value="decide"/>
286
+ <string key="Resource" value="Sara"/>
287
+ <string key="Costs" value="200"/>
288
+ </event>
289
+ <event>
290
+ <string key="concept:name" value="reinitiate request"/>
291
+ <string key="org:resource" value="Sara"/>
292
+ <date key="time:timestamp" value="2011-01-20T12:48:00.000+01:00"/>
293
+ <string key="Activity" value="reinitiate request"/>
294
+ <string key="Resource" value="Sara"/>
295
+ <string key="Costs" value="200"/>
296
+ </event>
297
+ <event>
298
+ <string key="concept:name" value="examine casually"/>
299
+ <string key="org:resource" value="Sue"/>
300
+ <date key="time:timestamp" value="2011-01-21T09:06:00.000+01:00"/>
301
+ <string key="Activity" value="examine casually"/>
302
+ <string key="Resource" value="Sue"/>
303
+ <string key="Costs" value="400"/>
304
+ </event>
305
+ <event>
306
+ <string key="concept:name" value="check ticket"/>
307
+ <string key="org:resource" value="Pete"/>
308
+ <date key="time:timestamp" value="2011-01-21T11:34:00.000+01:00"/>
309
+ <string key="Activity" value="check ticket"/>
310
+ <string key="Resource" value="Pete"/>
311
+ <string key="Costs" value="100"/>
312
+ </event>
313
+ <event>
314
+ <string key="concept:name" value="decide"/>
315
+ <string key="org:resource" value="Sara"/>
316
+ <date key="time:timestamp" value="2011-01-23T13:12:00.000+01:00"/>
317
+ <string key="Activity" value="decide"/>
318
+ <string key="Resource" value="Sara"/>
319
+ <string key="Costs" value="200"/>
320
+ </event>
321
+ <event>
322
+ <string key="concept:name" value="reject request"/>
323
+ <string key="org:resource" value="Mike"/>
324
+ <date key="time:timestamp" value="2011-01-24T14:56:00.000+01:00"/>
325
+ <string key="Activity" value="reject request"/>
326
+ <string key="Resource" value="Mike"/>
327
+ <string key="Costs" value="200"/>
328
+ </event>
329
+ </trace>
330
+ <trace>
331
+ <string key="concept:name" value="4"/>
332
+ <event>
333
+ <string key="concept:name" value="register request"/>
334
+ <string key="org:resource" value="Pete"/>
335
+ <date key="time:timestamp" value="2011-01-06T15:02:00.000+01:00"/>
336
+ <string key="Activity" value="register request"/>
337
+ <string key="Resource" value="Pete"/>
338
+ <string key="Costs" value="50"/>
339
+ </event>
340
+ <event>
341
+ <string key="concept:name" value="check ticket"/>
342
+ <string key="org:resource" value="Mike"/>
343
+ <date key="time:timestamp" value="2011-01-07T12:06:00.000+01:00"/>
344
+ <string key="Activity" value="check ticket"/>
345
+ <string key="Resource" value="Mike"/>
346
+ <string key="Costs" value="100"/>
347
+ </event>
348
+ <event>
349
+ <string key="concept:name" value="examine thoroughly"/>
350
+ <string key="org:resource" value="Sean"/>
351
+ <date key="time:timestamp" value="2011-01-08T14:43:00.000+01:00"/>
352
+ <string key="Activity" value="examine thoroughly"/>
353
+ <string key="Resource" value="Sean"/>
354
+ <string key="Costs" value="400"/>
355
+ </event>
356
+ <event>
357
+ <string key="concept:name" value="decide"/>
358
+ <string key="org:resource" value="Sara"/>
359
+ <date key="time:timestamp" value="2011-01-09T12:02:00.000+01:00"/>
360
+ <string key="Activity" value="decide"/>
361
+ <string key="Resource" value="Sara"/>
362
+ <string key="Costs" value="200"/>
363
+ </event>
364
+ <event>
365
+ <string key="concept:name" value="reject request"/>
366
+ <string key="org:resource" value="Ellen"/>
367
+ <date key="time:timestamp" value="2011-01-12T15:44:00.000+01:00"/>
368
+ <string key="Activity" value="reject request"/>
369
+ <string key="Resource" value="Ellen"/>
370
+ <string key="Costs" value="200"/>
371
+ </event>
372
+ </trace>
373
+ </log>
source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/data/running_example_broken.csv ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ costs;Resource;case:concept:name;concept:name;org:resource;time:timestamp
2
+ 50;Pete;3;register request;Pete;2010-12-30 14:32:00+01:00
3
+ 100;Ellen;3;check ticket;Ellen;2010-12-30 16:34:00+01:00
4
+ 200;Sara;3;decide;Sara;2011-01-06 09:18:00+01:00
5
+ 200;Sara;3;reinitiate request;Sara;2011-01-06 12:18:00+01:00
6
+ 200;Ellen;3;pay compensation;Ellen;2011-01-15 10:45:00+01:00
7
+ 50;Mike;2;register request;Mike;2010-12-30 11:32:00+01:00
8
+ 100;Mike;2;check ticket;Mike;2010-12-30 12:12:00+01:00
9
+ 400;Sean;2;examine casually;Sean;2010-12-30 14:16:00+01:00
10
+ 200;Ellen;2;pay compensation;Ellen;2011-01-08 12:05:00+01:00
11
+ 400;Sue;1;examine thoroughly;Sue;2010-12-31 10:06:00+01:00
12
+ 100;Mike;1;check ticket;Mike;2011-01-05 15:12:00+01:00
13
+ 200;Sara;1;decide;Sara;2011-01-06 11:18:00+01:00
14
+ 200;Pete;1;reject request;Pete;2011-01-07 14:24:00+01:00
15
+ 50;Mike;6;register request;Mike;2011-01-06 15:02:00+01:00
16
+ 100;Mike;6;check ticket;Mike;2011-01-07 16:22:00+01:00
17
+ 200;Sara;6;decide something;Sara;2011-01-07 16:52:00+01:00
18
+ 200;Mike;6;pay compensation;Mike;2011-01-16 11:47:00+01:00
19
+ 50;Ellen;5;register request;Ellen;2011-01-06 09:02:00+01:00
20
+ 400;Mike;5;examine casually;Mike;2011-01-07 10:16:00+01:00
21
+ 100;Pete;5;check ticket;Pete;2011-01-08 11:22:00+01:00
22
+ 200;Sara;5;decide;Sara;2011-01-10 13:28:00+01:00
23
+ 200;Sara;5;reinitiate the request for real;Sara;2011-01-11 16:18:00+01:00
24
+ 100;Ellen;5;check ticket;Ellen;2011-01-14 14:33:00+01:00
25
+ 400;Mike;5;examine casually;Mike;2011-01-16 15:50:00+01:00
26
+ 200;Sara;5;decide;Sara;2011-01-19 11:18:00+01:00
27
+ 400;Sue;5;examine casually;Sue;2011-01-21 09:06:00+01:00
28
+ 100;Pete;5;check ticket;Pete;2011-01-21 11:34:00+01:00
29
+ 200;Sara;5;decide;Sara;2011-01-23 13:12:00+01:00
30
+ 200;Mike;5;reject request;Mike;2011-01-24 14:56:00+01:00
31
+ 50;Pete;4;register request;Pete;2011-01-06 15:02:00+01:00
32
+ 100;Mike;4;check ticket;Mike;2011-01-07 12:06:00+01:00
33
+ 400;Sean;4;examine thoroughly;Sean;2011-01-08 14:43:00+01:00
34
+ 200;Sara;4;decide;Sara;2011-01-09 12:02:00+01:00
35
+ 200;Ellen;4;reject request;Ellen;2011-01-12 15:44:00+01:00
source_data/pinned/pm4py-process/tag-2.7.23.11/notebooks/img/bpmn_running_example.png ADDED

Git LFS Details

  • SHA256: 44af284679600cc0e27d9ecc104a574dd36bea8d98d4e14d380f4e1513d25511
  • Pointer size: 130 Bytes
  • Size of remote file: 44.4 kB
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/__init__.py ADDED
@@ -0,0 +1,413 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+ PM4Py – A Process Mining Library for Python
3
+ Copyright (C) 2026 Process Intelligence Solutions GmbH
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as
7
+ published by the Free Software Foundation, either version 3 of the
8
+ License, or any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Affero General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see this software project's root or
17
+ visit <https://www.gnu.org/licenses/>.
18
+
19
+ Website: https://processintelligence.solutions
20
+ Contact: info@processintelligence.solutions
21
+ '''
22
+ import sys
23
+ import time
24
+
25
+
26
+ def _pm4py_is_direct_import_from_entrypoint():
27
+ importlib_module_names = {
28
+ "_frozen_importlib",
29
+ "_frozen_importlib_external",
30
+ "importlib",
31
+ "importlib._bootstrap",
32
+ "importlib._bootstrap_external",
33
+ }
34
+ getframe = getattr(sys, "_getframe", None)
35
+ if getframe is None:
36
+ return False
37
+ frame = getframe(1)
38
+ while frame is not None:
39
+ module_name = frame.f_globals.get("__name__")
40
+ if module_name == __name__ or module_name in importlib_module_names:
41
+ frame = frame.f_back
42
+ continue
43
+ return module_name == "__main__"
44
+ return False
45
+
46
+
47
+ def _print_welcome():
48
+ yellow = "\033[93m"
49
+ cyan = "\033[96m"
50
+ reset = "\033[0m"
51
+
52
+ lines = [
53
+ "",
54
+ f"{yellow}{'=' * 60}{reset}",
55
+ "",
56
+ f" Welcome to {cyan}PM4Py{reset} — Community Version",
57
+ " Open-Source License (AGPL v3)",
58
+ "",
59
+ " 📚 Docs & Examples:",
60
+ " https://processintelligence.solutions/pm4py",
61
+ "",
62
+ f" ⚖️ {yellow}License: AGPL v3 — Commercial use requires open-sourcing your application.{reset}",
63
+ " Business use without open-sourcing? A commercial license is available:",
64
+ " https://processintelligence.solutions/pm4py#licensing",
65
+ "",
66
+ f"{yellow}{'=' * 60}{reset}",
67
+ "",
68
+ ]
69
+ print("\n".join(lines), file=sys.stderr)
70
+
71
+
72
+ if not hasattr(sys, "_pm4py_welcome_shown") and _pm4py_is_direct_import_from_entrypoint():
73
+ _print_welcome()
74
+ sys._pm4py_welcome_shown = True
75
+
76
+
77
+ from pm4py import (
78
+ util,
79
+ objects,
80
+ statistics,
81
+ algo,
82
+ visualization,
83
+ llm,
84
+ connectors,
85
+ )
86
+ from pm4py import (
87
+ analysis,
88
+ conformance,
89
+ convert,
90
+ discovery,
91
+ filtering,
92
+ hof,
93
+ ml,
94
+ ocel,
95
+ org,
96
+ read,
97
+ sim,
98
+ stats,
99
+ utils,
100
+ vis,
101
+ write,
102
+ )
103
+ from pm4py.read import (
104
+ read_xes,
105
+ read_dfg,
106
+ read_bpmn,
107
+ read_pnml,
108
+ read_ptml,
109
+ read_ocel,
110
+ read_ocel_csv,
111
+ read_ocel_xml,
112
+ read_ocel_json,
113
+ read_ocel_sqlite,
114
+ read_ocel2,
115
+ read_ocel2_bundle,
116
+ read_ocel2_csv,
117
+ read_ocel2_sqlite,
118
+ read_ocel2_json,
119
+ read_ocel2_xml,
120
+ )
121
+ from pm4py.write import (
122
+ write_xes,
123
+ write_dfg,
124
+ write_bpmn,
125
+ write_pnml,
126
+ write_ptml,
127
+ write_ocel,
128
+ write_ocel_json,
129
+ write_ocel_csv,
130
+ write_ocel_xml,
131
+ write_ocel_sqlite,
132
+ write_ocel2,
133
+ write_ocel2_bundle,
134
+ write_ocel2_csv,
135
+ write_ocel2_sqlite,
136
+ write_ocel2_xml,
137
+ write_ocel2_json,
138
+ )
139
+ from pm4py.utils import (
140
+ format_dataframe,
141
+ parse_process_tree,
142
+ serialize,
143
+ deserialize,
144
+ set_classifier,
145
+ parse_event_log_string,
146
+ project_on_event_attribute,
147
+ sample_cases,
148
+ sample_events,
149
+ rebase,
150
+ parse_powl_model_string,
151
+ )
152
+ from pm4py.filtering import (
153
+ filter_log_relative_occurrence_event_attribute,
154
+ filter_start_activities,
155
+ filter_end_activities,
156
+ filter_variants,
157
+ filter_directly_follows_relation,
158
+ filter_time_range,
159
+ filter_eventually_follows_relation,
160
+ filter_event_attribute_values,
161
+ filter_trace_attribute_values,
162
+ filter_between,
163
+ filter_case_size,
164
+ filter_case_performance,
165
+ filter_activities_rework,
166
+ filter_paths_performance,
167
+ filter_variants_by_coverage_percentage,
168
+ filter_variants_top_k,
169
+ filter_ocel_event_attribute,
170
+ filter_ocel_object_attribute,
171
+ filter_ocel_object_types_allowed_activities,
172
+ filter_ocel_object_per_type_count,
173
+ filter_ocel_start_events_per_object_type,
174
+ filter_ocel_end_events_per_object_type,
175
+ filter_ocel_events_timestamp,
176
+ filter_prefixes,
177
+ filter_suffixes,
178
+ filter_trace_segments,
179
+ filter_four_eyes_principle,
180
+ filter_activity_done_different_resources,
181
+ filter_ocel_events,
182
+ filter_ocel_objects,
183
+ filter_ocel_object_types,
184
+ filter_ocel_cc_object,
185
+ filter_ocel_cc_length,
186
+ filter_ocel_cc_otype,
187
+ filter_ocel_cc_activity,
188
+ filter_ocel_activities_connected_object_type,
189
+ filter_dfg_activities_percentage,
190
+ filter_dfg_paths_percentage
191
+ )
192
+ from pm4py.discovery import (
193
+ discover_petri_net_alpha,
194
+ discover_petri_net_alpha_plus,
195
+ discover_petri_net_ilp,
196
+ discover_petri_net_heuristics,
197
+ discover_petri_net_inductive,
198
+ discover_petri_net_genetic,
199
+ discover_process_tree_inductive,
200
+ discover_heuristics_net,
201
+ discover_dfg,
202
+ discover_footprints,
203
+ discover_eventually_follows_graph,
204
+ discover_directly_follows_graph,
205
+ discover_bpmn_inductive,
206
+ discover_bpmn_split_miner,
207
+ discover_performance_dfg,
208
+ discover_transition_system,
209
+ discover_prefix_tree,
210
+ discover_temporal_profile,
211
+ discover_log_skeleton,
212
+ discover_batches,
213
+ derive_minimum_self_distance,
214
+ discover_dfg_typed,
215
+ discover_declare,
216
+ discover_powl,
217
+ correlation_miner,
218
+ discover_otg,
219
+ discover_etot,
220
+ )
221
+ from pm4py.conformance import (
222
+ conformance_diagnostics_token_based_replay,
223
+ conformance_diagnostics_alignments,
224
+ fitness_token_based_replay,
225
+ fitness_alignments,
226
+ precision_token_based_replay,
227
+ precision_alignments,
228
+ conformance_diagnostics_footprints,
229
+ fitness_footprints,
230
+ precision_footprints,
231
+ check_is_fitting,
232
+ conformance_temporal_profile,
233
+ conformance_declare,
234
+ conformance_log_skeleton,
235
+ conformance_ocdfg,
236
+ conformance_otg,
237
+ conformance_etot,
238
+ replay_prefix_tbr,
239
+ generalization_tbr,
240
+ )
241
+ from pm4py.ocel import (
242
+ ocel_objects_interactions_summary,
243
+ ocel_temporal_summary,
244
+ ocel_objects_summary,
245
+ ocel_get_object_types,
246
+ ocel_get_attribute_names,
247
+ ocel_flattening,
248
+ ocel_object_type_activities,
249
+ ocel_objects_ot_count,
250
+ discover_ocdfg,
251
+ discover_oc_petri_net,
252
+ discover_objects_graph,
253
+ sample_ocel_objects,
254
+ ocel_drop_duplicates,
255
+ ocel_merge_duplicates,
256
+ ocel_sort_by_additional_column,
257
+ ocel_add_index_based_timedelta,
258
+ sample_ocel_connected_components,
259
+ ocel_o2o_enrichment,
260
+ ocel_e2o_lifecycle_enrichment,
261
+ cluster_equivalent_ocel,
262
+ ocel_drill_down,
263
+ ocel_roll_up,
264
+ ocel_unfold,
265
+ ocel_fold,
266
+ )
267
+ from pm4py.vis import (
268
+ view_petri_net,
269
+ save_vis_petri_net,
270
+ view_dfg,
271
+ save_vis_dfg,
272
+ view_process_tree,
273
+ save_vis_process_tree,
274
+ view_ocdfg,
275
+ save_vis_ocdfg,
276
+ view_heuristics_net,
277
+ save_vis_heuristics_net,
278
+ view_bpmn,
279
+ save_vis_bpmn,
280
+ view_sna,
281
+ save_vis_sna,
282
+ view_dotted_chart,
283
+ save_vis_dotted_chart,
284
+ view_performance_spectrum,
285
+ save_vis_performance_spectrum,
286
+ view_case_duration_graph,
287
+ view_events_per_time_graph,
288
+ save_vis_case_duration_graph,
289
+ save_vis_events_per_time_graph,
290
+ view_events_distribution_graph,
291
+ save_vis_events_distribution_graph,
292
+ view_performance_dfg,
293
+ save_vis_performance_dfg,
294
+ view_ocpn,
295
+ save_vis_ocpn,
296
+ view_network_analysis,
297
+ save_vis_network_analysis,
298
+ view_transition_system,
299
+ save_vis_transition_system,
300
+ view_prefix_tree,
301
+ save_vis_prefix_tree,
302
+ view_object_graph,
303
+ save_vis_object_graph,
304
+ view_alignments,
305
+ save_vis_alignments,
306
+ view_footprints,
307
+ save_vis_footprints,
308
+ view_powl,
309
+ save_vis_powl,
310
+ )
311
+ from pm4py.convert import (
312
+ convert_to_event_log,
313
+ convert_to_event_stream,
314
+ convert_to_dataframe,
315
+ convert_to_bpmn,
316
+ convert_to_petri_net,
317
+ convert_to_process_tree,
318
+ convert_to_reachability_graph,
319
+ convert_log_to_ocel,
320
+ convert_ocel_to_networkx,
321
+ convert_log_to_networkx,
322
+ convert_log_to_time_intervals,
323
+ convert_petri_net_to_networkx,
324
+ convert_petri_net_type,
325
+ convert_to_powl,
326
+ )
327
+ from pm4py.analysis import (
328
+ cluster_log,
329
+ check_soundness,
330
+ compute_emd,
331
+ solve_marking_equation,
332
+ solve_extended_marking_equation,
333
+ construct_synchronous_product_net,
334
+ insert_artificial_start_end,
335
+ check_is_workflow_net,
336
+ maximal_decomposition,
337
+ generate_marking,
338
+ reduce_petri_net_invisibles,
339
+ reduce_petri_net_implicit_places,
340
+ insert_case_arrival_finish_rate,
341
+ insert_case_service_waiting_time,
342
+ get_enabled_transitions,
343
+ simplicity_petri_net,
344
+ behavioral_similarity,
345
+ structural_similarity,
346
+ embeddings_similarity,
347
+ get_activity_labels,
348
+ replace_activity_labels,
349
+ label_sets_similarity,
350
+ map_labels_from_second_model
351
+ )
352
+ from pm4py.stats import (
353
+ get_start_activities,
354
+ get_process_cube,
355
+ get_end_activities,
356
+ get_event_attributes,
357
+ get_event_attribute_values,
358
+ get_variants,
359
+ get_trace_attributes,
360
+ get_variants_as_tuples,
361
+ get_trace_attribute_values,
362
+ get_case_arrival_average,
363
+ get_minimum_self_distances,
364
+ get_minimum_self_distance_witnesses,
365
+ get_frequent_trace_segments,
366
+ get_case_arrival_average,
367
+ get_rework_cases_per_activity,
368
+ get_case_overlap,
369
+ get_cycle_time,
370
+ get_all_case_durations,
371
+ get_case_duration,
372
+ get_activity_position_summary,
373
+ get_stochastic_language,
374
+ split_by_process_variant,
375
+ get_variants_paths_duration,
376
+ get_service_time
377
+ )
378
+ from pm4py.sim import play_out, generate_process_tree
379
+ from pm4py.ml import (
380
+ split_train_test,
381
+ get_prefixes_from_log,
382
+ extract_ocel_features,
383
+ extract_features_dataframe,
384
+ extract_temporal_features_dataframe,
385
+ extract_outcome_enriched_dataframe,
386
+ extract_target_vector,
387
+ )
388
+ from pm4py.org import (
389
+ discover_handover_of_work_network,
390
+ discover_activity_based_resource_similarity,
391
+ discover_subcontracting_network,
392
+ discover_working_together_network,
393
+ discover_organizational_roles,
394
+ discover_network_analysis,
395
+ )
396
+
397
+ # from pm4py.hof import filter_log, filter_trace, sort_trace, sort_log
398
+ from pm4py.meta import (
399
+ __name__,
400
+ __version__,
401
+ __doc__,
402
+ __author__,
403
+ __author_email__,
404
+ __maintainer__,
405
+ __maintainer_email__,
406
+ )
407
+
408
+ from pm4py.objects.petri_net.obj import PetriNet, Marking
409
+ from pm4py.objects.process_tree.obj import ProcessTree
410
+ from pm4py.objects.ocel.obj import OCEL
411
+ from pm4py.objects.bpmn.obj import BPMN
412
+
413
+ time.clock = time.process_time
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/__init__.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+ PM4Py – A Process Mining Library for Python
3
+ Copyright (C) 2026 Process Intelligence Solutions GmbH
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as
7
+ published by the Free Software Foundation, either version 3 of the
8
+ License, or any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Affero General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see this software project's root or
17
+ visit <https://www.gnu.org/licenses/>.
18
+
19
+ Website: https://processintelligence.solutions
20
+ Contact: info@processintelligence.solutions
21
+ '''
22
+ from pm4py.util import constants as pm4_constants
23
+
24
+ if pm4_constants.ENABLE_INTERNAL_IMPORTS:
25
+ from pm4py.algo import (
26
+ analysis,
27
+ clustering,
28
+ comparison,
29
+ concept_drift,
30
+ conformance,
31
+ connectors,
32
+ discovery,
33
+ evaluation,
34
+ filtering,
35
+ label_splitting,
36
+ merging,
37
+ organizational_mining,
38
+ querying,
39
+ simulation,
40
+ transformation,
41
+ )
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/analysis/__init__.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+ PM4Py – A Process Mining Library for Python
3
+ Copyright (C) 2026 Process Intelligence Solutions GmbH
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as
7
+ published by the Free Software Foundation, either version 3 of the
8
+ License, or any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Affero General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see this software project's root or
17
+ visit <https://www.gnu.org/licenses/>.
18
+
19
+ Website: https://processintelligence.solutions
20
+ Contact: info@processintelligence.solutions
21
+ '''
22
+ from pm4py.util import constants as pm4_constants
23
+
24
+ if pm4_constants.ENABLE_INTERNAL_IMPORTS:
25
+ from pm4py.algo.analysis import (
26
+ extended_marking_equation,
27
+ marking_equation,
28
+ workflow_net,
29
+ woflan,
30
+ )
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/analysis/extended_marking_equation/__init__.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+ PM4Py – A Process Mining Library for Python
3
+ Copyright (C) 2026 Process Intelligence Solutions GmbH
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as
7
+ published by the Free Software Foundation, either version 3 of the
8
+ License, or any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Affero General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see this software project's root or
17
+ visit <https://www.gnu.org/licenses/>.
18
+
19
+ Website: https://processintelligence.solutions
20
+ Contact: info@processintelligence.solutions
21
+ '''
22
+ from pm4py.algo.analysis.extended_marking_equation import variants
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/analysis/extended_marking_equation/algorithm.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+ PM4Py – A Process Mining Library for Python
3
+ Copyright (C) 2026 Process Intelligence Solutions GmbH
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as
7
+ published by the Free Software Foundation, either version 3 of the
8
+ License, or any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Affero General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see this software project's root or
17
+ visit <https://www.gnu.org/licenses/>.
18
+
19
+ Website: https://processintelligence.solutions
20
+ Contact: info@processintelligence.solutions
21
+ '''
22
+ from enum import Enum
23
+ from typing import Optional, Dict, Any
24
+
25
+ from pm4py.algo.analysis.extended_marking_equation.variants import classic
26
+ from pm4py.objects.log.obj import Trace
27
+ from pm4py.objects.petri_net.obj import PetriNet, Marking
28
+ from pm4py.util import exec_utils
29
+
30
+
31
+ class Variants(Enum):
32
+ CLASSIC = classic
33
+
34
+
35
+ def build(
36
+ trace: Trace,
37
+ sync_net: PetriNet,
38
+ sync_im: Marking,
39
+ sync_fm: Marking,
40
+ variant=Variants.CLASSIC,
41
+ parameters: Optional[Dict[Any, Any]] = None,
42
+ ) -> Any:
43
+ """
44
+ Builds the extended marking equation out of a trace and a synchronous product net
45
+
46
+ Parameters
47
+ ----------
48
+ trace
49
+ Trace
50
+ sync_net
51
+ Synchronous product net
52
+ sync_im
53
+ Initial marking (of sync net)
54
+ sync_fm
55
+ Final marking (of sync net)
56
+ variant
57
+ Variant of the algorithm to use, possible values:
58
+
59
+ - Variants.CLASSIC parameters Parameters of the algorithm, including:
60
+ - Parameters.CASE_ID_KEY => attribute to use as case identifier
61
+ - Parameters.ACTIVITY_KEY => attribute to use as activity
62
+ - Parameters.COSTS => (if provided) the cost function (otherwise the default cost function is applied)
63
+ - Parameters.SPLIT_IDX => (if provided) the split points as indices of elements of the trace (e.g. for ["A", "B", "C", "D", "E"], specifying [1,3] as split points means splitting at "B" and "D"). If not provided, some split points at uniform distances are found.
64
+ - Parameters.MAX_K_VALUE => the maximum number of split points that is allowed (trim the specified indexes if necessary).
65
+ - Parameters.INCIDENCE_MATRIX => (if provided) the incidence matrix associated to the sync product net
66
+ - Parameters.A => (if provided) the A numpy matrix of the incidence matrix
67
+ - Parameters.CONSUMPTION_MATRIX => (if provided) the consumption matrix associated to the sync product net
68
+ - Parameters.C => (if provided) the C numpy matrix of the consumption matrix
69
+ - Parameters.FULL_BOOTSTRAP_REQUIRED => The preset/postset of places/transitions need to be inserted
70
+
71
+ """
72
+ return exec_utils.get_variant(variant).build(
73
+ trace, sync_net, sync_im, sync_fm, parameters=parameters
74
+ )
75
+
76
+
77
+ def get_h_value(
78
+ solver: Any,
79
+ variant=Variants.CLASSIC,
80
+ parameters: Optional[Dict[Any, Any]] = None,
81
+ ) -> int:
82
+ """
83
+ Gets the heuristics value from the extended marking equation
84
+
85
+ Parameters
86
+ --------------
87
+ solver
88
+ Extended marking equation solver (class in this file)
89
+ variant
90
+ Variant of the algorithm to use, possible values:
91
+ - Variants.CLASSIC
92
+ parameters
93
+ Possible parameters of the algorithm
94
+ """
95
+ return exec_utils.get_variant(variant).get_h_value(
96
+ solver, parameters=parameters
97
+ )
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/analysis/extended_marking_equation/variants/__init__.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+ PM4Py – A Process Mining Library for Python
3
+ Copyright (C) 2026 Process Intelligence Solutions GmbH
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as
7
+ published by the Free Software Foundation, either version 3 of the
8
+ License, or any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Affero General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see this software project's root or
17
+ visit <https://www.gnu.org/licenses/>.
18
+
19
+ Website: https://processintelligence.solutions
20
+ Contact: info@processintelligence.solutions
21
+ '''
22
+ from pm4py.algo.analysis.extended_marking_equation.variants import classic
source_data/pinned/pm4py-process/tag-2.7.23.11/pm4py/algo/analysis/extended_marking_equation/variants/classic.py ADDED
@@ -0,0 +1,641 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+ PM4Py – A Process Mining Library for Python
3
+ Copyright (C) 2026 Process Intelligence Solutions GmbH
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as
7
+ published by the Free Software Foundation, either version 3 of the
8
+ License, or any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Affero General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see this software project's root or
17
+ visit <https://www.gnu.org/licenses/>.
18
+
19
+ Website: https://processintelligence.solutions
20
+ Contact: info@processintelligence.solutions
21
+ '''
22
+ from enum import Enum
23
+ from typing import Optional, Dict
24
+ from typing import Tuple, List, Any
25
+
26
+ import numpy as np
27
+
28
+ from pm4py.objects.log.obj import Trace
29
+ from pm4py.objects.petri_net.utils import (
30
+ align_utils,
31
+ petri_utils as petri_utils,
32
+ )
33
+ from pm4py.objects.petri_net.utils.consumption_matrix import ConsumptionMatrix
34
+ from pm4py.objects.petri_net.utils.incidence_matrix import IncidenceMatrix
35
+ from pm4py.objects.petri_net.obj import PetriNet, Marking
36
+ from pm4py.util import exec_utils, constants, xes_constants, points_subset
37
+ from pm4py.util.lp import solver
38
+
39
+
40
+ class Parameters(Enum):
41
+ CASE_ID_KEY = constants.PARAMETER_CONSTANT_CASEID_KEY
42
+ ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
43
+ MAX_K_VALUE = "max_k_value"
44
+ COSTS = "costs"
45
+ SPLIT_IDX = "split_idx"
46
+ INCIDENCE_MATRIX = "incidence_matrix"
47
+ A = "A_matrix"
48
+ CONSUMPTION_MATRIX = "consumption_matrix"
49
+ C = "C_matrix"
50
+ FULL_BOOTSTRAP_REQUIRED = "full_bootstrap_required"
51
+
52
+
53
+ """
54
+ Implements the extended marking equation as explained in the following paper:
55
+
56
+ van Dongen, Boudewijn F. "Efficiently computing alignments." International Conference on Business Process Management.
57
+ Springer, Cham, 2018.
58
+ https://link.springer.com/chapter/10.1007/978-3-319-98648-7_12
59
+ """
60
+
61
+
62
+ class ExtendedMarkingEquationSolver(object):
63
+ def __init__(
64
+ self,
65
+ trace: Trace,
66
+ sync_net: PetriNet,
67
+ sync_im: Marking,
68
+ sync_fm: Marking,
69
+ parameters: Optional[Dict[Any, Any]] = None,
70
+ ):
71
+ """
72
+ Constructor
73
+
74
+ Parameters
75
+ ---------------
76
+ trace
77
+ Trace
78
+ sync_net
79
+ Synchronous product net
80
+ sync_im
81
+ Initial marking
82
+ sync_fm
83
+ Final marking
84
+ parameters
85
+ Parameters of the algorithm, including:
86
+ - Parameters.CASE_ID_KEY => attribute to use as case identifier
87
+ - Parameters.ACTIVITY_KEY => attribute to use as activity
88
+ - Parameters.COSTS => (if provided) the cost function (otherwise the default cost function is applied)
89
+ - Parameters.SPLIT_IDX => (if provided) the split points as indices of elements of the trace
90
+ (e.g. for ["A", "B", "C", "D", "E"], specifying [1,3] as split points means splitting at "B" and "D").
91
+ If not provided, some split points at uniform distances are found.
92
+ - Parameters.MAX_K_VALUE => the maximum number of split points that is allowed (trim the specified indexes
93
+ if necessary).
94
+ - Parameters.INCIDENCE_MATRIX => (if provided) the incidence matrix associated to the sync product net
95
+ - Parameters.A => (if provided) the A numpy matrix of the incidence matrix
96
+ - Parameters.CONSUMPTION_MATRIX => (if provided) the consumption matrix associated to the sync product net
97
+ - Parameters.C => (if provided) the C numpy matrix of the consumption matrix
98
+ - Parameters.FULL_BOOTSTRAP_REQUIRED => The preset/postset of places/transitions need to be inserted
99
+ """
100
+ if parameters is None:
101
+ parameters = {}
102
+
103
+ activity_key = exec_utils.get_param_value(
104
+ Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY
105
+ )
106
+ max_k_value = exec_utils.get_param_value(
107
+ Parameters.MAX_K_VALUE, parameters, 5
108
+ )
109
+ costs = exec_utils.get_param_value(Parameters.COSTS, parameters, None)
110
+ split_idx = exec_utils.get_param_value(
111
+ Parameters.SPLIT_IDX, parameters, None
112
+ )
113
+ self.full_bootstrap_required = exec_utils.get_param_value(
114
+ Parameters.FULL_BOOTSTRAP_REQUIRED, parameters, True
115
+ )
116
+
117
+ self.trace = [x[activity_key] for x in trace]
118
+ if costs is None:
119
+ costs = align_utils.construct_standard_cost_function(
120
+ sync_net, align_utils.SKIP
121
+ )
122
+ if split_idx is None:
123
+ split_idx = [i for i in range(1, len(trace))]
124
+ self.split_idx = split_idx
125
+ if len(self.split_idx) > max_k_value:
126
+ self.split_idx = points_subset.pick_chosen_points_list(
127
+ max_k_value, self.split_idx
128
+ )
129
+ self.k = len(self.split_idx) if len(self.split_idx) > 1 else 2
130
+ self.sync_net = sync_net
131
+ self.ini = sync_im
132
+ self.fin = sync_fm
133
+ self.costs = costs
134
+ self.incidence_matrix = exec_utils.get_param_value(
135
+ Parameters.INCIDENCE_MATRIX,
136
+ parameters,
137
+ IncidenceMatrix(self.sync_net),
138
+ )
139
+ self.consumption_matrix = exec_utils.get_param_value(
140
+ Parameters.CONSUMPTION_MATRIX,
141
+ parameters,
142
+ ConsumptionMatrix(self.sync_net),
143
+ )
144
+ self.A = exec_utils.get_param_value(
145
+ Parameters.A,
146
+ parameters,
147
+ np.asmatrix(self.incidence_matrix.a_matrix),
148
+ )
149
+ self.C = exec_utils.get_param_value(
150
+ Parameters.C,
151
+ parameters,
152
+ np.asmatrix(self.consumption_matrix.c_matrix),
153
+ )
154
+
155
+ self.__build_entities()
156
+
157
+ def __build_entities(self):
158
+ """
159
+ Builds entities useful to define the marking equation
160
+ """
161
+ self.Aeq = None
162
+ self.__build_encodings()
163
+ if self.full_bootstrap_required:
164
+ petri_utils.decorate_transitions_prepostset(self.sync_net)
165
+ petri_utils.decorate_places_preset_trans(self.sync_net)
166
+
167
+ def __build_encodings(self):
168
+ """
169
+ Encodes the aforementioned objects in Numpy matrixes
170
+ """
171
+ self.zeros = np.zeros((self.A.shape[0], self.A.shape[1]))
172
+ self.ini_vec = np.matrix(
173
+ self.incidence_matrix.encode_marking(self.ini)
174
+ ).transpose()
175
+ self.fin_vec = np.matrix(
176
+ self.incidence_matrix.encode_marking(self.fin)
177
+ ).transpose()
178
+ transitions = self.incidence_matrix.transitions
179
+ self.inv_indices = {y: x for x, y in transitions.items()}
180
+ self.inv_indices = [
181
+ self.inv_indices[i] for i in range(len(self.inv_indices))
182
+ ]
183
+ self.c = self.__build_cost_vector()
184
+ self.__build_variable_corr()
185
+ self.__build_h_value_cost_vector()
186
+ self.c1 = list(self.c)
187
+ self.__build_non_null_entries_y()
188
+
189
+ def __build_cost_vector(self) -> List[int]:
190
+ """
191
+ Builds the complete cost vector of the integer problem
192
+ """
193
+ c1 = [
194
+ self.costs[self.inv_indices[i]]
195
+ for i in range(len(self.inv_indices))
196
+ ] * self.k
197
+ c2 = [
198
+ self.costs[self.inv_indices[i]]
199
+ for i in range(len(self.inv_indices))
200
+ ] * (self.k - 1)
201
+ c3 = [0 for i in range(len(self.inv_indices))] * (self.k - 1)
202
+ c = c1 + c2 + c3
203
+ return c
204
+
205
+ def __build_h_value_cost_vector(self):
206
+ """
207
+ Builds the cost vector for the heuristics calculation as explained in the paper
208
+ """
209
+ self.c0 = list(self.c)
210
+ for idx in self.y[-1]:
211
+ self.c0[idx] = 0
212
+
213
+ def __build_variable_corr(self):
214
+ """
215
+ The variables of the LP are split between both "x", "y" and "xy" (which is the sum of x and y)
216
+
217
+ Make sure we can reconstruct that!
218
+ """
219
+ count = 0
220
+ self.x = []
221
+ for i in range(self.k):
222
+ self.x.append([])
223
+ for j in range(len(self.inv_indices)):
224
+ self.x[-1].append(count)
225
+ count = count + 1
226
+ self.y = []
227
+ for i in range(self.k - 1):
228
+ self.y.append([])
229
+ for j in range(len(self.inv_indices)):
230
+ self.y[-1].append(count)
231
+ count = count + 1
232
+ self.xy = []
233
+ for i in range(self.k - 1):
234
+ self.xy.append([])
235
+ for j in range(len(self.inv_indices)):
236
+ self.xy[-1].append(count)
237
+ count = count + 1
238
+
239
+ def __build_Aeq1(self) -> np.ndarray:
240
+ """
241
+ Builds point (1) of the extended marking equation paper
242
+ """
243
+ Aeq1 = np.hstack(
244
+ [self.A]
245
+ + (2 * self.k - 2) * [self.zeros]
246
+ + (self.k - 1) * [self.A]
247
+ )
248
+ return Aeq1
249
+
250
+ def __build_Aeq2(self) -> np.ndarray:
251
+ """
252
+ We have some variables xy, that are the sum of x and y.
253
+ Just make sure that xy = x + y
254
+ (not implementing any specific point!)
255
+ """
256
+ Aeq_stack = []
257
+ for i in range(1, len(self.x)):
258
+ Aeq = np.zeros((len(self.x[i]), self.xy[-1][-1] + 1))
259
+ for j in range(len(self.x[i])):
260
+ Aeq[j][self.x[i][j]] = 1
261
+ Aeq[j][self.y[i - 1][j]] = 1
262
+ Aeq[j][self.xy[i - 1][j]] = -1
263
+ Aeq_stack.append(Aeq)
264
+ Aeq = np.vstack(Aeq_stack)
265
+ return Aeq
266
+
267
+ def __build_non_null_entries_y(self):
268
+ """
269
+ Utility function that is needed for point (6) of the extended marking equation paper
270
+ """
271
+ self.null_entries = []
272
+ for i in self.split_idx:
273
+ self.null_entries.append([])
274
+ act = self.trace[i]
275
+ for j in range(len(self.inv_indices)):
276
+ if self.inv_indices[j].label[0] == act:
277
+ self.null_entries[-1].append(j)
278
+
279
+ def __build_Aeq3(self) -> np.ndarray:
280
+ """
281
+ Implements point (6) of the extended marking equation paper
282
+ """
283
+ Aeq_stack = []
284
+ for i in range(len(self.y)):
285
+ Aeq = np.zeros((1, self.xy[-1][-1] + 1))
286
+ for j in range(len(self.y[i])):
287
+ Aeq[0][self.y[i][j]] = 1
288
+ Aeq_stack.append(Aeq)
289
+ Aeq = np.vstack(Aeq_stack)
290
+ return Aeq
291
+
292
+ def __build_Aeq4(self) -> np.ndarray:
293
+ """
294
+ Implements point (5) of the extended marking equation paper
295
+ """
296
+ Aeq = np.zeros((len(self.null_entries), self.xy[-1][-1] + 1))
297
+ for i in range(min(len(self.null_entries), len(self.y))):
298
+ for j in range(len(self.y[i])):
299
+ if j not in self.null_entries[i]:
300
+ Aeq[i][self.y[i][j]] = 1
301
+ return Aeq
302
+
303
+ def __build_Aub1(self) -> np.ndarray:
304
+ """
305
+ Implements points (3) and (4) of the extended marking equation paper
306
+ """
307
+ Aub_stack = []
308
+ for i in range(len(self.x)):
309
+ Aub = np.zeros((len(self.x[i]), self.xy[-1][-1] + 1))
310
+ for j in range(len(self.x[i])):
311
+ Aub[j][self.x[i][j]] = -1
312
+ Aub_stack.append(Aub)
313
+ for i in range(len(self.y)):
314
+ Aub = np.zeros((len(self.y[i]), self.xy[-1][-1] + 1))
315
+ for j in range(len(self.y[i])):
316
+ Aub[j][self.y[i][j]] = -1
317
+ Aub_stack.append(Aub)
318
+ Aub = np.vstack(Aub_stack)
319
+ return Aub
320
+
321
+ def __build_Aub2(self) -> np.ndarray:
322
+ """
323
+ Implements point (2) of the extended marking equation paper
324
+ """
325
+ Aub_stack = []
326
+ for i in range(self.k - 1):
327
+ v = [self.A]
328
+ v = v + (self.k - 1) * [self.zeros]
329
+ for j in range(self.k - 1):
330
+ if j == i:
331
+ v = v + [self.C]
332
+ else:
333
+ v = v + [self.zeros]
334
+ for j in range(self.k - 1):
335
+ if j < i:
336
+ v = v + [self.A]
337
+ else:
338
+ v = v + [self.zeros]
339
+ Aub = np.hstack(v)
340
+ Aub_stack.append(Aub)
341
+ Aub = np.vstack(Aub_stack)
342
+ Aub = -Aub
343
+ return Aub
344
+
345
+ def __build_lin_prog_components(self):
346
+ """
347
+ Builds the components needed to solve the marking equation
348
+ """
349
+ Aeq1 = self.__build_Aeq1()
350
+ Aeq2 = self.__build_Aeq2()
351
+ Aeq3 = self.__build_Aeq3()
352
+ Aeq4 = self.__build_Aeq4()
353
+ self.Aeq = np.vstack([Aeq1, Aeq2, Aeq3, Aeq4])
354
+ Aub1 = self.__build_Aub1()
355
+ Aub2 = self.__build_Aub2()
356
+ self.Aub = np.vstack([Aub1, Aub2])
357
+
358
+ if (
359
+ solver.DEFAULT_LP_SOLVER_VARIANT
360
+ == solver.CVXOPT_SOLVER_CUSTOM_ALIGN
361
+ ):
362
+ from cvxopt import matrix
363
+
364
+ self.Aeq_transf = matrix(self.Aeq.astype(np.float64))
365
+ self.Aub_transf = matrix(self.Aub.astype(np.float64))
366
+ self.c = matrix([1.0 * x for x in self.c])
367
+ else:
368
+ self.Aeq_transf = self.Aeq
369
+ self.Aub_transf = self.Aub
370
+
371
+ def __calculate_vectors(self) -> Tuple[np.ndarray, np.ndarray]:
372
+ """
373
+ Calculates the inequality/equality vector from the knowledge of the
374
+ initial/final marking of the synchronous product net
375
+ """
376
+ beq_stack = []
377
+ bub_stack = []
378
+ beq_stack.append(self.fin_vec - self.ini_vec)
379
+ beq_stack.append(np.zeros(((len(self.x) - 1) * len(self.x[0]), 1)))
380
+ beq_stack.append(np.ones((len(self.y), 1)))
381
+ beq_stack.append(np.zeros((len(self.null_entries), 1)))
382
+ bub_stack.append(np.zeros((len(self.x) * len(self.x[0]), 1)))
383
+ bub_stack.append(np.zeros((len(self.y) * len(self.y[0]), 1)))
384
+ for i in range(self.k - 1):
385
+ bub_stack.append(self.ini_vec)
386
+
387
+ beq = np.vstack(beq_stack)
388
+ bub = np.vstack(bub_stack)
389
+
390
+ return beq, bub
391
+
392
+ def get_components(self) -> Tuple[Any, Any, Any, Any, Any]:
393
+ """
394
+ Retrieve the components (Numpy matrixes) of the problem
395
+
396
+ Returns
397
+ ---------------
398
+ c
399
+ objective function
400
+ Aub
401
+ Inequalities matrix
402
+ bub
403
+ Inequalities vector
404
+ Aeq
405
+ Equalities matrix
406
+ beq
407
+ Equalities vector
408
+ """
409
+ if self.Aeq is None:
410
+ self.__build_lin_prog_components()
411
+
412
+ self.beq, self.bub = self.__calculate_vectors()
413
+
414
+ if (
415
+ solver.DEFAULT_LP_SOLVER_VARIANT
416
+ == solver.CVXOPT_SOLVER_CUSTOM_ALIGN
417
+ ):
418
+ from cvxopt import matrix
419
+
420
+ self.beq_transf = matrix(self.beq.astype(np.float64))
421
+ self.bub_transf = matrix(self.bub.astype(np.float64))
422
+ else:
423
+ self.beq_transf = self.beq
424
+ self.bub_transf = self.bub
425
+
426
+ return (
427
+ self.c,
428
+ self.Aub_transf,
429
+ self.bub_transf,
430
+ self.Aeq_transf,
431
+ self.beq_transf,
432
+ )
433
+
434
+ def change_ini_vec(self, ini: Marking):
435
+ """
436
+ Changes the initial marking of the synchronous product net
437
+
438
+ Parameters
439
+ --------------
440
+ ini
441
+ Initial marking
442
+ """
443
+ self.ini = ini
444
+ self.ini_vec = np.matrix(
445
+ self.incidence_matrix.encode_marking(ini)
446
+ ).transpose()
447
+
448
+ def get_x_vector(self, sol_points: List[int]) -> List[int]:
449
+ """
450
+ Returns the x vector of the solution
451
+
452
+ Parameters
453
+ --------------
454
+ sol_points
455
+ Solution of the integer problem
456
+
457
+ Returns
458
+ ---------------
459
+ x
460
+ X vector
461
+ """
462
+ x_vector = [0] * len(self.sync_net.transitions)
463
+ for i in range(len(self.x)):
464
+ for j in range(len(self.x[i])):
465
+ x_vector[j] += sol_points[self.x[i][j]]
466
+ for i in range(len(self.y)):
467
+ for j in range(len(self.y[i])):
468
+ x_vector[j] += sol_points[self.y[i][j]]
469
+ return x_vector
470
+
471
+ def get_h(self, sol_points: List[int]) -> int:
472
+ """
473
+ Returns the value of the heuristics
474
+
475
+ Parameters
476
+ --------------
477
+ sol_points
478
+ Solution of the integer problem
479
+
480
+ Returns
481
+ --------------
482
+ h
483
+ Heuristics value
484
+ """
485
+ h = 0.0
486
+ for i in range(len(sol_points)):
487
+ h += sol_points[i] * self.c1[i]
488
+ return int(h)
489
+
490
+ def get_activated_transitions(
491
+ self, sol_points: List[int]
492
+ ) -> List[PetriNet.Transition]:
493
+ """
494
+ Gets the transitions of the synchronous product net that are non-zero
495
+ in the solution of the marking equation
496
+
497
+ Parameters
498
+ --------------
499
+ sol_points
500
+ Solution of the integer problem
501
+
502
+ Returns
503
+ --------------
504
+ act_trans
505
+ Activated transitions
506
+ """
507
+ act_trans = []
508
+ for i in range(len(sol_points)):
509
+ for j in range(sol_points[i]):
510
+ act_trans.append(self.inv_indices[i])
511
+ return act_trans
512
+
513
+ def solve(self, variant=None) -> Tuple[int, List[int]]:
514
+ """
515
+ Solves the extended marking equation, returning the heuristics and the x vector
516
+
517
+ Parameters
518
+ -------------
519
+ variant
520
+ Variant of the ILP solver to use
521
+
522
+ Returns
523
+ -------------
524
+ h
525
+ Heuristics value
526
+ x
527
+ X vector
528
+ """
529
+ if variant is None:
530
+ variant = solver.DEFAULT_LP_SOLVER_VARIANT
531
+ # use ILP solver
532
+ if variant is solver.CVXOPT_SOLVER_CUSTOM_ALIGN:
533
+ variant = solver.CVXOPT_SOLVER_CUSTOM_ALIGN_ILP
534
+ c, Aub, bub, Aeq, beq = self.get_components()
535
+ parameters_solver = {}
536
+ parameters_solver["use_ilp"] = True
537
+ sol = solver.apply(
538
+ c,
539
+ Aub,
540
+ bub,
541
+ Aeq,
542
+ beq,
543
+ variant=variant,
544
+ parameters=parameters_solver,
545
+ )
546
+ sol_points = solver.get_points_from_sol(sol, variant=variant)
547
+ if sol_points is not None:
548
+ x = self.get_x_vector(sol_points)
549
+ x = [int(y) for y in x]
550
+ h = self.get_h(sol_points)
551
+ return h, x
552
+ return None, None
553
+
554
+ def get_firing_sequence(
555
+ self, x: List[int]
556
+ ) -> Tuple[List[PetriNet.Transition], bool, int]:
557
+ """
558
+ Gets a firing sequence from the X vector
559
+
560
+ Parameters
561
+ ----------------
562
+ x
563
+ X vector
564
+
565
+ Returns
566
+ ----------------
567
+ firing_sequence
568
+ Firing sequence
569
+ reach_fm
570
+ Boolean value that is true whether the firing sequence reaches the final marking
571
+ explained_events
572
+ Number of explaned events by the firing sequence
573
+ """
574
+ activated_transitions = self.get_activated_transitions(x)
575
+ firing_sequence, reach_fm, explained_events = (
576
+ align_utils.search_path_among_sol(
577
+ self.sync_net, self.ini, self.fin, activated_transitions
578
+ )
579
+ )
580
+ return firing_sequence, reach_fm, explained_events
581
+
582
+
583
+ def build(
584
+ trace: Trace,
585
+ sync_net: PetriNet,
586
+ sync_im: Marking,
587
+ sync_fm: Marking,
588
+ parameters: Optional[Dict[Any, Any]] = None,
589
+ ) -> ExtendedMarkingEquationSolver:
590
+ """
591
+ Builds the extended marking equation out of a trace and a synchronous
592
+ product net.
593
+
594
+ Parameters
595
+ ----------
596
+ trace
597
+ Trace
598
+ sync_net
599
+ Synchronous product net
600
+ sync_im
601
+ Initial marking (of sync net)
602
+ sync_fm
603
+ Final marking (of sync net)
604
+ parameters
605
+ Parameters of the algorithm, including:
606
+
607
+ - Parameters.CASE_ID_KEY => attribute to use as case identifier
608
+ - Parameters.ACTIVITY_KEY => attribute to use as activity
609
+ - Parameters.COSTS => (if provided) the cost function (otherwise the default cost function is applied)
610
+ - Parameters.SPLIT_IDX => (if provided) the split points as indices of elements of the trace (e.g. for ["A", "B", "C", "D", "E"], specifying [1,3] as split points means splitting at "B" and "D"). If not provided, some split points at uniform distances are found.
611
+ - Parameters.MAX_K_VALUE => the maximum number of split points that is allowed (trim the specified indexes if necessary).
612
+ - Parameters.INCIDENCE_MATRIX => (if provided) the incidence matrix associated to the sync product net
613
+ - Parameters.A => (if provided) the A numpy matrix of the incidence matrix
614
+ - Parameters.CONSUMPTION_MATRIX => (if provided) the consumption matrix associated to the sync product net
615
+ - Parameters.C => (if provided) the C numpy matrix of the consumption matrix
616
+ - Parameters.FULL_BOOTSTRAP_REQUIRED => The preset/postset of places/transitions need to be inserted
617
+
618
+ """
619
+ if parameters is None:
620
+ parameters = {}
621
+
622
+ return ExtendedMarkingEquationSolver(
623
+ trace, sync_net, sync_im, sync_fm, parameters=parameters
624
+ )
625
+
626
+
627
+ def get_h_value(
628
+ solver: ExtendedMarkingEquationSolver,
629
+ parameters: Optional[Dict[Any, Any]] = None,
630
+ ) -> int:
631
+ """
632
+ Gets the heuristics value from the extended marking equation
633
+
634
+ Parameters
635
+ --------------
636
+ solver
637
+ Extended marking equation solver (class in this file)
638
+ parameters
639
+ Possible parameters of the algorithm
640
+ """
641
+ return solver.solve()[0]