linear-continuous-process-mapper 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/PKG-INFO +37 -3
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/README.md +163 -129
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/__init__.py +2 -1
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/constants.py +7 -0
- linear_continuous_process_mapper-0.2.0/lcm/domain/traces.py +61 -0
- linear_continuous_process_mapper-0.2.0/lcm/graph_builders/abstract_graph_builder.py +58 -0
- linear_continuous_process_mapper-0.2.0/lcm/graph_builders/last_activity_based.py +36 -0
- linear_continuous_process_mapper-0.2.0/lcm/graph_builders/sequence_based.py +32 -0
- linear_continuous_process_mapper-0.2.0/lcm/graph_builders/set_based.py +28 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/services/process_analytics_service.py +46 -4
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/visualization/sankey_visualizer.py +62 -4
- linear_continuous_process_mapper-0.2.0/lcm/visualization/trace_layout.py +296 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/pyproject.toml +3 -3
- linear_continuous_process_mapper-0.2.0/tests/test_lcm.py +647 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/uv.lock +1 -1
- linear_continuous_process_mapper-0.1.0/lcm/graph_builders/abstract_graph_builder.py +0 -18
- linear_continuous_process_mapper-0.1.0/lcm/graph_builders/last_activity_based.py +0 -65
- linear_continuous_process_mapper-0.1.0/lcm/graph_builders/sequence_based.py +0 -62
- linear_continuous_process_mapper-0.1.0/lcm/graph_builders/set_based.py +0 -56
- linear_continuous_process_mapper-0.1.0/tests/test_lcm.py +0 -319
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/.github/workflows/ci.yml +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/.gitignore +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/.python-version +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/LICENSE +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/data/__init__.py +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/data/data_loader.py +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/data/data_processor.py +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/domain/__init__.py +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/domain/graph_analyzer.py +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/graph_builders/__init__.py +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/logger_config.py +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/services/__init__.py +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/services/graph_service.py +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/visualization/__init__.py +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/marimo_app.py +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/programmatic_example.py +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/resources/interface-screenshot-annotated.png +0 -0
- {linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/resources/interface-screenshot.png +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: linear-continuous-process-mapper
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Linear continuous process maps of event logs as Plotly Sankey figures.
|
|
5
|
-
Project-URL: Homepage, https://github.com/
|
|
6
|
-
Project-URL: Repository, https://github.com/
|
|
5
|
+
Project-URL: Homepage, https://github.com/alvarobernal2412/lc-maps
|
|
6
|
+
Project-URL: Repository, https://github.com/alvarobernal2412/lc-maps
|
|
7
7
|
Author: ICS University St. Gallen
|
|
8
8
|
License-Expression: MIT
|
|
9
9
|
License-File: LICENSE
|
|
@@ -122,6 +122,40 @@ last_activity_map
|
|
|
122
122
|
|
|
123
123
|
Display the figure directly. Wrapping it in `mo.ui.plotly()` leaves a blank plot, because that wrapper does not support Sankey traces.
|
|
124
124
|
|
|
125
|
+
## Traces and layout
|
|
126
|
+
|
|
127
|
+
A trace is a distinct sequence of activities, with the number of cases that follow it. `generate` lists the traces of the map, the most frequent first (ties: the longer one, then by sequence), at most 500:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
figure, metadata = lcm_service.generate(map_type="sequence_based", layout="traces")
|
|
131
|
+
|
|
132
|
+
metadata["traces"] # [{"name", "sequence", "cases", "links", "nodes"}, ...]
|
|
133
|
+
metadata["traces_truncated"] # True when there were more than 500 traces
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
- `name` is the activities joined with ` → `; the empty trace is `EMPTY TRACE`. If two different sequences would get the same name (only possible when an activity holds ` → ` itself), the later one gets ` (2)`, ` (3)` and so on. `sequence` is the list of activities and is the reliable way to identify a trace.
|
|
137
|
+
- `links` are the links the trace uses, in order, and `nodes` the nodes it passes, starting with the root. Both are numbered as the figure numbers its own links and nodes (their position in `link.source` and `node.label`). A step that is not drawn (a repeated activity with `allow_loops=False`) has no link.
|
|
138
|
+
|
|
139
|
+
`generate(trace_limit=500)` sets how many of the most frequent traces are stored. Every stored trace adds to the size of the figure (500 traces of a map of 20,000 cases added about 670 KB), so lower it, or use `0` to store none (the layout then falls back to `"auto"`), when figures are kept or sent around; a negative value raises a `ValueError`.
|
|
140
|
+
|
|
141
|
+
The list is plain data (it can go through `json.dumps`) and the figure carries the same one in `figure.data[0].meta`:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
figure.data[0].meta["lcm"]
|
|
145
|
+
# {"traces": [...], "truncated": bool, "layout": "auto" or "traces"}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`layout` is `"auto"` (Plotly places the nodes) or `"traces"`. With `"traces"` the nodes of the most frequent trace share the top edge of the root, so the trace is a straight band from the root. The other traces are stacked below it, row by row, and the nodes get fixed positions (`node.x`, `node.y`, `arrangement="freeform"` (the nodes stay where they are put and can still be dragged), `pad` of 10 px). Any other value raises a `ValueError`. Traces that were cut at 500 are not laid out as rows; their nodes are placed below the others. A column that does not fit below the common top starts higher, as far as it has to.
|
|
149
|
+
|
|
150
|
+
The positions depend on the size of the plot area. After changing the height or the margins of the figure, call `lcm.relayout` to place the nodes again:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
figure.update_layout(height=900, margin=dict(l=110, r=10, t=100, b=140))
|
|
154
|
+
lcm.relayout(figure)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
It returns the figure. A figure drawn with `layout="auto"` stays as it is. Plotly sizes the nodes of a map with loops or cycles by its own rules, which `relayout` follows only approximately, so the top edges can differ by a few pixels there.
|
|
158
|
+
|
|
125
159
|
## Project Structure
|
|
126
160
|
|
|
127
161
|
|
|
@@ -1,129 +1,163 @@
|
|
|
1
|
-
# LCM Marimo
|
|
2
|
-
|
|
3
|
-
# Linear Continuous Process Mapper
|
|
4
|
-
|
|
5
|
-
A prototypical implementation of linear and continuous process maps for the exploratory analysis of sequential behavior in event logs. This Python application builds upon interactive Sankey diagrams to provide effective visualizations of process behavior. The system loads event logs, constructs process maps using different abstractions (such as sequence-based, set-based, and last-activity-based), and visualizes them to display relevant insights in a precise yet interpretable way.
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-

|
|
9
|
-
UI of the application. Users choose an event log from the `logs/` folder via the event log selector (H), and can either analyze it as-is or apply further transformations by editing the marimo notebook. The UI supports folding activities (A) and activity selection (B). Furthermore, users can select from the three generic LCMs: sequence-, set-, or last-activity abstraction (C) and choose whether to visualize self-loops and empty traces (D). After selecting the desired visualization controls, they can refresh the visualization (E), which refreshes the Sankey diagram (F). Here, they can freely reposition nodes to adjust the visualization to their needs. More details about edges and nodes are revealed on hover (G). The current settings are also available as a `generate` call to copy into a notebook cell (I).
|
|
10
|
-
|
|
11
|
-
## How to Run
|
|
12
|
-
|
|
13
|
-
This is the marimo version of the LCPM.
|
|
14
|
-
|
|
15
|
-
To get started:
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
uv sync
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Then to run:
|
|
22
|
-
```
|
|
23
|
-
uv run marimo run marimo_app.py
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Or to edit;
|
|
27
|
-
```
|
|
28
|
-
uv run marimo edit marimo_app.py
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### Event logs
|
|
32
|
-
|
|
33
|
-
Put event logs in the `logs/` folder and choose one from the **Event log** dropdown at the top of the app. Both `.xes` and `.csv` files are supported. A CSV needs these columns:
|
|
34
|
-
|
|
35
|
-
- `case:concept:name`: case ID
|
|
36
|
-
- `concept:name`: activity
|
|
37
|
-
- `time:timestamp`: timestamp
|
|
38
|
-
|
|
39
|
-
The included `logs/log.csv` is a preprocessed subset of **BPI Challenge 2020:
|
|
40
|
-
Domestic Declarations** by Boudewijn van Dongen (2020), Version 1,
|
|
41
|
-
4TU.ResearchData.
|
|
42
|
-
Source: https://doi.org/10.4121/uuid:3f422315-ed9d-4882-891f-e180b5b4feb5
|
|
43
|
-
|
|
44
|
-
The subset contains 8,260 cases and 46,375 events; all included cases start
|
|
45
|
-
in 2018. It was converted from `DomesticDeclarations2H.xes` to CSV, retaining
|
|
46
|
-
only case ID, activity, and timestamp, with timestamps expressed in UTC.
|
|
47
|
-
|
|
48
|
-
This dataset is licensed under
|
|
49
|
-
[Creative Commons Attribution–NonCommercial 4.0 International (CC BY-NC 4.0)](https://creativecommons.org/licenses/by-nc/4.0/).
|
|
50
|
-
Its reuse and redistribution are subject to that license, including its
|
|
51
|
-
attribution and noncommercial-use conditions. The repository’s MIT license
|
|
52
|
-
applies to the code, not to this dataset.
|
|
53
|
-
|
|
54
|
-
## Install
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
pip install linear-continuous-process-mapper
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
This installs the `lcm` library only. The interactive notebook needs the extra: `pip install "linear-continuous-process-mapper[notebook]"`.
|
|
61
|
-
|
|
62
|
-
## Programmatic Use
|
|
63
|
-
|
|
64
|
-
The widgets in `marimo_app.py` are one way to call the `lcm` library. The same maps can be drawn from code, without any widgets. To fix a state you found interactively, copy the call from **Reproduce this map in code** below the map.
|
|
65
|
-
|
|
66
|
-
`programmatic_example.py` is a worked analysis of the included log in this style. It compares map types, folds activities, measures what each activity adds to a map, and transforms the log before mapping it. It has no widgets and is meant to be read with its code visible, so open it in edit mode:
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
uv run marimo edit programmatic_example.py
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
```python
|
|
73
|
-
import lcm
|
|
74
|
-
|
|
75
|
-
lcm_service = lcm.get_service(lcm.load_event_log("logs/log.csv"))
|
|
76
|
-
|
|
77
|
-
figure, metadata = lcm_service.generate(
|
|
78
|
-
activities=None, # None keeps all of them; folded ones go by their fold name
|
|
79
|
-
map_type=lcm.MapType.SEQUENCE_BASED, # or "sequence_based"
|
|
80
|
-
allow_loops=True, # has no effect on sequence-based maps
|
|
81
|
-
visualize_empty_cases=True,
|
|
82
|
-
folds={"Rejections": ["Declaration REJECTED by ADMINISTRATION", "Declaration REJECTED by SUPERVISOR"]},
|
|
83
|
-
)
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
All arguments are optional and invalid choices raise a `ValueError`. `figure` is a Plotly figure and `metadata` is a dict of counts. `generate` starts from the full log on every call, so one service can draw many maps. In a marimo notebook, every cell needs its own variable names:
|
|
87
|
-
|
|
88
|
-
```python
|
|
89
|
-
# One cell
|
|
90
|
-
set_map, set_metadata = lcm_service.generate(map_type="set_based")
|
|
91
|
-
set_map
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
```python
|
|
95
|
-
# Another cell
|
|
96
|
-
last_activity_map, last_activity_metadata = lcm_service.generate(map_type="last_activity_based")
|
|
97
|
-
last_activity_map
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Display the figure directly. Wrapping it in `mo.ui.plotly()` leaves a blank plot, because that wrapper does not support Sankey traces.
|
|
101
|
-
|
|
102
|
-
##
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
1
|
+
# LCM Marimo
|
|
2
|
+
|
|
3
|
+
# Linear Continuous Process Mapper
|
|
4
|
+
|
|
5
|
+
A prototypical implementation of linear and continuous process maps for the exploratory analysis of sequential behavior in event logs. This Python application builds upon interactive Sankey diagrams to provide effective visualizations of process behavior. The system loads event logs, constructs process maps using different abstractions (such as sequence-based, set-based, and last-activity-based), and visualizes them to display relevant insights in a precise yet interpretable way.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+

|
|
9
|
+
UI of the application. Users choose an event log from the `logs/` folder via the event log selector (H), and can either analyze it as-is or apply further transformations by editing the marimo notebook. The UI supports folding activities (A) and activity selection (B). Furthermore, users can select from the three generic LCMs: sequence-, set-, or last-activity abstraction (C) and choose whether to visualize self-loops and empty traces (D). After selecting the desired visualization controls, they can refresh the visualization (E), which refreshes the Sankey diagram (F). Here, they can freely reposition nodes to adjust the visualization to their needs. More details about edges and nodes are revealed on hover (G). The current settings are also available as a `generate` call to copy into a notebook cell (I).
|
|
10
|
+
|
|
11
|
+
## How to Run
|
|
12
|
+
|
|
13
|
+
This is the marimo version of the LCPM.
|
|
14
|
+
|
|
15
|
+
To get started:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
uv sync
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then to run:
|
|
22
|
+
```
|
|
23
|
+
uv run marimo run marimo_app.py
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or to edit;
|
|
27
|
+
```
|
|
28
|
+
uv run marimo edit marimo_app.py
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Event logs
|
|
32
|
+
|
|
33
|
+
Put event logs in the `logs/` folder and choose one from the **Event log** dropdown at the top of the app. Both `.xes` and `.csv` files are supported. A CSV needs these columns:
|
|
34
|
+
|
|
35
|
+
- `case:concept:name`: case ID
|
|
36
|
+
- `concept:name`: activity
|
|
37
|
+
- `time:timestamp`: timestamp
|
|
38
|
+
|
|
39
|
+
The included `logs/log.csv` is a preprocessed subset of **BPI Challenge 2020:
|
|
40
|
+
Domestic Declarations** by Boudewijn van Dongen (2020), Version 1,
|
|
41
|
+
4TU.ResearchData.
|
|
42
|
+
Source: https://doi.org/10.4121/uuid:3f422315-ed9d-4882-891f-e180b5b4feb5
|
|
43
|
+
|
|
44
|
+
The subset contains 8,260 cases and 46,375 events; all included cases start
|
|
45
|
+
in 2018. It was converted from `DomesticDeclarations2H.xes` to CSV, retaining
|
|
46
|
+
only case ID, activity, and timestamp, with timestamps expressed in UTC.
|
|
47
|
+
|
|
48
|
+
This dataset is licensed under
|
|
49
|
+
[Creative Commons Attribution–NonCommercial 4.0 International (CC BY-NC 4.0)](https://creativecommons.org/licenses/by-nc/4.0/).
|
|
50
|
+
Its reuse and redistribution are subject to that license, including its
|
|
51
|
+
attribution and noncommercial-use conditions. The repository’s MIT license
|
|
52
|
+
applies to the code, not to this dataset.
|
|
53
|
+
|
|
54
|
+
## Install
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
pip install linear-continuous-process-mapper
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
This installs the `lcm` library only. The interactive notebook needs the extra: `pip install "linear-continuous-process-mapper[notebook]"`.
|
|
61
|
+
|
|
62
|
+
## Programmatic Use
|
|
63
|
+
|
|
64
|
+
The widgets in `marimo_app.py` are one way to call the `lcm` library. The same maps can be drawn from code, without any widgets. To fix a state you found interactively, copy the call from **Reproduce this map in code** below the map.
|
|
65
|
+
|
|
66
|
+
`programmatic_example.py` is a worked analysis of the included log in this style. It compares map types, folds activities, measures what each activity adds to a map, and transforms the log before mapping it. It has no widgets and is meant to be read with its code visible, so open it in edit mode:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
uv run marimo edit programmatic_example.py
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import lcm
|
|
74
|
+
|
|
75
|
+
lcm_service = lcm.get_service(lcm.load_event_log("logs/log.csv"))
|
|
76
|
+
|
|
77
|
+
figure, metadata = lcm_service.generate(
|
|
78
|
+
activities=None, # None keeps all of them; folded ones go by their fold name
|
|
79
|
+
map_type=lcm.MapType.SEQUENCE_BASED, # or "sequence_based"
|
|
80
|
+
allow_loops=True, # has no effect on sequence-based maps
|
|
81
|
+
visualize_empty_cases=True,
|
|
82
|
+
folds={"Rejections": ["Declaration REJECTED by ADMINISTRATION", "Declaration REJECTED by SUPERVISOR"]},
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
All arguments are optional and invalid choices raise a `ValueError`. `figure` is a Plotly figure and `metadata` is a dict of counts. `generate` starts from the full log on every call, so one service can draw many maps. In a marimo notebook, every cell needs its own variable names:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
# One cell
|
|
90
|
+
set_map, set_metadata = lcm_service.generate(map_type="set_based")
|
|
91
|
+
set_map
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# Another cell
|
|
96
|
+
last_activity_map, last_activity_metadata = lcm_service.generate(map_type="last_activity_based")
|
|
97
|
+
last_activity_map
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Display the figure directly. Wrapping it in `mo.ui.plotly()` leaves a blank plot, because that wrapper does not support Sankey traces.
|
|
101
|
+
|
|
102
|
+
## Traces and layout
|
|
103
|
+
|
|
104
|
+
A trace is a distinct sequence of activities, with the number of cases that follow it. `generate` lists the traces of the map, the most frequent first (ties: the longer one, then by sequence), at most 500:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
figure, metadata = lcm_service.generate(map_type="sequence_based", layout="traces")
|
|
108
|
+
|
|
109
|
+
metadata["traces"] # [{"name", "sequence", "cases", "links", "nodes"}, ...]
|
|
110
|
+
metadata["traces_truncated"] # True when there were more than 500 traces
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
- `name` is the activities joined with ` → `; the empty trace is `EMPTY TRACE`. If two different sequences would get the same name (only possible when an activity holds ` → ` itself), the later one gets ` (2)`, ` (3)` and so on. `sequence` is the list of activities and is the reliable way to identify a trace.
|
|
114
|
+
- `links` are the links the trace uses, in order, and `nodes` the nodes it passes, starting with the root. Both are numbered as the figure numbers its own links and nodes (their position in `link.source` and `node.label`). A step that is not drawn (a repeated activity with `allow_loops=False`) has no link.
|
|
115
|
+
|
|
116
|
+
`generate(trace_limit=500)` sets how many of the most frequent traces are stored. Every stored trace adds to the size of the figure (500 traces of a map of 20,000 cases added about 670 KB), so lower it, or use `0` to store none (the layout then falls back to `"auto"`), when figures are kept or sent around; a negative value raises a `ValueError`.
|
|
117
|
+
|
|
118
|
+
The list is plain data (it can go through `json.dumps`) and the figure carries the same one in `figure.data[0].meta`:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
figure.data[0].meta["lcm"]
|
|
122
|
+
# {"traces": [...], "truncated": bool, "layout": "auto" or "traces"}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`layout` is `"auto"` (Plotly places the nodes) or `"traces"`. With `"traces"` the nodes of the most frequent trace share the top edge of the root, so the trace is a straight band from the root. The other traces are stacked below it, row by row, and the nodes get fixed positions (`node.x`, `node.y`, `arrangement="freeform"` (the nodes stay where they are put and can still be dragged), `pad` of 10 px). Any other value raises a `ValueError`. Traces that were cut at 500 are not laid out as rows; their nodes are placed below the others. A column that does not fit below the common top starts higher, as far as it has to.
|
|
126
|
+
|
|
127
|
+
The positions depend on the size of the plot area. After changing the height or the margins of the figure, call `lcm.relayout` to place the nodes again:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
figure.update_layout(height=900, margin=dict(l=110, r=10, t=100, b=140))
|
|
131
|
+
lcm.relayout(figure)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
It returns the figure. A figure drawn with `layout="auto"` stays as it is. Plotly sizes the nodes of a map with loops or cycles by its own rules, which `relayout` follows only approximately, so the top edges can differ by a few pixels there.
|
|
135
|
+
|
|
136
|
+
## Project Structure
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
**marimo_app.py** - The main entry point for running the application, via a marimo notebook. It is also the example of
|
|
140
|
+
interactive use of the library.
|
|
141
|
+
|
|
142
|
+
**programmatic_example.py** - An example analysis that uses the library from code, without widgets.
|
|
143
|
+
|
|
144
|
+
**lcm** - The library, independent of marimo. `lcm/__init__.py` wires together all components (data processors, graph
|
|
145
|
+
builders, analyzers) in `get_service`. It contains the main analytical components:
|
|
146
|
+
|
|
147
|
+
- **data** - Event log data handling using PM4Py. Loads XES and CSV files, orders each case's events by timestamp,
|
|
148
|
+
applies folds, filters by activities, and creates the variants for analysis
|
|
149
|
+
- **domain** - Graph analysis algorithms that enrich process graphs with business metrics including flow analysis,
|
|
150
|
+
leakage detection, termination ratios, and node balancing
|
|
151
|
+
- **graph_builders** - Multiple strategies for constructing process graphs from event data: set-based prefix graphs,
|
|
152
|
+
sequence-based prefix trees, and last-activity-based graphs with configurable loop handling
|
|
153
|
+
- **services** - High-level orchestration services that coordinate graph construction and the complete analytics
|
|
154
|
+
pipeline from raw data to visualizations
|
|
155
|
+
- **visualization** - Interactive Sankey diagram generator using Plotly that converts enriched process graphs into
|
|
156
|
+
color-coded flow visualizations with hover details and activity legends
|
|
157
|
+
|
|
158
|
+
**tests** - Tests of the library. Run them with `uv run pytest`.
|
|
159
|
+
|
|
160
|
+
## Repository Authors
|
|
161
|
+
- [@moritzfaes](https://github.com/moritzfaes)
|
|
162
|
+
- [@hvoelzer](https://github.com/hvoelzer)
|
|
163
|
+
- [@aaronkurz](https://github.com/aaronkurz)
|
{linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/__init__.py
RENAMED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import pandas as pd
|
|
8
8
|
|
|
9
|
-
from lcm.constants import MapType
|
|
9
|
+
from lcm.constants import Layout, MapType
|
|
10
10
|
from lcm.data.data_loader import LOG_SUFFIXES, load_event_log
|
|
11
11
|
from lcm.data.data_processor import DataProcessor
|
|
12
12
|
from lcm.domain.graph_analyzer import GraphAnalyzer
|
|
@@ -17,6 +17,7 @@ from lcm.graph_builders import (
|
|
|
17
17
|
)
|
|
18
18
|
from lcm.services.graph_service import GraphService
|
|
19
19
|
from lcm.services.process_analytics_service import ProcessAnalyticsService
|
|
20
|
+
from lcm.visualization.trace_layout import relayout
|
|
20
21
|
|
|
21
22
|
__all__ = [
|
|
22
23
|
"LOG_SUFFIXES",
|
{linear_continuous_process_mapper-0.1.0 → linear_continuous_process_mapper-0.2.0}/lcm/constants.py
RENAMED
|
@@ -11,3 +11,10 @@ class MapType(StrEnum):
|
|
|
11
11
|
SET_BASED = "set_based"
|
|
12
12
|
SEQUENCE_BASED = "sequence_based"
|
|
13
13
|
LAST_ACTIVITY_BASED = "last_activity_based"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Layout(StrEnum):
|
|
17
|
+
# Plotly places the nodes.
|
|
18
|
+
AUTO = "auto"
|
|
19
|
+
# The most frequent trace runs straight along the root's row.
|
|
20
|
+
TRACES = "traces"
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from collections import Counter
|
|
2
|
+
from typing import Dict, List, Tuple
|
|
3
|
+
|
|
4
|
+
from lcm.graph_builders import AbstractGraphBuilder
|
|
5
|
+
|
|
6
|
+
SEPARATOR = " → "
|
|
7
|
+
# The most traces a map keeps; the rest are counted as truncated.
|
|
8
|
+
TRACE_LIMIT = 500
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def find_traces(
|
|
12
|
+
variants: List[List[str]],
|
|
13
|
+
builder: AbstractGraphBuilder,
|
|
14
|
+
allow_loops: bool,
|
|
15
|
+
limit: int = TRACE_LIMIT,
|
|
16
|
+
) -> Tuple[List[dict], bool]:
|
|
17
|
+
"""List the distinct variants, the most frequent first.
|
|
18
|
+
|
|
19
|
+
Traces with as many cases come longest first, then in sequence order.
|
|
20
|
+
|
|
21
|
+
A trace is named by its activities joined with " → ". Two different
|
|
22
|
+
sequences can only get the same name when an activity holds the arrow
|
|
23
|
+
itself; the later one then gets " (2)", " (3)" and so on, so use `sequence`
|
|
24
|
+
to identify a trace, not the name.
|
|
25
|
+
|
|
26
|
+
Each trace has its `name`, its `sequence` of activities, the number of
|
|
27
|
+
`cases` that follow it, the `root` state and the `steps` it takes in the map `builder` draws.
|
|
28
|
+
The second value is True when more than `limit` traces exist and the rarest
|
|
29
|
+
were cut.
|
|
30
|
+
"""
|
|
31
|
+
counts = Counter(tuple(variant) for variant in variants)
|
|
32
|
+
ordered = sorted(counts.items(), key=lambda item: (-item[1], -len(item[0]), item[0]))
|
|
33
|
+
truncated = len(ordered) > limit
|
|
34
|
+
kept = ordered[:limit]
|
|
35
|
+
|
|
36
|
+
names = _unique_names([sequence for sequence, _ in kept])
|
|
37
|
+
traces = [
|
|
38
|
+
{
|
|
39
|
+
"name": name,
|
|
40
|
+
"sequence": list(sequence),
|
|
41
|
+
"cases": cases,
|
|
42
|
+
"root": builder.root(),
|
|
43
|
+
"steps": builder.walk(list(sequence), allow_loops),
|
|
44
|
+
}
|
|
45
|
+
for name, (sequence, cases) in zip(names, kept)
|
|
46
|
+
]
|
|
47
|
+
return traces, truncated
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _unique_names(sequences: List[Tuple[str, ...]]) -> List[str]:
|
|
51
|
+
"""Join each sequence with arrows; a repeated name gets a number."""
|
|
52
|
+
names, used = [], set()
|
|
53
|
+
for sequence in sequences:
|
|
54
|
+
name = SEPARATOR.join(sequence)
|
|
55
|
+
base, number = name, 1
|
|
56
|
+
while name in used:
|
|
57
|
+
number += 1
|
|
58
|
+
name = f"{base} ({number})"
|
|
59
|
+
used.add(name)
|
|
60
|
+
names.append(name)
|
|
61
|
+
return names
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import networkx as nx
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
from collections import defaultdict
|
|
4
|
+
from typing import Any, Dict, Hashable, List, Tuple
|
|
5
|
+
|
|
6
|
+
Step = Tuple[Hashable, Hashable, str]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AbstractGraphBuilder(ABC):
|
|
10
|
+
"""Abstract base class for all graph builder"""
|
|
11
|
+
|
|
12
|
+
# Draw the root node even when there are no cases.
|
|
13
|
+
ROOT_ALWAYS = False
|
|
14
|
+
|
|
15
|
+
@abstractmethod
|
|
16
|
+
def root(self) -> Hashable:
|
|
17
|
+
"""The state every case starts in."""
|
|
18
|
+
|
|
19
|
+
@abstractmethod
|
|
20
|
+
def walk(self, variant: List[str], allow_loops: bool) -> List[Step]:
|
|
21
|
+
"""Return the (from_state, to_state, activity) steps one variant takes.
|
|
22
|
+
|
|
23
|
+
The states are the node keys of the graph `build` returns. A step that
|
|
24
|
+
`build` does not draw (the state is unchanged and loops are hidden) is
|
|
25
|
+
left out.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
@abstractmethod
|
|
29
|
+
def node_attributes(self, state: Hashable) -> Dict[str, Any]:
|
|
30
|
+
"""The attributes of the node of `state`, without its weight."""
|
|
31
|
+
|
|
32
|
+
def build(
|
|
33
|
+
self, variants: List[List[str]], allow_loops: bool = True
|
|
34
|
+
) -> nx.MultiDiGraph:
|
|
35
|
+
"""Draw every step of every variant into one graph."""
|
|
36
|
+
root = self.root()
|
|
37
|
+
state_counts = defaultdict(int)
|
|
38
|
+
edge_counts = defaultdict(int)
|
|
39
|
+
if self.ROOT_ALWAYS:
|
|
40
|
+
state_counts[root] = 0
|
|
41
|
+
|
|
42
|
+
for variant in variants:
|
|
43
|
+
state_counts[root] += 1
|
|
44
|
+
for from_state, to_state, activity in self.walk(variant, allow_loops):
|
|
45
|
+
state_counts[to_state] += 1
|
|
46
|
+
edge_counts[(from_state, to_state, activity)] += 1
|
|
47
|
+
|
|
48
|
+
G = nx.MultiDiGraph()
|
|
49
|
+
for state, count in state_counts.items():
|
|
50
|
+
G.add_node(state, weight=count, **self.node_attributes(state))
|
|
51
|
+
for (from_state, to_state, activity), count in edge_counts.items():
|
|
52
|
+
G.add_edge(from_state, to_state, weight=count, activity=activity)
|
|
53
|
+
return G
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
@abstractmethod
|
|
57
|
+
def name(self) -> str:
|
|
58
|
+
"""User friendly name for the builder strategy"""
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from typing import Any, Dict, List
|
|
2
|
+
|
|
3
|
+
from .abstract_graph_builder import AbstractGraphBuilder, Step
|
|
4
|
+
|
|
5
|
+
START_NODE = "START"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LastActivityBasedGraphBuilder(AbstractGraphBuilder):
|
|
9
|
+
"""
|
|
10
|
+
Build a graph where each node is the last activity executed in the prefix.
|
|
11
|
+
Edges represent direct transitions between last activities. The START node
|
|
12
|
+
weighs the total number of cases.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
ROOT_ALWAYS = True
|
|
16
|
+
|
|
17
|
+
@property
|
|
18
|
+
def name(self) -> str:
|
|
19
|
+
return "Last-Activity-Based Graph"
|
|
20
|
+
|
|
21
|
+
def root(self) -> str:
|
|
22
|
+
return START_NODE
|
|
23
|
+
|
|
24
|
+
def walk(self, variant: List[str], allow_loops: bool) -> List[Step]:
|
|
25
|
+
steps = []
|
|
26
|
+
previous = START_NODE
|
|
27
|
+
for activity in variant:
|
|
28
|
+
if previous != activity or allow_loops:
|
|
29
|
+
steps.append((previous, activity, activity))
|
|
30
|
+
previous = activity
|
|
31
|
+
return steps
|
|
32
|
+
|
|
33
|
+
def node_attributes(self, state: str) -> Dict[str, Any]:
|
|
34
|
+
if state == START_NODE:
|
|
35
|
+
return {"label": "START", "last_activity": None}
|
|
36
|
+
return {"label": state, "last_activity": state}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from typing import Any, Dict, List, Tuple
|
|
2
|
+
|
|
3
|
+
from .abstract_graph_builder import AbstractGraphBuilder, Step
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SequenceBasedPrefixTreeBuilder(AbstractGraphBuilder):
|
|
7
|
+
"""
|
|
8
|
+
Build a prefix tree where each node is a unique sequence (tuple) of activities.
|
|
9
|
+
No merging: A->B->C is different from B->A->C.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
@property
|
|
13
|
+
def name(self) -> str:
|
|
14
|
+
return "Sequence-Based Prefix Tree"
|
|
15
|
+
|
|
16
|
+
def root(self) -> Tuple[str, ...]:
|
|
17
|
+
return tuple() # empty prefix
|
|
18
|
+
|
|
19
|
+
def walk(self, variant: List[str], allow_loops: bool) -> List[Step]:
|
|
20
|
+
# Every prefix is a new state, so no step is ever hidden.
|
|
21
|
+
return [
|
|
22
|
+
(tuple(variant[:i]), tuple(variant[: i + 1]), activity)
|
|
23
|
+
for i, activity in enumerate(variant)
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
def node_attributes(self, state: Tuple[str, ...]) -> Dict[str, Any]:
|
|
27
|
+
# Label: START for empty, otherwise "A → B → C"
|
|
28
|
+
return {
|
|
29
|
+
"label": "START" if len(state) == 0 else " → ".join(state),
|
|
30
|
+
"sequence_length": len(state),
|
|
31
|
+
"activities": list(state),
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from typing import Any, Dict, FrozenSet, List
|
|
2
|
+
|
|
3
|
+
from .abstract_graph_builder import AbstractGraphBuilder, Step
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SetBasedPrefixGraphBuilder(AbstractGraphBuilder):
|
|
7
|
+
"""Build a prefix graph where each node is the set of activities done so far."""
|
|
8
|
+
|
|
9
|
+
@property
|
|
10
|
+
def name(self) -> str:
|
|
11
|
+
return "Set-Based Prefix Graph"
|
|
12
|
+
|
|
13
|
+
def root(self) -> FrozenSet[str]:
|
|
14
|
+
return frozenset()
|
|
15
|
+
|
|
16
|
+
def walk(self, variant: List[str], allow_loops: bool) -> List[Step]:
|
|
17
|
+
steps = []
|
|
18
|
+
current_state = frozenset()
|
|
19
|
+
for i, activity in enumerate(variant):
|
|
20
|
+
new_state = frozenset(variant[: i + 1])
|
|
21
|
+
if current_state != new_state or allow_loops:
|
|
22
|
+
steps.append((current_state, new_state, activity))
|
|
23
|
+
current_state = new_state
|
|
24
|
+
return steps
|
|
25
|
+
|
|
26
|
+
def node_attributes(self, state: FrozenSet[str]) -> Dict[str, Any]:
|
|
27
|
+
label = "START" if not state else "{" + ", ".join(sorted(state)) + "}"
|
|
28
|
+
return {"label": label, "activities_completed": len(state)}
|