in playground/process_analysis/status_transition_graph_stats_plot.py [0:0]
def boxplot(source: StatusTransitionGraph, max_edges: int = 8) -> Figure:
"""
Create a boxplot of status transition durations.
"""
fig = Figure()
most_common_edges_upto_max = sorted(
source.graph.edges.data(),
key=lambda edge: len(edge[2]["durations"]),
reverse=True,
)[:max_edges]
edge_counts = list(map(lambda edge: len(edge[2]["durations"]), most_common_edges_upto_max))
lowest_edge_count = min(edge_counts, default=1)
highest_edge_count = max(edge_counts, default=1)
edges_by_max_duration = sorted(
most_common_edges_upto_max,
key=lambda edge: max(edge[2]["durations"]),
reverse=True,
)
for edge in edges_by_max_duration:
durations = list(map(lambda d: round(d, 5), edge[2]["durations"]))
color = _color_for_edge(len(durations), lowest_edge_count, highest_edge_count)
fig.add_trace(
Box(
y=durations,
name=f"{edge[0]} ⮕ {edge[1]} ({len(durations)}x)",
boxpoints="outliers",
boxmean=True,
marker_color=color,
line_color=color,
)
)
fig.update_layout(
title_text="Status Transition Duration Statistics",
yaxis_title="Days",
xaxis_title="Transitions with occurences",
showlegend=False,
)
return fig