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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions raptor/api/insight/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ def nice_range(low: float, high: float, count: int = 5, *,
"""[low, high] widened to whole tick steps (so the axis ends on a tick).

`share`: the values are fractions (availability, a share), so the axis
never leaves 0..1 and spans at least one point. Every run at 100 %
drew an axis to 101 %, and a spread of 6e-8 gave ticks at 8 decimals."""
never leaves 0..1. Every run at 100 % drew an axis to 101 %, and a
spread of 6e-8 gave ticks at 8 decimals, so a spread under a thousandth
of a point is drawn one point wide. A larger spread under one point is
drawn to fit, with a tenth of it as margin: runs from 99.85 % to
99.995 % were drawn on a 99 % to 100 % axis, all in its top sixth.
Callers put the target in `low`..`high`, so it is always on the axis."""
if share:
low, high = max(0.0, min(low, 1.0)), max(0.0, min(high, 1.0))
if 1e-5 <= high - low < 0.01:
margin = 0.1 * (high - low)
low, high = nice_range(max(0.0, low - margin), min(1.0, high + margin), count)
return max(0.0, low), min(1.0, high)
if high - low < 0.01:
middle = (low + high) / 2
low, high = middle - 0.005, middle + 0.005
Expand Down
45 changes: 33 additions & 12 deletions raptor/api/insight/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ def downtime_pareto(attribution: dict[str, Any], top: int = 10) -> ChartSpec:


def downtime_waterfall(attribution: dict[str, Any],
operational: float | None = None) -> ChartSpec:
operational: float | None = None,
target: float | None = None) -> ChartSpec:
"""C3: from 100 % availability to the achieved one, one step per cause."""
causes = attribution.get("causes") or {}
loss = 1.0 - operational if operational is not None else None
Expand Down Expand Up @@ -496,13 +497,16 @@ def downtime_waterfall(attribution: dict[str, Any],
"waterfall", "From full availability to the achieved one",
"each step is a cause's share of the loss", "cause",
"share of loss", series=steps,
marks=[{"kind": "end", "value": running}] if steps else [],
# a target only means something on the availability scale
marks=([{"kind": "end", "value": running}] if steps else [])
+ ([{"kind": "target", "value": target}]
if target is not None and operational is not None and steps else []),
caption=caption,
provenance={"runs": attribution.get("runs", 0), "format": "percent",
"operational": operational})


def availability_ladder(ladder: dict[str, Any]) -> ChartSpec:
def availability_ladder(ladder: dict[str, Any], target: float | None = None) -> ChartSpec:
"""C4: inherent, achieved and operational availability with their gaps."""
order = (("inherent", "Inherent (repair only)"),
("achieved", "Achieved (+ planned maintenance)"),
Expand All @@ -526,6 +530,7 @@ def availability_ladder(ladder: dict[str, Any]) -> ChartSpec:
"ladder", "What each kind of availability keeps",
"the gap between rungs is what the next cause takes away",
"availability", "fraction", series=present,
marks=[{"kind": "target", "value": target}] if target is not None else [],
caption=caption,
provenance={"runs": ladder.get("runs"), "format": "percent"})

Expand Down Expand Up @@ -932,7 +937,17 @@ def annual_capacity_fan(periods: dict[str, Any]) -> ChartSpec:
return spec


def annual_fan(periods: dict[str, Any]) -> ChartSpec:
def _year_line(periods: dict[str, Any], target: float | None
) -> tuple[float | None, str]:
"""The line the year charts draw and its name: the Charts page's
target when one is set (it said "no threshold was set" beside a
target the other charts drew), else the summary's own threshold."""
if target is not None:
return target, "target"
return periods.get("threshold"), "threshold"


def annual_fan(periods: dict[str, Any], target: float | None = None) -> ChartSpec:
"""K6: does a bad year happen, and does it get worse with age?"""
rows = [row for row in periods.get("by_index") or []
if row.get("n") and row.get("p50") is not None]
Expand All @@ -941,7 +956,7 @@ def annual_fan(periods: dict[str, Any]) -> ChartSpec:
"p50": row.get("p50"), "p75": row.get("p75"),
"p95": row.get("p95"), "n": row.get("n")}
for row in rows]
threshold = periods.get("threshold")
threshold, line = _year_line(periods, target)
few = len(series) < FAN_LINE_MIN
medians = ", ".join(pct(row["p50"]) for row in series)
if not series:
Expand All @@ -967,17 +982,17 @@ def annual_fan(periods: dict[str, Any]) -> ChartSpec:
"across the runs: the dark band holds the middle half, the light one "
"9 in 10, the line is the median"), "year", "availability",
series=series,
marks=[{"kind": "target", "value": threshold}]
marks=[{"kind": "target", "value": threshold, "label": line}]
if threshold is not None else [],
caption=caption,
provenance={"runs": periods.get("runs", 0), "format": "percent",
"periods_per_run": periods.get("periods_per_run", 0)})


def annual_dots(periods: dict[str, Any]) -> ChartSpec:
def annual_dots(periods: dict[str, Any], target: float | None = None) -> ChartSpec:
"""K7: all run-years as a dot plot against the guarantee."""
pooled = periods.get("pooled") or {}
threshold = periods.get("threshold")
threshold, line = _year_line(periods, target)
n = int(pooled.get("n") or 0)
if pooled.get("dots"):
values = [float(v) for v in pooled["dots"]]
Expand All @@ -992,9 +1007,15 @@ def annual_dots(periods: dict[str, Any]) -> ChartSpec:
subtitle = "each dot is one of the quantiles P1 to P99 of the run-years"
dots = [{"value": v} for v in values]
below = pooled.get("p_below")
caption = (f"{pct(below)} of run-years fall below the threshold."
if isinstance(below, (int, float)) else
f"{pooled.get('n', 0)} run-years; no threshold was set.")
about = ""
if target is not None and target != periods.get("threshold") and values:
# equal-share dots: the share of dots below is the share of
# run-years below, exactly when there is one dot per run-year
below = sum(v < target for v in values) / len(values)
about = "" if len(values) == n else "about "
caption = (f"{about}{pct(below)} of run-years fall below the {line}."
if isinstance(below, (int, float)) and threshold is not None else
f"{pooled.get('n', 0)} run-years; no target was set.")
if values:
# a tall stack at the top had no scale: say how many it holds
top = max(values)
Expand All @@ -1006,7 +1027,7 @@ def annual_dots(periods: dict[str, Any]) -> ChartSpec:
"dot_plot", "A bad year, as a frequency",
subtitle, "availability",
"years", series=[{"name": "run-years", "dots": dots}],
marks=[{"kind": "target", "value": threshold}]
marks=[{"kind": "target", "value": threshold, "label": line}]
if threshold is not None else [],
caption=caption,
provenance={"runs": periods.get("runs", 0), "format": "percent",
Expand Down
21 changes: 17 additions & 4 deletions raptor/gui/ui/chart_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,9 @@ def _paint_waterfall(self, painter, spec, palette, area) -> None:
if not steps:
return self._paint_none(painter, spec, palette, area)
operational = spec.provenance.get("operational")
ends = [float(s["to"]) for s in steps] + [float(s["from"]) for s in steps]
target = self._target(spec) if _number(operational) else None
ends = [float(s["to"]) for s in steps] + [float(s["from"]) for s in steps] \
+ ([target] if target is not None else [])
# Zoomed so the steps fill the height, with room under the result
# so its bar is never a sliver.
span = max(ends) - min(ends)
Expand Down Expand Up @@ -768,6 +770,10 @@ def _paint_waterfall(self, painter, spec, palette, area) -> None:
self._column_label(painter, palette, QRectF(x, r.bottom() + 4, width,
2 * fm.height()),
"achieved" if _number(operational) else "rest")
if target is not None:
# last, over the result column, so its label is not hidden
self._target_line(painter, palette, frame, target, horizontal=True,
label=f"target {format_value(target, 'percent', 5)}")

def _column_label(self, painter, palette, rect: QRectF, text: str) -> None:
fm = QFontMetrics(self.font())
Expand All @@ -782,11 +788,13 @@ def _paint_ladder(self, painter, spec, palette, area) -> None:
return self._paint_none(painter, spec, palette, area)
fm = QFontMetrics(self.font())
values = [float(r["value"]) for r in rows]
target = self._target(spec)
# Zoomed towards 100 %: the rungs differ by small amounts, and on a
# 0-100 % axis every bar would look full.
top_value = 1.0 if max(values) <= 1.0 else max(values)
span = max(top_value - min(values), 1e-9)
low, high = nice_range(min(values) - 0.6 * span, top_value, 4,
bottom = min(values + ([target] if target is not None else []))
span = max(top_value - bottom, 1e-9)
low, high = nice_range(bottom - 0.6 * span, top_value, 4,
share=top_value <= 1.0)
low, high = max(0.0, low), (min(1.0, high) if top_value <= 1.0 else high)
gutter = min(area.width() * 0.45,
Expand Down Expand Up @@ -824,6 +832,9 @@ def _paint_ladder(self, painter, spec, palette, area) -> None:
Qt.AlignmentFlag.AlignVCenter, text)
self._hit(QRectF(r.left(), top, r.width(), bar_h), "rung",
str(row["name"]), f"{row['name']}: {text}")
if target is not None:
self._target_line(painter, palette, frame, target, horizontal=False,
label=f"target {format_value(target, 'percent', 5)}")

def _paint_histogram(self, painter, spec, palette, area) -> None:
bins = [b for b in spec.series if _number(b.get("lo")) and _number(b.get("hi"))
Expand Down Expand Up @@ -1121,8 +1132,10 @@ def _paint_fan(self, painter, spec, palette, area) -> None:
else:
self._paint_fan_bands(painter, palette, frame, rows)
if target is not None:
word = next((str(m.get("label")) for m in spec.marks
if m.get("kind") == "target" and m.get("label")), "threshold")
self._target_line(painter, palette, frame, target, horizontal=True,
label=f"threshold {format_value(target, fmt, 5)}")
label=f"{word} {format_value(target, fmt, 5)}")

def read(px: float) -> list[tuple[QPointF, str]]:
i = min(n - 1, max(0, round(frame.value_at_x(px)) - 1))
Expand Down
15 changes: 10 additions & 5 deletions raptor/gui/ui/charts_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class _Entry:

#: The charts that draw a target line, where the Target button is shown.
TARGET_CHARTS = ("trial-outcome", "ecdf", "convergence", "availability-through-run",
"interval-availability", "availability-band")
"interval-availability", "availability-band", "availability-ladder",
"downtime-waterfall", "annual-fan", "annual-dots")

_RECORD_AO = ("These charts are drawn from the availability plot. "
+ run_needs.gui_hint("availability_plot"))
Expand Down Expand Up @@ -371,6 +372,10 @@ def _catalogue(self) -> list[_Entry]: # noqa: C901, PLR0915 - one table of char
periods = i.get("periods")
report_data = i.get("report_data") or []
target, units = i.get("target"), i.get("units") or ""
# The ladder, the waterfall and the year charts are availability
# whatever the headline measure is: a dependability target is not
# drawn on them.
a_target = target if (i.get("measure") or "availability") == "availability" else None
entries: list[_Entry] = []

def add(key: str, title: str, group: str,
Expand All @@ -395,7 +400,7 @@ def add(key: str, title: str, group: str,
lambda: charts.ecdf(per_run, measure, label=label, target=target,
units=units), no_runs)
add("availability-ladder", "Availability ladder", "The answer",
lambda: _with_run_id(charts.availability_ladder(_ladder(per_run)), i),
lambda: _with_run_id(charts.availability_ladder(_ladder(per_run), a_target), i),
no_runs)
add("convergence", "Has the run settled?", "The answer",
lambda: charts.convergence(per_run, measure, target=target),
Expand Down Expand Up @@ -448,7 +453,7 @@ def drivers_missing(_need: str = "") -> str:
("downtime-pareto", "Who causes the downtime",
lambda: charts.downtime_pareto(a), ""),
("downtime-waterfall", "Where availability is lost",
lambda: charts.downtime_waterfall(a, operational), ""),
lambda: charts.downtime_waterfall(a, operational, a_target), ""),
("downtime-treemap", "Downtime treemap",
lambda: charts.downtime_treemap(a), ""),
("phase-downtime", "Downtime by phase",
Expand Down Expand Up @@ -508,10 +513,10 @@ def drivers_missing(_need: str = "") -> str:
("attribution",) if not attribution and not action else ())
p = periods or {}
add("annual-fan", "Availability year by year", "Year by year",
lambda: charts.annual_fan(p), no_years, action if not attribution else "",
lambda: charts.annual_fan(p, a_target), no_years, action if not attribution else "",
needs=years_needs)
add("annual-dots", "A bad year, as a frequency", "Year by year",
lambda: charts.annual_dots(p), no_years, action if not attribution else "",
lambda: charts.annual_dots(p, a_target), no_years, action if not attribution else "",
needs=years_needs)
add("annual-capacity-fan", "Capacity delivered year by year", "Year by year",
lambda: charts.annual_capacity_fan(p),
Expand Down
34 changes: 33 additions & 1 deletion raptor/gui/ui/dock_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@
_SIDE = ("left", "right")



def _sync_maximise(button: QToolButton, dock: QDockWidget) -> None:
""""Restore" while the Results fill the screen in their own window."""
try:
full = dock.isFloating() and dock.isMaximized()
except RuntimeError: # torn down
return
button.setText("Restore" if full else "Maximise")
button.setToolTip("Put the Results back in the main window" if full
else "Show the Results full screen in their own window")


def _maximise_button(win: Any, dock: QDockWidget, layout: QHBoxLayout) -> QToolButton | None:
"""The Results' Maximise / Restore button (no other dock has one).

The bottom strip keeps the canvas's own minimum, so on a short screen
a chart could not be seen whole: Maximise gives the Results a window
of their own at full screen, Restore docks them again."""
if dock is not getattr(win, "_results_dock", None):
return None
button = QToolButton()
button.setAutoRaise(True)
button.setText("Maximise")
button.setToolTip("Show the Results full screen in their own window")
button.setAccessibleName("Maximise the Results")
button.clicked.connect(lambda _checked=False: win._maximise_results())
dock.topLevelChanged.connect(lambda _floating: _sync_maximise(button, dock))
layout.addWidget(button)
return button

class DockSlotChrome:
"""Title bars, minimise/restore and the closed stub for one dock slot."""

Expand Down Expand Up @@ -78,6 +108,8 @@ def _build_entry(self, dock: QDockWidget) -> dict[str, Any]:
tb.addWidget(label)
tb.addStretch(1)

max_btn = _maximise_button(win, dock, tb)

min_btn = QToolButton()
min_btn.setAutoRaise(True)
min_btn.setText(self.glyph_collapse)
Expand Down Expand Up @@ -124,7 +156,7 @@ def _build_entry(self, dock: QDockWidget) -> dict[str, Any]:
return {"dock": dock, "content": content,
"titlebar": titlebar, "icon_label": icon_label,
"label": label,
"min_btn": min_btn, "float_btn": float_btn,
"min_btn": min_btn, "float_btn": float_btn, "max_btn": max_btn,
"close_btn": close_btn, "stub": stub,
"edge": self.edge,
"normal_min_width": max(dock.minimumWidth(), 0),
Expand Down
Loading