linear-continuous-process-mapper 0.1.0__py3-none-any.whl
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.
- lcm/__init__.py +44 -0
- lcm/constants.py +13 -0
- lcm/data/__init__.py +0 -0
- lcm/data/data_loader.py +49 -0
- lcm/data/data_processor.py +52 -0
- lcm/domain/__init__.py +0 -0
- lcm/domain/graph_analyzer.py +43 -0
- lcm/graph_builders/__init__.py +4 -0
- lcm/graph_builders/abstract_graph_builder.py +18 -0
- lcm/graph_builders/last_activity_based.py +65 -0
- lcm/graph_builders/sequence_based.py +62 -0
- lcm/graph_builders/set_based.py +56 -0
- lcm/logger_config.py +22 -0
- lcm/services/__init__.py +0 -0
- lcm/services/graph_service.py +19 -0
- lcm/services/process_analytics_service.py +132 -0
- lcm/visualization/__init__.py +0 -0
- lcm/visualization/sankey_visualizer.py +175 -0
- linear_continuous_process_mapper-0.1.0.dist-info/METADATA +152 -0
- linear_continuous_process_mapper-0.1.0.dist-info/RECORD +22 -0
- linear_continuous_process_mapper-0.1.0.dist-info/WHEEL +4 -0
- linear_continuous_process_mapper-0.1.0.dist-info/licenses/LICENSE +21 -0
lcm/__init__.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Linear continuous process maps as Plotly Sankey figures.
|
|
2
|
+
|
|
3
|
+
lcm_service = lcm.get_service(lcm.load_event_log("logs/log.csv"))
|
|
4
|
+
figure, metadata = lcm_service.generate(map_type="sequence_based")
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import pandas as pd
|
|
8
|
+
|
|
9
|
+
from lcm.constants import MapType
|
|
10
|
+
from lcm.data.data_loader import LOG_SUFFIXES, load_event_log
|
|
11
|
+
from lcm.data.data_processor import DataProcessor
|
|
12
|
+
from lcm.domain.graph_analyzer import GraphAnalyzer
|
|
13
|
+
from lcm.graph_builders import (
|
|
14
|
+
LastActivityBasedGraphBuilder,
|
|
15
|
+
SequenceBasedPrefixTreeBuilder,
|
|
16
|
+
SetBasedPrefixGraphBuilder,
|
|
17
|
+
)
|
|
18
|
+
from lcm.services.graph_service import GraphService
|
|
19
|
+
from lcm.services.process_analytics_service import ProcessAnalyticsService
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"LOG_SUFFIXES",
|
|
23
|
+
"MapType",
|
|
24
|
+
"ProcessAnalyticsService",
|
|
25
|
+
"get_service",
|
|
26
|
+
"load_event_log",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_service(event_log: pd.DataFrame) -> ProcessAnalyticsService:
|
|
31
|
+
"""Create a service for `event_log`; `generate` then draws maps from it."""
|
|
32
|
+
graph_service = GraphService(
|
|
33
|
+
{
|
|
34
|
+
MapType.SET_BASED: SetBasedPrefixGraphBuilder(),
|
|
35
|
+
MapType.SEQUENCE_BASED: SequenceBasedPrefixTreeBuilder(),
|
|
36
|
+
MapType.LAST_ACTIVITY_BASED: LastActivityBasedGraphBuilder(),
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
return ProcessAnalyticsService(
|
|
40
|
+
event_log=event_log,
|
|
41
|
+
data_processor=DataProcessor(),
|
|
42
|
+
graph_service=graph_service,
|
|
43
|
+
graph_analyzer=GraphAnalyzer(),
|
|
44
|
+
)
|
lcm/constants.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
|
|
3
|
+
CASE_ID_COL = "case:concept:name"
|
|
4
|
+
ACTIVITY_COL = "concept:name"
|
|
5
|
+
TIMESTAMP_COL = "time:timestamp"
|
|
6
|
+
# Stands in for the activities of a case that has none of the selected ones.
|
|
7
|
+
EMPTY_TRACE = "EMPTY TRACE"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MapType(StrEnum):
|
|
11
|
+
SET_BASED = "set_based"
|
|
12
|
+
SEQUENCE_BASED = "sequence_based"
|
|
13
|
+
LAST_ACTIVITY_BASED = "last_activity_based"
|
lcm/data/__init__.py
ADDED
|
File without changes
|
lcm/data/data_loader.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
import pm4py
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from lcm.constants import TIMESTAMP_COL
|
|
6
|
+
from lcm.data.data_processor import check_columns
|
|
7
|
+
from lcm.logger_config import setup_logger
|
|
8
|
+
|
|
9
|
+
logger = setup_logger(__name__)
|
|
10
|
+
|
|
11
|
+
# File types the notebook's log picker offers and `load_event_log` accepts.
|
|
12
|
+
LOG_SUFFIXES = (".csv", ".xes")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def load_xes_log(file_path: str) -> pd.DataFrame:
|
|
16
|
+
try:
|
|
17
|
+
event_log = pm4py.read_xes(file_path, variant="rustxes")
|
|
18
|
+
return event_log
|
|
19
|
+
except Exception as e:
|
|
20
|
+
logger.error(f"Error loading event log from: {file_path}: {e}")
|
|
21
|
+
return None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def load_csv_log(file_path: str) -> pd.DataFrame:
|
|
25
|
+
event_log = pd.read_csv(file_path)
|
|
26
|
+
# Parsed here rather than via `parse_dates`, which would raise its own
|
|
27
|
+
# error before `load_event_log` can report the missing column.
|
|
28
|
+
if TIMESTAMP_COL in event_log.columns:
|
|
29
|
+
event_log[TIMESTAMP_COL] = pd.to_datetime(event_log[TIMESTAMP_COL])
|
|
30
|
+
return event_log
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def load_event_log(file_path) -> pd.DataFrame:
|
|
34
|
+
"""Load a .csv or .xes event log and check it has the columns we need."""
|
|
35
|
+
path = Path(file_path)
|
|
36
|
+
suffix = path.suffix.lower()
|
|
37
|
+
if suffix == ".csv":
|
|
38
|
+
event_log = load_csv_log(str(path))
|
|
39
|
+
elif suffix == ".xes":
|
|
40
|
+
event_log = load_xes_log(str(path))
|
|
41
|
+
if event_log is None:
|
|
42
|
+
raise ValueError(f"Could not read XES log '{path.name}'.")
|
|
43
|
+
else:
|
|
44
|
+
raise ValueError(
|
|
45
|
+
f"Unsupported log type '{suffix}'; expected one of {', '.join(LOG_SUFFIXES)}."
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
check_columns(event_log, f"'{path.name}'")
|
|
49
|
+
return event_log
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
from typing import Dict, List, Tuple
|
|
3
|
+
from lcm.constants import CASE_ID_COL, ACTIVITY_COL, TIMESTAMP_COL, EMPTY_TRACE
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def check_columns(event_log: pd.DataFrame, source: str = "The event log") -> None:
|
|
7
|
+
"""Raise a ValueError if `event_log` lacks a column the maps need."""
|
|
8
|
+
missing = [
|
|
9
|
+
col
|
|
10
|
+
for col in (CASE_ID_COL, ACTIVITY_COL, TIMESTAMP_COL)
|
|
11
|
+
if col not in event_log.columns
|
|
12
|
+
]
|
|
13
|
+
if missing:
|
|
14
|
+
raise ValueError(f"{source} is missing column(s): {', '.join(missing)}.")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class DataProcessor:
|
|
18
|
+
"""Handles all data transformation and preparation logic."""
|
|
19
|
+
|
|
20
|
+
def prepare_traces(self, event_log: pd.DataFrame) -> List[List[str]]:
|
|
21
|
+
"""Return the activities of each case in timestamp order."""
|
|
22
|
+
check_columns(event_log)
|
|
23
|
+
events = event_log.dropna(subset=[ACTIVITY_COL]).sort_values(
|
|
24
|
+
TIMESTAMP_COL, kind="stable"
|
|
25
|
+
)
|
|
26
|
+
return events.groupby(CASE_ID_COL)[ACTIVITY_COL].agg(list).tolist()
|
|
27
|
+
|
|
28
|
+
def apply_folds(
|
|
29
|
+
self, traces: List[List[str]], folds: Dict[str, List[str]]
|
|
30
|
+
) -> List[List[str]]:
|
|
31
|
+
"""Rename every folded activity to its fold name."""
|
|
32
|
+
if not folds:
|
|
33
|
+
return traces
|
|
34
|
+
mapping = {act: name for name, members in folds.items() for act in members}
|
|
35
|
+
return [[mapping.get(act, act) for act in trace] for trace in traces]
|
|
36
|
+
|
|
37
|
+
def create_variants(
|
|
38
|
+
self,
|
|
39
|
+
traces: List[List[str]],
|
|
40
|
+
selected_activities: List[str],
|
|
41
|
+
visualize_empty_cases: bool,
|
|
42
|
+
) -> Tuple[List[List[str]], int]:
|
|
43
|
+
"""Reduce traces to the selected activities; also count the emptied ones."""
|
|
44
|
+
selected = set(selected_activities)
|
|
45
|
+
filtered = [[act for act in trace if act in selected] for trace in traces]
|
|
46
|
+
variants = [trace for trace in filtered if trace]
|
|
47
|
+
empty_cases = len(filtered) - len(variants)
|
|
48
|
+
|
|
49
|
+
if visualize_empty_cases:
|
|
50
|
+
variants += [[EMPTY_TRACE] for _ in range(empty_cases)]
|
|
51
|
+
|
|
52
|
+
return variants, empty_cases
|
lcm/domain/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import networkx as nx
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class GraphAnalyzer:
|
|
5
|
+
"""Enriches graphs with domain-specific metrics (leakage, termination, etc.)."""
|
|
6
|
+
|
|
7
|
+
def enrich_graph_with_metrics(
|
|
8
|
+
self, G: nx.MultiDiGraph, knockout_threshold: float = 0.5
|
|
9
|
+
) -> nx.MultiDiGraph:
|
|
10
|
+
leakage_gt_0_count = 0
|
|
11
|
+
terminal_count = 0
|
|
12
|
+
G_enriched = G.copy()
|
|
13
|
+
for node in G_enriched.nodes():
|
|
14
|
+
incoming_weight = sum(
|
|
15
|
+
G_enriched.edges[pred, node, key]["weight"]
|
|
16
|
+
for pred in G_enriched.predecessors(node)
|
|
17
|
+
for key in G_enriched[pred][node]
|
|
18
|
+
)
|
|
19
|
+
outgoing_weight = sum(
|
|
20
|
+
G_enriched.edges[node, succ, key]["weight"]
|
|
21
|
+
for succ in G_enriched.successors(node)
|
|
22
|
+
for key in G_enriched[node][succ]
|
|
23
|
+
)
|
|
24
|
+
weight = G_enriched.nodes[node].get("weight", 0)
|
|
25
|
+
leakage = incoming_weight - outgoing_weight
|
|
26
|
+
terminated_cases = weight - outgoing_weight
|
|
27
|
+
termination_ratio = terminated_cases / weight if weight > 0 else 0
|
|
28
|
+
|
|
29
|
+
G_enriched.nodes[node]["metrics"] = {
|
|
30
|
+
"incoming_flow": incoming_weight,
|
|
31
|
+
"outgoing_flow": outgoing_weight,
|
|
32
|
+
"leakage": leakage,
|
|
33
|
+
"termination_ratio": termination_ratio,
|
|
34
|
+
"is_balanced": incoming_weight == outgoing_weight,
|
|
35
|
+
"is_terminal": termination_ratio >= knockout_threshold,
|
|
36
|
+
}
|
|
37
|
+
if leakage > 0:
|
|
38
|
+
leakage_gt_0_count += 1
|
|
39
|
+
if termination_ratio >= knockout_threshold:
|
|
40
|
+
terminal_count += 1
|
|
41
|
+
G_enriched.graph["leakage_gt_0_count"] = leakage_gt_0_count
|
|
42
|
+
G_enriched.graph["terminal_count"] = terminal_count
|
|
43
|
+
return G_enriched
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import networkx as nx
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AbstractGraphBuilder(ABC):
|
|
7
|
+
"""Abstract base class for all graph builder"""
|
|
8
|
+
|
|
9
|
+
@abstractmethod
|
|
10
|
+
def build(
|
|
11
|
+
self, variants: List[List[str]], allow_loops: bool = True
|
|
12
|
+
) -> nx.MultiDiGraph:
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
@property
|
|
16
|
+
@abstractmethod
|
|
17
|
+
def name(self) -> str:
|
|
18
|
+
"""User friendly name for the builder strategy"""
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import networkx as nx
|
|
2
|
+
from collections import defaultdict
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
from .abstract_graph_builder import AbstractGraphBuilder
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LastActivityBasedGraphBuilder(AbstractGraphBuilder):
|
|
9
|
+
@property
|
|
10
|
+
def name(self) -> str:
|
|
11
|
+
return "Last-Activity-Based Graph"
|
|
12
|
+
|
|
13
|
+
def build(
|
|
14
|
+
self, variants: List[List[str]], allow_loops: bool = True
|
|
15
|
+
) -> nx.MultiDiGraph:
|
|
16
|
+
"""
|
|
17
|
+
Build a graph where each node is the last activity executed in the prefix.
|
|
18
|
+
Edges represent direct transitions between last activities.
|
|
19
|
+
"""
|
|
20
|
+
transition_counts = defaultdict(int)
|
|
21
|
+
node_weights = defaultdict(int) # Total times each activity appears as last
|
|
22
|
+
START_NODE = "START"
|
|
23
|
+
|
|
24
|
+
total_cases = len(variants)
|
|
25
|
+
|
|
26
|
+
for activities in variants:
|
|
27
|
+
prev_activity = START_NODE
|
|
28
|
+
|
|
29
|
+
for activity in activities:
|
|
30
|
+
transition_key = (prev_activity, activity)
|
|
31
|
+
if prev_activity != activity or allow_loops:
|
|
32
|
+
transition_counts[transition_key] += 1
|
|
33
|
+
node_weights[activity] += 1
|
|
34
|
+
|
|
35
|
+
prev_activity = activity
|
|
36
|
+
|
|
37
|
+
G = nx.MultiDiGraph()
|
|
38
|
+
|
|
39
|
+
# START node weight = total number of cases
|
|
40
|
+
G.add_node(
|
|
41
|
+
START_NODE,
|
|
42
|
+
weight=total_cases,
|
|
43
|
+
label="START",
|
|
44
|
+
last_activity=None,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# Add activity nodes
|
|
48
|
+
for activity, weight in node_weights.items():
|
|
49
|
+
G.add_node(
|
|
50
|
+
activity,
|
|
51
|
+
weight=weight,
|
|
52
|
+
label=activity,
|
|
53
|
+
last_activity=activity,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Add edges
|
|
57
|
+
for (from_activity, to_activity), count in transition_counts.items():
|
|
58
|
+
G.add_edge(
|
|
59
|
+
from_activity,
|
|
60
|
+
to_activity,
|
|
61
|
+
weight=count,
|
|
62
|
+
activity=to_activity,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return G
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import networkx as nx
|
|
2
|
+
from collections import defaultdict
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
from .abstract_graph_builder import AbstractGraphBuilder
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SequenceBasedPrefixTreeBuilder(AbstractGraphBuilder):
|
|
9
|
+
@property
|
|
10
|
+
def name(self) -> str:
|
|
11
|
+
return "Sequence-Based Prefix Tree"
|
|
12
|
+
|
|
13
|
+
def build(
|
|
14
|
+
self, variants: List[List[str]], allow_loops: bool = True
|
|
15
|
+
) -> nx.MultiDiGraph:
|
|
16
|
+
"""
|
|
17
|
+
Build a prefix tree where each node is a unique sequence (tuple) of activities.
|
|
18
|
+
No merging: A->B->C is different from B->A->C.
|
|
19
|
+
"""
|
|
20
|
+
state_counts = defaultdict(int)
|
|
21
|
+
transition_info = defaultdict(lambda: {"count": 0, "activity": None})
|
|
22
|
+
|
|
23
|
+
for activities in variants:
|
|
24
|
+
current_state = tuple() # empty prefix
|
|
25
|
+
state_counts[current_state] += 1
|
|
26
|
+
|
|
27
|
+
for i, activity in enumerate(activities):
|
|
28
|
+
# Build prefix up to current position
|
|
29
|
+
new_state = tuple(activities[: i + 1])
|
|
30
|
+
|
|
31
|
+
# Always add edge (even if same state, if loops allowed)
|
|
32
|
+
if current_state != new_state or allow_loops:
|
|
33
|
+
transition_key = (current_state, new_state)
|
|
34
|
+
transition_info[transition_key]["count"] += 1
|
|
35
|
+
transition_info[transition_key]["activity"] = activity
|
|
36
|
+
|
|
37
|
+
current_state = new_state
|
|
38
|
+
state_counts[current_state] += 1
|
|
39
|
+
|
|
40
|
+
G = nx.MultiDiGraph()
|
|
41
|
+
|
|
42
|
+
for state, count in state_counts.items():
|
|
43
|
+
# Label: START for empty, otherwise "A → B → C"
|
|
44
|
+
state_label = "START" if len(state) == 0 else " → ".join(state)
|
|
45
|
+
G.add_node(
|
|
46
|
+
state,
|
|
47
|
+
weight=count,
|
|
48
|
+
label=state_label,
|
|
49
|
+
sequence_length=len(state),
|
|
50
|
+
activities=list(state),
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
for (from_state, to_state), info in transition_info.items():
|
|
54
|
+
if info["count"] > 0 and from_state in G.nodes and to_state in G.nodes:
|
|
55
|
+
G.add_edge(
|
|
56
|
+
from_state,
|
|
57
|
+
to_state,
|
|
58
|
+
weight=info["count"],
|
|
59
|
+
activity=info["activity"],
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
return G
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import networkx as nx
|
|
2
|
+
from collections import defaultdict
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
from .abstract_graph_builder import AbstractGraphBuilder
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SetBasedPrefixGraphBuilder(AbstractGraphBuilder):
|
|
9
|
+
@property
|
|
10
|
+
def name(self) -> str:
|
|
11
|
+
return "Set-Based Prefix Graph"
|
|
12
|
+
|
|
13
|
+
def build(
|
|
14
|
+
self, variants: List[List[str]], allow_loops: bool = True
|
|
15
|
+
) -> nx.MultiDiGraph:
|
|
16
|
+
"""
|
|
17
|
+
Build a prefix graph from a case log
|
|
18
|
+
"""
|
|
19
|
+
state_counts = defaultdict(int)
|
|
20
|
+
transitions = [] # store each transition as (from_state, to_state, activity)
|
|
21
|
+
|
|
22
|
+
for activities in variants:
|
|
23
|
+
current_state = frozenset()
|
|
24
|
+
state_counts[current_state] += 1
|
|
25
|
+
|
|
26
|
+
for i, activity in enumerate(activities):
|
|
27
|
+
new_state = frozenset(activities[: i + 1])
|
|
28
|
+
if current_state != new_state or allow_loops:
|
|
29
|
+
transitions.append((current_state, new_state, activity))
|
|
30
|
+
state_counts[new_state] += 1
|
|
31
|
+
current_state = new_state
|
|
32
|
+
|
|
33
|
+
G = nx.MultiDiGraph()
|
|
34
|
+
# add nodes
|
|
35
|
+
for state, count in state_counts.items():
|
|
36
|
+
state_label = "START" if not state else "{" + ", ".join(sorted(state)) + "}"
|
|
37
|
+
G.add_node(
|
|
38
|
+
state, weight=count, label=state_label, activities_completed=len(state)
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# group transitions by (from_state, to_state, activity) to count occurrences per activity
|
|
42
|
+
transition_groups = defaultdict(int)
|
|
43
|
+
for from_state, to_state, activity in transitions:
|
|
44
|
+
key = (from_state, to_state, activity)
|
|
45
|
+
transition_groups[key] += 1
|
|
46
|
+
|
|
47
|
+
# add each unique (from, to, activity) as a separate edge
|
|
48
|
+
for (from_state, to_state, activity), count in transition_groups.items():
|
|
49
|
+
G.add_edge(
|
|
50
|
+
from_state,
|
|
51
|
+
to_state,
|
|
52
|
+
weight=count,
|
|
53
|
+
activity=activity,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
return G
|
lcm/logger_config.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def setup_logger(name):
|
|
5
|
+
logger = logging.getLogger(name)
|
|
6
|
+
logger.setLevel(logging.INFO) # Set the minimum logging level
|
|
7
|
+
|
|
8
|
+
# Create console handler
|
|
9
|
+
ch = logging.StreamHandler()
|
|
10
|
+
ch.setLevel(logging.INFO)
|
|
11
|
+
|
|
12
|
+
# Create formatter
|
|
13
|
+
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
14
|
+
|
|
15
|
+
# Add formatter to console handler
|
|
16
|
+
ch.setFormatter(formatter)
|
|
17
|
+
|
|
18
|
+
# Add console handler to logger
|
|
19
|
+
if not logger.handlers:
|
|
20
|
+
logger.addHandler(ch)
|
|
21
|
+
|
|
22
|
+
return logger
|
lcm/services/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import networkx as nx
|
|
2
|
+
from typing import Dict, List
|
|
3
|
+
from lcm.constants import MapType
|
|
4
|
+
from lcm.graph_builders import AbstractGraphBuilder
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class GraphService:
|
|
8
|
+
"""Handles graph construction."""
|
|
9
|
+
|
|
10
|
+
def __init__(self, graph_builders: Dict[MapType, AbstractGraphBuilder]):
|
|
11
|
+
self.graph_builders = graph_builders
|
|
12
|
+
|
|
13
|
+
def build_graph(
|
|
14
|
+
self,
|
|
15
|
+
variants: List[List[str]],
|
|
16
|
+
map_type: MapType,
|
|
17
|
+
allow_loops: bool = True,
|
|
18
|
+
) -> nx.MultiDiGraph:
|
|
19
|
+
return self.graph_builders[map_type].build(variants, allow_loops=allow_loops)
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
from typing import Dict, List, Optional, Tuple
|
|
3
|
+
import plotly.graph_objects as go
|
|
4
|
+
from lcm.constants import MapType
|
|
5
|
+
from lcm.data.data_processor import DataProcessor
|
|
6
|
+
from lcm.services.graph_service import GraphService
|
|
7
|
+
from lcm.domain.graph_analyzer import GraphAnalyzer
|
|
8
|
+
from lcm.visualization.sankey_visualizer import SankeyVisualizer
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ProcessAnalyticsService:
|
|
12
|
+
"""Orchestrates the analytics pipeline"""
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
event_log: pd.DataFrame,
|
|
17
|
+
data_processor: DataProcessor,
|
|
18
|
+
graph_service: GraphService,
|
|
19
|
+
graph_analyzer: GraphAnalyzer,
|
|
20
|
+
):
|
|
21
|
+
self.data_processor = data_processor
|
|
22
|
+
self.graph_service = graph_service
|
|
23
|
+
self.graph_analyzer = graph_analyzer
|
|
24
|
+
|
|
25
|
+
self.traces = self.data_processor.prepare_traces(event_log)
|
|
26
|
+
|
|
27
|
+
def get_all_activities(
|
|
28
|
+
self, folds: Optional[Dict[str, List[str]]] = None
|
|
29
|
+
) -> List[str]:
|
|
30
|
+
"""List the activities of the log, as they appear after `folds`.
|
|
31
|
+
|
|
32
|
+
Raises:
|
|
33
|
+
ValueError: If `folds` are invalid.
|
|
34
|
+
"""
|
|
35
|
+
folds = folds or {}
|
|
36
|
+
known = {act for trace in self.traces for act in trace}
|
|
37
|
+
folded = set()
|
|
38
|
+
for name, members in folds.items():
|
|
39
|
+
if not name.strip():
|
|
40
|
+
raise ValueError("Every fold needs a name.")
|
|
41
|
+
if not members:
|
|
42
|
+
raise ValueError(f"Fold '{name}' has no activities.")
|
|
43
|
+
self._reject(set(members) - known, f"Fold '{name}' has unknown activities")
|
|
44
|
+
self._reject(set(members) & folded, f"Fold '{name}' reuses folded activities")
|
|
45
|
+
folded |= set(members)
|
|
46
|
+
if name in known - set(members):
|
|
47
|
+
raise ValueError(f"Fold '{name}' has the name of another activity.")
|
|
48
|
+
|
|
49
|
+
return sorted((known - folded) | set(folds))
|
|
50
|
+
|
|
51
|
+
def generate(
|
|
52
|
+
self,
|
|
53
|
+
*,
|
|
54
|
+
activities: Optional[List[str]] = None,
|
|
55
|
+
map_type: str = MapType.SET_BASED,
|
|
56
|
+
allow_loops: bool = True,
|
|
57
|
+
visualize_empty_cases: bool = True,
|
|
58
|
+
folds: Optional[Dict[str, List[str]]] = None,
|
|
59
|
+
) -> Tuple[go.Figure, dict]:
|
|
60
|
+
"""Draw a process map of the log.
|
|
61
|
+
|
|
62
|
+
Every call starts from the full log, so maps do not affect each other.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
activities: Activities to keep, named as they appear after folding.
|
|
66
|
+
All of them if None.
|
|
67
|
+
map_type: A `MapType`, or its value such as "set_based".
|
|
68
|
+
allow_loops: Draw an activity that leaves the node unchanged as a
|
|
69
|
+
self-loop. Has no effect on sequence-based maps, whose nodes
|
|
70
|
+
never repeat.
|
|
71
|
+
visualize_empty_cases: Draw the cases that have none of the selected
|
|
72
|
+
activities as an "EMPTY TRACE" node.
|
|
73
|
+
folds: Fold name mapped to the activities it replaces, for example
|
|
74
|
+
{"Rejections": ["Rejected by A", "Rejected by B"]}.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
The Plotly Sankey figure, and a dict of counts describing the map.
|
|
78
|
+
|
|
79
|
+
Raises:
|
|
80
|
+
ValueError: If `map_type`, `activities` or `folds` are invalid.
|
|
81
|
+
"""
|
|
82
|
+
map_type = MapType(map_type)
|
|
83
|
+
folds = folds or {}
|
|
84
|
+
selected_activities = self._select_activities(
|
|
85
|
+
activities, self.get_all_activities(folds)
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
traces = self.data_processor.apply_folds(self.traces, folds)
|
|
89
|
+
variants, empty_cases = self.data_processor.create_variants(
|
|
90
|
+
traces, selected_activities, visualize_empty_cases
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
G = self.graph_service.build_graph(variants, map_type, allow_loops=allow_loops)
|
|
94
|
+
G = self.graph_analyzer.enrich_graph_with_metrics(G)
|
|
95
|
+
|
|
96
|
+
# Create visualizer with selected activities for legend
|
|
97
|
+
visualizer = SankeyVisualizer(all_activities=selected_activities)
|
|
98
|
+
return visualizer.create_figure(G), {
|
|
99
|
+
"nodes_leakage_gt_0": G.graph.get("leakage_gt_0_count", 0),
|
|
100
|
+
"terminal_nodes": G.graph.get("terminal_count", 0),
|
|
101
|
+
"total_nodes": G.number_of_nodes(),
|
|
102
|
+
"empty_cases": empty_cases,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
def _select_activities(
|
|
106
|
+
self, activities: Optional[List[str]], available: List[str]
|
|
107
|
+
) -> List[str]:
|
|
108
|
+
"""Check the chosen activities; return the ones to draw."""
|
|
109
|
+
if activities is None:
|
|
110
|
+
return available
|
|
111
|
+
if not activities:
|
|
112
|
+
raise ValueError("Select at least one activity.")
|
|
113
|
+
self._reject(
|
|
114
|
+
set(activities) - set(available),
|
|
115
|
+
"Unknown activities (folded ones go by fold name)",
|
|
116
|
+
)
|
|
117
|
+
return list(activities)
|
|
118
|
+
|
|
119
|
+
@staticmethod
|
|
120
|
+
def _reject(names: set, problem: str) -> None:
|
|
121
|
+
if names:
|
|
122
|
+
raise ValueError(f"{problem}: {', '.join(sorted(names))}.")
|
|
123
|
+
|
|
124
|
+
@staticmethod
|
|
125
|
+
def summarize_metadata(metadata: dict) -> dict:
|
|
126
|
+
"""Summary of graph metadata for display."""
|
|
127
|
+
return {
|
|
128
|
+
"Total Nodes": metadata["total_nodes"],
|
|
129
|
+
"Nodes with Leakage > 0": metadata["nodes_leakage_gt_0"],
|
|
130
|
+
"Terminal Nodes": metadata["terminal_nodes"],
|
|
131
|
+
"Empty Cases": metadata["empty_cases"],
|
|
132
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import networkx as nx
|
|
2
|
+
import plotly.graph_objects as go
|
|
3
|
+
import plotly.express as px
|
|
4
|
+
from typing import Dict, Any
|
|
5
|
+
|
|
6
|
+
from lcm.constants import EMPTY_TRACE
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SankeyVisualizer:
|
|
10
|
+
"""Converts an enriched graph into a Plotly Sankey figure."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, all_activities=None):
|
|
13
|
+
self.all_activities = all_activities or []
|
|
14
|
+
|
|
15
|
+
def create_figure(self, G: nx.MultiDiGraph) -> go.Figure:
|
|
16
|
+
if not G.nodes:
|
|
17
|
+
return go.Figure()
|
|
18
|
+
|
|
19
|
+
data = self._prepare_sankey_data(G)
|
|
20
|
+
return self._build_figure(data)
|
|
21
|
+
|
|
22
|
+
def _prepare_sankey_data(self, G: nx.MultiDiGraph) -> Dict[str, Any]:
|
|
23
|
+
node_to_idx = {}
|
|
24
|
+
nodes_info = []
|
|
25
|
+
node_custom_data = []
|
|
26
|
+
|
|
27
|
+
# Use all activities for consistent coloring, fall back to graph activities if not provided
|
|
28
|
+
if self.all_activities:
|
|
29
|
+
activities_for_coloring = sorted(self.all_activities)
|
|
30
|
+
else:
|
|
31
|
+
activities_for_coloring = sorted(
|
|
32
|
+
{data.get("activity", "Unknown") for _, _, data in G.edges(data=True)}
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
activity_colors = px.colors.qualitative.Plotly
|
|
36
|
+
activity_color_map = {
|
|
37
|
+
act: activity_colors[i % len(activity_colors)]
|
|
38
|
+
for i, act in enumerate(activities_for_coloring)
|
|
39
|
+
}
|
|
40
|
+
activity_color_map[EMPTY_TRACE] = "lightgrey"
|
|
41
|
+
|
|
42
|
+
# Process nodes
|
|
43
|
+
for node, data in G.nodes(data=True):
|
|
44
|
+
weight = data.get("weight", 0)
|
|
45
|
+
if weight <= 0:
|
|
46
|
+
continue
|
|
47
|
+
|
|
48
|
+
node_idx = len(nodes_info)
|
|
49
|
+
node_to_idx[node] = node_idx
|
|
50
|
+
|
|
51
|
+
metrics = data.get("metrics", {})
|
|
52
|
+
incoming = metrics.get("incoming_flow", 0)
|
|
53
|
+
outgoing = metrics.get("outgoing_flow", 0)
|
|
54
|
+
leakage = metrics.get("leakage", 0)
|
|
55
|
+
|
|
56
|
+
# Determine color based on semantic state
|
|
57
|
+
if data["label"] == "START":
|
|
58
|
+
node_color = "white"
|
|
59
|
+
elif data["label"] in [EMPTY_TRACE, f"{{{EMPTY_TRACE}}}"]:
|
|
60
|
+
node_color = "white"
|
|
61
|
+
elif metrics.get("is_terminal", False):
|
|
62
|
+
node_color = "black"
|
|
63
|
+
elif metrics.get("is_balanced", False):
|
|
64
|
+
node_color = "lightgrey"
|
|
65
|
+
else:
|
|
66
|
+
node_color = "dimgrey"
|
|
67
|
+
|
|
68
|
+
nodes_info.append({"label": data["label"], "color": node_color})
|
|
69
|
+
node_custom_data.append(
|
|
70
|
+
{
|
|
71
|
+
"node_label": data["label"],
|
|
72
|
+
"incoming_flow": incoming,
|
|
73
|
+
"outgoing_flow": outgoing,
|
|
74
|
+
"leakage": leakage,
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# Process edges
|
|
79
|
+
sources, targets, values, link_labels, link_colors = [], [], [], [], []
|
|
80
|
+
for src, tgt, key, data in G.edges(data=True, keys=True):
|
|
81
|
+
src_idx = node_to_idx.get(src)
|
|
82
|
+
tgt_idx = node_to_idx.get(tgt)
|
|
83
|
+
if src_idx is None or tgt_idx is None:
|
|
84
|
+
continue
|
|
85
|
+
|
|
86
|
+
activity = data.get("activity", "Unknown")
|
|
87
|
+
weight = data["weight"]
|
|
88
|
+
|
|
89
|
+
sources.append(src_idx)
|
|
90
|
+
targets.append(tgt_idx)
|
|
91
|
+
values.append(weight)
|
|
92
|
+
link_labels.append(f"{activity} ({weight})")
|
|
93
|
+
link_colors.append(activity_color_map[activity])
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
"nodes_info": nodes_info,
|
|
97
|
+
"node_custom_data": node_custom_data,
|
|
98
|
+
"sources": sources,
|
|
99
|
+
"targets": targets,
|
|
100
|
+
"values": values,
|
|
101
|
+
"link_labels": link_labels,
|
|
102
|
+
"link_colors": link_colors,
|
|
103
|
+
"activity_color_map": activity_color_map,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
def _build_figure(self, data: Dict[str, Any]) -> go.Figure:
|
|
107
|
+
node_labels = [n["label"] for n in data["nodes_info"]]
|
|
108
|
+
node_colors = [n["color"] for n in data["nodes_info"]]
|
|
109
|
+
|
|
110
|
+
fig = go.Figure(
|
|
111
|
+
data=[
|
|
112
|
+
go.Sankey(
|
|
113
|
+
textfont=dict(color="rgba(0,0,0,0)", size=1),
|
|
114
|
+
node=dict(
|
|
115
|
+
pad=15,
|
|
116
|
+
thickness=20,
|
|
117
|
+
line=dict(color="black", width=0.5),
|
|
118
|
+
label=node_labels,
|
|
119
|
+
color=node_colors,
|
|
120
|
+
customdata=data["node_custom_data"],
|
|
121
|
+
hovertemplate=(
|
|
122
|
+
"<b>%{customdata.node_label}</b><br>"
|
|
123
|
+
"Incoming Flow: %{customdata.incoming_flow}<br>"
|
|
124
|
+
"Outgoing Flow: %{customdata.outgoing_flow}<br>"
|
|
125
|
+
"Leakage: %{customdata.leakage}<br>"
|
|
126
|
+
),
|
|
127
|
+
),
|
|
128
|
+
link=dict(
|
|
129
|
+
source=data["sources"],
|
|
130
|
+
target=data["targets"],
|
|
131
|
+
value=data["values"],
|
|
132
|
+
label=data["link_labels"],
|
|
133
|
+
color=data["link_colors"],
|
|
134
|
+
hovertemplate="%{label}<br>Cases: %{value}<extra></extra>",
|
|
135
|
+
),
|
|
136
|
+
)
|
|
137
|
+
]
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
fig.update_layout(
|
|
141
|
+
font_size=12,
|
|
142
|
+
height=700,
|
|
143
|
+
paper_bgcolor='rgba(0,0,0,0)',
|
|
144
|
+
plot_bgcolor='rgba(0,0,0,0)',
|
|
145
|
+
legend=dict(
|
|
146
|
+
title="Activities",
|
|
147
|
+
orientation="v",
|
|
148
|
+
yanchor="top",
|
|
149
|
+
y=1,
|
|
150
|
+
xanchor="left",
|
|
151
|
+
x=1.05,
|
|
152
|
+
bgcolor="rgba(255, 255, 255, 0.8)",
|
|
153
|
+
bordercolor="gray",
|
|
154
|
+
borderwidth=1,
|
|
155
|
+
),
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
# Add dummy traces for legend
|
|
159
|
+
for activity, color in data["activity_color_map"].items():
|
|
160
|
+
fig.add_trace(
|
|
161
|
+
go.Scatter(
|
|
162
|
+
x=[None],
|
|
163
|
+
y=[None],
|
|
164
|
+
mode="markers",
|
|
165
|
+
marker=dict(size=10, color=color),
|
|
166
|
+
legendgroup=activity,
|
|
167
|
+
showlegend=True,
|
|
168
|
+
name=activity,
|
|
169
|
+
)
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
fig.update_xaxes(showgrid=False, zeroline=False, showticklabels=False)
|
|
173
|
+
fig.update_yaxes(showgrid=False, zeroline=False, showticklabels=False)
|
|
174
|
+
|
|
175
|
+
return fig
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: linear-continuous-process-mapper
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Linear continuous process maps of event logs as Plotly Sankey figures.
|
|
5
|
+
Project-URL: Homepage, https://github.com/aaronkurz/linear-continuous-process-mapper-marimo
|
|
6
|
+
Project-URL: Repository, https://github.com/aaronkurz/linear-continuous-process-mapper-marimo
|
|
7
|
+
Author: ICS University St. Gallen
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: event log,process map,process mining,sankey
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Requires-Dist: networkx>=3.2
|
|
16
|
+
Requires-Dist: pandas>=2.2
|
|
17
|
+
Requires-Dist: plotly>=5.20
|
|
18
|
+
Requires-Dist: pm4py>=2.7.11
|
|
19
|
+
Provides-Extra: notebook
|
|
20
|
+
Requires-Dist: kaleido>=1.0.0; extra == 'notebook'
|
|
21
|
+
Requires-Dist: marimo>=0.21.1; extra == 'notebook'
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# LCM Marimo
|
|
25
|
+
|
|
26
|
+
# Linear Continuous Process Mapper
|
|
27
|
+
|
|
28
|
+
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.
|
|
29
|
+
|
|
30
|
+
## Overview
|
|
31
|
+

|
|
32
|
+
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).
|
|
33
|
+
|
|
34
|
+
## How to Run
|
|
35
|
+
|
|
36
|
+
This is the marimo version of the LCPM.
|
|
37
|
+
|
|
38
|
+
To get started:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
uv sync
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Then to run:
|
|
45
|
+
```
|
|
46
|
+
uv run marimo run marimo_app.py
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or to edit;
|
|
50
|
+
```
|
|
51
|
+
uv run marimo edit marimo_app.py
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Event logs
|
|
55
|
+
|
|
56
|
+
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:
|
|
57
|
+
|
|
58
|
+
- `case:concept:name`: case ID
|
|
59
|
+
- `concept:name`: activity
|
|
60
|
+
- `time:timestamp`: timestamp
|
|
61
|
+
|
|
62
|
+
The included `logs/log.csv` is a preprocessed subset of **BPI Challenge 2020:
|
|
63
|
+
Domestic Declarations** by Boudewijn van Dongen (2020), Version 1,
|
|
64
|
+
4TU.ResearchData.
|
|
65
|
+
Source: https://doi.org/10.4121/uuid:3f422315-ed9d-4882-891f-e180b5b4feb5
|
|
66
|
+
|
|
67
|
+
The subset contains 8,260 cases and 46,375 events; all included cases start
|
|
68
|
+
in 2018. It was converted from `DomesticDeclarations2H.xes` to CSV, retaining
|
|
69
|
+
only case ID, activity, and timestamp, with timestamps expressed in UTC.
|
|
70
|
+
|
|
71
|
+
This dataset is licensed under
|
|
72
|
+
[Creative Commons Attribution–NonCommercial 4.0 International (CC BY-NC 4.0)](https://creativecommons.org/licenses/by-nc/4.0/).
|
|
73
|
+
Its reuse and redistribution are subject to that license, including its
|
|
74
|
+
attribution and noncommercial-use conditions. The repository’s MIT license
|
|
75
|
+
applies to the code, not to this dataset.
|
|
76
|
+
|
|
77
|
+
## Install
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
pip install linear-continuous-process-mapper
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This installs the `lcm` library only. The interactive notebook needs the extra: `pip install "linear-continuous-process-mapper[notebook]"`.
|
|
84
|
+
|
|
85
|
+
## Programmatic Use
|
|
86
|
+
|
|
87
|
+
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.
|
|
88
|
+
|
|
89
|
+
`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:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
uv run marimo edit programmatic_example.py
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
import lcm
|
|
97
|
+
|
|
98
|
+
lcm_service = lcm.get_service(lcm.load_event_log("logs/log.csv"))
|
|
99
|
+
|
|
100
|
+
figure, metadata = lcm_service.generate(
|
|
101
|
+
activities=None, # None keeps all of them; folded ones go by their fold name
|
|
102
|
+
map_type=lcm.MapType.SEQUENCE_BASED, # or "sequence_based"
|
|
103
|
+
allow_loops=True, # has no effect on sequence-based maps
|
|
104
|
+
visualize_empty_cases=True,
|
|
105
|
+
folds={"Rejections": ["Declaration REJECTED by ADMINISTRATION", "Declaration REJECTED by SUPERVISOR"]},
|
|
106
|
+
)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
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:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
# One cell
|
|
113
|
+
set_map, set_metadata = lcm_service.generate(map_type="set_based")
|
|
114
|
+
set_map
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
# Another cell
|
|
119
|
+
last_activity_map, last_activity_metadata = lcm_service.generate(map_type="last_activity_based")
|
|
120
|
+
last_activity_map
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Display the figure directly. Wrapping it in `mo.ui.plotly()` leaves a blank plot, because that wrapper does not support Sankey traces.
|
|
124
|
+
|
|
125
|
+
## Project Structure
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
**marimo_app.py** - The main entry point for running the application, via a marimo notebook. It is also the example of
|
|
129
|
+
interactive use of the library.
|
|
130
|
+
|
|
131
|
+
**programmatic_example.py** - An example analysis that uses the library from code, without widgets.
|
|
132
|
+
|
|
133
|
+
**lcm** - The library, independent of marimo. `lcm/__init__.py` wires together all components (data processors, graph
|
|
134
|
+
builders, analyzers) in `get_service`. It contains the main analytical components:
|
|
135
|
+
|
|
136
|
+
- **data** - Event log data handling using PM4Py. Loads XES and CSV files, orders each case's events by timestamp,
|
|
137
|
+
applies folds, filters by activities, and creates the variants for analysis
|
|
138
|
+
- **domain** - Graph analysis algorithms that enrich process graphs with business metrics including flow analysis,
|
|
139
|
+
leakage detection, termination ratios, and node balancing
|
|
140
|
+
- **graph_builders** - Multiple strategies for constructing process graphs from event data: set-based prefix graphs,
|
|
141
|
+
sequence-based prefix trees, and last-activity-based graphs with configurable loop handling
|
|
142
|
+
- **services** - High-level orchestration services that coordinate graph construction and the complete analytics
|
|
143
|
+
pipeline from raw data to visualizations
|
|
144
|
+
- **visualization** - Interactive Sankey diagram generator using Plotly that converts enriched process graphs into
|
|
145
|
+
color-coded flow visualizations with hover details and activity legends
|
|
146
|
+
|
|
147
|
+
**tests** - Tests of the library. Run them with `uv run pytest`.
|
|
148
|
+
|
|
149
|
+
## Repository Authors
|
|
150
|
+
- [@moritzfaes](https://github.com/moritzfaes)
|
|
151
|
+
- [@hvoelzer](https://github.com/hvoelzer)
|
|
152
|
+
- [@aaronkurz](https://github.com/aaronkurz)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
lcm/__init__.py,sha256=zxkVEuwB47CH_6Q22hgsbT1-JURzMhOy5_pzRu17e6U,1417
|
|
2
|
+
lcm/constants.py,sha256=A4K1xh9btwEyIeVOuJciOLZuK6Dz6IDY8zDhA3x3xKE,368
|
|
3
|
+
lcm/logger_config.py,sha256=it05OCWWOaiCniuSSVbtp8wrBaXB6pMsWWq3w0juxKU,537
|
|
4
|
+
lcm/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
lcm/data/data_loader.py,sha256=Y-iQYm2k1FbzqSBUrS7XVNcMIRiMTpV9ErDePNYcx_c,1611
|
|
6
|
+
lcm/data/data_processor.py,sha256=ezmxnUwyNVJ6mTuNd2GyRaofn2TUGCXah71nWvfEb4M,2029
|
|
7
|
+
lcm/domain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
lcm/domain/graph_analyzer.py,sha256=augW2ul6xVtRHHFFF3IDt_ePCdWvvHHhtSPYm3jrLa0,1780
|
|
9
|
+
lcm/graph_builders/__init__.py,sha256=yxsg67MXfi_EOrNNdO4SYqGkJrFicy67IYG7VywBsOQ,229
|
|
10
|
+
lcm/graph_builders/abstract_graph_builder.py,sha256=0ct5PyNXJHOkaJqsCsI-Wh4x_S2smjfXEE3fLv2pBT8,430
|
|
11
|
+
lcm/graph_builders/last_activity_based.py,sha256=NZF3gxMm4TzHP2o2qyHIdqxbcIe2N0TMBaG7Cgc2x70,1913
|
|
12
|
+
lcm/graph_builders/sequence_based.py,sha256=q9Eepeo7ezwIjSD9pZyKmBIPU04-0L6MV-JQZfMK4Z8,2214
|
|
13
|
+
lcm/graph_builders/set_based.py,sha256=2HYKrKh_ENNov_xUuoZsB_7wmiCBg_zVGjwIHt3VxFg,1982
|
|
14
|
+
lcm/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
lcm/services/graph_service.py,sha256=BffupgUMebQVah9Z3_I8NGVkUEDdxCrJ2xa4Q_pLuiM,565
|
|
16
|
+
lcm/services/process_analytics_service.py,sha256=usXEMiqOfeoW2VNTZQkjRviGVYOQECYrPyO8MDbk1Iw,5138
|
|
17
|
+
lcm/visualization/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
lcm/visualization/sankey_visualizer.py,sha256=Njhl74gH9i6DzuoQSUN54yC_pYlx5NDrWaBx1MBwjnI,6187
|
|
19
|
+
linear_continuous_process_mapper-0.1.0.dist-info/METADATA,sha256=aXZnuesk6zk1AroEKOUAxFf9H56jECVdWS0wFUr9CU4,7284
|
|
20
|
+
linear_continuous_process_mapper-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
21
|
+
linear_continuous_process_mapper-0.1.0.dist-info/licenses/LICENSE,sha256=tc4i7y2-RzztqbJSsMb_Xc7HJ5TB0NPocgG2CgNZJ3k,1081
|
|
22
|
+
linear_continuous_process_mapper-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ICS University St.Gallen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|