feat(tui): add Diagnostics panel for stored evidence
Toggle a Diagnostics panel with i, built on the Activity readout. It swaps in for the Drive pane and shows the decoded critical_warning, power-on hours, power cycles, unsafe shutdowns, media errors and available spare with their change over the selection, and per-hour (Day) or per-day (History) temperature min/avg/max, active/idle/powered-off/unknown split and coverage. History bars draw reads beside writes while it is open, and a set critical_warning shows as a badge in the endurance outlook without affecting the projection. Counter deltas are withheld across a controller segment change.
This commit is contained in:
@@ -21,13 +21,19 @@ class VolumePoint:
|
||||
def volume_plot(
|
||||
points: Sequence[VolumePoint], width: int, height: int,
|
||||
selected: int, colors: Mapping[str, str],
|
||||
secondary: Sequence[VolumePoint] | None = None,
|
||||
) -> tuple[Text, list[int], str]:
|
||||
"""Render bounded axes and a dotted trace, without resampling evidence."""
|
||||
"""Render bounded axes and a dotted trace, without resampling evidence.
|
||||
|
||||
*secondary* is a second series over the same time axis (reads beside
|
||||
writes); it shares the volume scale and draws in its own colour.
|
||||
"""
|
||||
width, height = max(12, width), max(4, height)
|
||||
axis_width = 8
|
||||
columns, rows = width - axis_width, height - 2
|
||||
pixel_width, pixel_height = columns * 2, rows * 4
|
||||
maximum = max((p.volume or 0 for p in points), default=0)
|
||||
maximum = max(
|
||||
(p.volume or 0 for p in (*points, *(secondary or ()))), default=0)
|
||||
scale, unit = (1e12, "TB") if maximum >= 1e12 else (
|
||||
(1e9, "GB") if maximum >= 1e9 else
|
||||
(1e6, "MB") if maximum >= 1e6 else
|
||||
@@ -39,11 +45,16 @@ def volume_plot(
|
||||
xs = [round((p.time - start) / span * (pixel_width - 1)) if span else 0
|
||||
for p in points]
|
||||
cells = [[0] * columns for _ in range(rows)]
|
||||
second = [[0] * columns for _ in range(rows)]
|
||||
# Unicode braille dot numbering, indexed by y within cell and then x.
|
||||
bits = ((1, 8), (2, 16), (4, 32), (64, 128))
|
||||
|
||||
def dot(x: int, y: int) -> None:
|
||||
cells[y // 4][x // 2] |= bits[y % 4][x % 2]
|
||||
def dot(x: int, y: int, grid: list[list[int]] = cells) -> None:
|
||||
grid[y // 4][x // 2] |= bits[y % 4][x % 2]
|
||||
|
||||
def y_of(volume: int) -> int:
|
||||
y = round((1 - volume / ceiling) * (pixel_height - 1))
|
||||
return min(pixel_height - 1, max(0, y))
|
||||
|
||||
previous = None
|
||||
markers = {}
|
||||
@@ -53,8 +64,7 @@ def volume_plot(
|
||||
if point.state != "future":
|
||||
markers[x // 2] = "?"
|
||||
continue
|
||||
y = round((1 - point.volume / ceiling) * (pixel_height - 1))
|
||||
y = min(pixel_height - 1, max(0, y))
|
||||
y = y_of(point.volume)
|
||||
if previous is not None and point.state == "measured":
|
||||
px, py = previous
|
||||
steps = max(abs(x - px), abs(y - py), 1)
|
||||
@@ -68,6 +78,21 @@ def volume_plot(
|
||||
elif point.volume == 0:
|
||||
markers.setdefault(x // 2, "·")
|
||||
|
||||
previous = None
|
||||
for point, x in zip(secondary or (), xs):
|
||||
if point.volume is None:
|
||||
previous = None
|
||||
continue
|
||||
y = y_of(point.volume)
|
||||
if previous is not None and point.state == "measured":
|
||||
px, py = previous
|
||||
steps = max(abs(x - px), abs(y - py), 1)
|
||||
for step in range(steps + 1):
|
||||
dot(round(px + (x - px) * step / steps),
|
||||
round(py + (y - py) * step / steps), second)
|
||||
dot(x, y, second)
|
||||
previous = (x, y) if point.state == "measured" else None
|
||||
|
||||
selected_column = xs[selected] // 2 if 0 <= selected < len(xs) else -1
|
||||
result = Text(no_wrap=True, overflow="crop")
|
||||
ticks = {0, rows // 2, rows - 1}
|
||||
@@ -76,8 +101,10 @@ def volume_plot(
|
||||
label = f"{value:6.2f}"[-6:] if row in ticks else " "
|
||||
result.append(label + " │", style=colors["muted"])
|
||||
for col, value in enumerate(values):
|
||||
char = chr(0x2800 + value) if value else " "
|
||||
style = colors["allocated"]
|
||||
extra = second[row][col]
|
||||
char = chr(0x2800 + (value | extra)) if value | extra else " "
|
||||
style = colors["allocated"] if value or not extra else colors["secondary"]
|
||||
value |= extra
|
||||
if col == selected_column:
|
||||
style = "bold " + colors["selection"]
|
||||
if not value:
|
||||
|
||||
@@ -33,6 +33,26 @@ from .timefmt import (
|
||||
|
||||
LIVE_WINDOW_H = 3 # Rolling window for the live graph
|
||||
|
||||
# NVMe SMART critical warning bits (NVMe base specification, Get Log Page 02h).
|
||||
CRITICAL_WARNING_FLAGS = (
|
||||
(0x01, "available spare below threshold"),
|
||||
(0x02, "temperature outside threshold"),
|
||||
(0x04, "reliability degraded"),
|
||||
(0x08, "media in read-only mode"),
|
||||
(0x10, "volatile memory backup failed"),
|
||||
(0x20, "persistent memory region read-only"),
|
||||
)
|
||||
_KNOWN_WARNING_BITS = sum(bit for bit, _ in CRITICAL_WARNING_FLAGS)
|
||||
|
||||
# Drive counters shown with their change over the selection.
|
||||
DIAGNOSTIC_COUNTERS = (
|
||||
("power_on_hours", "Power-on hours", ""),
|
||||
("power_cycles", "Power cycles", ""),
|
||||
("unsafe_shutdowns", "Unsafe shutdowns", ""),
|
||||
("media_errors", "Media errors", ""),
|
||||
("available_spare", "Available spare", "%"),
|
||||
)
|
||||
|
||||
LOCAL_ACTIVITY_STATE_LABELS = {
|
||||
"so_far": "totals so far",
|
||||
"incomplete": "incomplete",
|
||||
@@ -55,6 +75,7 @@ class ActivityReadout:
|
||||
live: tuple[Dict[str, Any], ...]
|
||||
health: Dict[str, Any]
|
||||
local_day: Optional[Dict[str, Any]]
|
||||
diagnostics: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
def readout(
|
||||
@@ -68,18 +89,24 @@ def readout(
|
||||
hours: List[Dict[str, Any]] = []
|
||||
if selection.view == "day" and selection.browse_date is not None:
|
||||
hours = _query_local_hourly_graph_data(conn, local_day, now)
|
||||
days = tuple(_query_local_day_graph_data(
|
||||
conn, now, zone_name, selected_date=selection.browse_date,
|
||||
))
|
||||
health = _query_drive_health(conn)
|
||||
return ActivityReadout(
|
||||
view=selection.view,
|
||||
timezone_name=zone_name,
|
||||
timezone_label=tz_label(now, zone_name),
|
||||
local_date=local_date,
|
||||
days=tuple(_query_local_day_graph_data(
|
||||
conn, now, zone_name, selected_date=selection.browse_date,
|
||||
)),
|
||||
days=days,
|
||||
hours=tuple(hours),
|
||||
live=tuple(_query_live_graph_data(conn, now, zone_name)),
|
||||
health=_query_drive_health(conn),
|
||||
health=health,
|
||||
local_day=local_day,
|
||||
diagnostics=(
|
||||
_query_diagnostics(conn, selection, now, local_day, days, health)
|
||||
if selection.diagnostics else None
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -234,7 +261,8 @@ def _query_local_hourly_graph_data(
|
||||
rows = conn.execute(
|
||||
"SELECT hour, bytes_written_delta, bytes_read_delta, coverage, "
|
||||
"sample_count, unknown_seconds, active_seconds, idle_seconds, "
|
||||
"powered_off_seconds, temperature_min, temperature_max "
|
||||
"powered_off_seconds, temperature_min, temperature_max, "
|
||||
"temperature_avg "
|
||||
"FROM hour_observations WHERE hour >= ? AND hour <= ? ORDER BY hour",
|
||||
(first_hour.isoformat(), last_hour.isoformat()),
|
||||
).fetchall()
|
||||
@@ -251,7 +279,7 @@ def _query_local_hourly_graph_data(
|
||||
is_future = hour_start > current
|
||||
identity = hour_start.isoformat()
|
||||
active = idle = off = 0
|
||||
temp_min = temp_max = None
|
||||
temp_min = temp_avg = temp_max = None
|
||||
if row is None:
|
||||
written = read = coverage = sample_count = 0
|
||||
unknown_seconds = 0
|
||||
@@ -263,7 +291,7 @@ def _query_local_hourly_graph_data(
|
||||
sample_count = row[4] or 0
|
||||
unknown_seconds = row[5] or 0
|
||||
active, idle, off = row[6] or 0, row[7] or 0, row[8] or 0
|
||||
temp_min, temp_max = row[9], row[10]
|
||||
temp_min, temp_max, temp_avg = row[9], row[10], row[11]
|
||||
is_gap = sample_count == 0 and unknown_seconds > 0
|
||||
result.append({
|
||||
"hour": identity,
|
||||
@@ -280,6 +308,7 @@ def _query_local_hourly_graph_data(
|
||||
"powered_off_seconds": off,
|
||||
"unknown_seconds": unknown_seconds,
|
||||
"temperature_min": temp_min,
|
||||
"temperature_avg": temp_avg,
|
||||
"temperature_max": temp_max,
|
||||
"is_zero": written == 0 and read == 0 and not is_gap,
|
||||
"is_gap": is_gap,
|
||||
@@ -306,7 +335,7 @@ def _day_habit(conn: sqlite3.Connection, summary: Dict[str, Any]) -> Optional[Di
|
||||
"SELECT COUNT(*), COALESCE(SUM(active_seconds), 0), "
|
||||
"COALESCE(SUM(idle_seconds), 0), COALESCE(SUM(powered_off_seconds), 0), "
|
||||
"COALESCE(SUM(unknown_seconds), 0), MIN(temperature_min), "
|
||||
"MAX(temperature_max) FROM hour_observations "
|
||||
"MAX(temperature_max), AVG(temperature_avg) FROM hour_observations "
|
||||
"WHERE hour >= ? AND hour <= ?",
|
||||
(first_hour.isoformat(), (day_end - timedelta(hours=1)).isoformat()),
|
||||
).fetchone()
|
||||
@@ -319,6 +348,7 @@ def _day_habit(conn: sqlite3.Connection, summary: Dict[str, Any]) -> Optional[Di
|
||||
"unknown_seconds": row[4],
|
||||
"temperature_min": row[5],
|
||||
"temperature_max": row[6],
|
||||
"temperature_avg": row[7],
|
||||
}
|
||||
|
||||
|
||||
@@ -586,7 +616,7 @@ def _query_drive_health(conn: sqlite3.Connection) -> Dict[str, Any]:
|
||||
cursor = conn.execute(
|
||||
"SELECT mn, sn, fr, temperature_c, available_spare, media_errors, "
|
||||
"power_on_hours, power_cycles, unsafe_shutdowns, capacity_bytes, "
|
||||
"percentage_used, data_units_written "
|
||||
"percentage_used, data_units_written, critical_warning "
|
||||
"FROM samples ORDER BY id DESC LIMIT 1"
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
@@ -602,6 +632,7 @@ def _query_drive_health(conn: sqlite3.Connection) -> Dict[str, Any]:
|
||||
"capacity": "unknown",
|
||||
"percentage_used": 0,
|
||||
"written_tb": 0,
|
||||
"critical_warning": 0,
|
||||
}
|
||||
|
||||
capacity = row[9]
|
||||
@@ -619,6 +650,124 @@ def _query_drive_health(conn: sqlite3.Connection) -> Dict[str, Any]:
|
||||
"capacity": capacity_str,
|
||||
"percentage_used": row[10] or 0,
|
||||
"written_tb": written_tb,
|
||||
"critical_warning": row[12] or 0,
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Diagnostics (issue #109)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def decode_critical_warning(value: int | None) -> tuple[str, ...]:
|
||||
"""Name each NVMe critical-warning bit that is set; reserved bits are flagged."""
|
||||
value = value or 0
|
||||
flags = [name for bit, name in CRITICAL_WARNING_FLAGS if value & bit]
|
||||
if value & ~_KNOWN_WARNING_BITS:
|
||||
flags.append("unrecognised bits 0x%02x" % (value & ~_KNOWN_WARNING_BITS))
|
||||
return tuple(flags)
|
||||
|
||||
|
||||
def critical_warning_badge(health: Dict[str, Any]) -> str:
|
||||
"""Outlook badge for a set critical warning; empty when the drive reports none.
|
||||
|
||||
A drive-reported fact only (ADR 0005): it never changes the projection.
|
||||
"""
|
||||
value = health.get("critical_warning") or 0
|
||||
if not value:
|
||||
return ""
|
||||
return "[bold yellow]![/bold yellow] [bold]Drive reports critical warning 0x%02x[/bold] · %s" % (
|
||||
value, ", ".join(decode_critical_warning(value)),
|
||||
)
|
||||
|
||||
|
||||
def _counter_deltas(
|
||||
conn: sqlite3.Connection, start: datetime | None, end: datetime,
|
||||
) -> Dict[str, Dict[str, Optional[int]]]:
|
||||
"""Latest counter values and their change across a window of raw samples.
|
||||
|
||||
The baseline is the last sample at or before *start*, else the first sample
|
||||
inside the window; with fewer than two distinct samples, or across a
|
||||
controller-segment change, there is no delta.
|
||||
"""
|
||||
columns = ", ".join(key for key, _, _ in DIAGNOSTIC_COUNTERS)
|
||||
columns += ", segment_id"
|
||||
last = conn.execute(
|
||||
"SELECT id, %s FROM samples WHERE ts <= ? ORDER BY ts DESC, id DESC "
|
||||
"LIMIT 1" % columns, (end.isoformat(),),
|
||||
).fetchone()
|
||||
first = None
|
||||
if start is not None and last is not None:
|
||||
first = conn.execute(
|
||||
"SELECT id, %s FROM samples WHERE ts <= ? ORDER BY ts DESC, id DESC "
|
||||
"LIMIT 1" % columns, (start.isoformat(),),
|
||||
).fetchone() or conn.execute(
|
||||
"SELECT id, %s FROM samples WHERE ts > ? AND ts <= ? "
|
||||
"ORDER BY ts, id LIMIT 1" % columns,
|
||||
(start.isoformat(), end.isoformat()),
|
||||
).fetchone()
|
||||
result: Dict[str, Dict[str, Optional[int]]] = {}
|
||||
for offset, (key, _, _) in enumerate(DIAGNOSTIC_COUNTERS, start=1):
|
||||
value = last[offset] if last is not None else None
|
||||
delta = None
|
||||
if first is not None and first[0] != last[0] and first[-1] == last[-1] and None not in (
|
||||
value, first[offset],
|
||||
):
|
||||
delta = value - first[offset]
|
||||
result[key] = {"value": value, "delta": delta}
|
||||
return result
|
||||
|
||||
|
||||
def _diagnostics_window(
|
||||
selection: ActivitySelection,
|
||||
now: datetime,
|
||||
local_day: Optional[Dict[str, Any]],
|
||||
days: tuple[Dict[str, Any], ...],
|
||||
) -> tuple[str, datetime | None, datetime]:
|
||||
"""Label and UTC bounds of what the selection covers."""
|
||||
if selection.view == "live":
|
||||
return "last %dh" % LIVE_WINDOW_H, now - timedelta(hours=LIVE_WINDOW_H), now
|
||||
if selection.view == "day":
|
||||
label = "day %s" % (selection.browse_date or "")
|
||||
if local_day is None:
|
||||
return label, None, now
|
||||
end = min(_parse_ts(local_day["utc_end"]), now)
|
||||
return label, _parse_ts(local_day["utc_start"]), end
|
||||
start = next((
|
||||
_parse_ts(day["identity"].utc_start)
|
||||
for day in days if day["identity"] is not None
|
||||
), None)
|
||||
return "last %d days" % selection.history_range_days, start, now
|
||||
|
||||
|
||||
def _query_diagnostics(
|
||||
conn: sqlite3.Connection,
|
||||
selection: ActivitySelection,
|
||||
now: datetime,
|
||||
local_day: Optional[Dict[str, Any]],
|
||||
days: tuple[Dict[str, Any], ...],
|
||||
health: Dict[str, Any],
|
||||
) -> Dict[str, Any]:
|
||||
"""Stored diagnostic evidence for the selection: warning, counters, habit."""
|
||||
visible = days[-selection.history_range_days:]
|
||||
label, start, end = _diagnostics_window(selection, now, local_day, visible)
|
||||
warning = health["critical_warning"]
|
||||
habit_days: List[Dict[str, Any]] = []
|
||||
if selection.view == "history":
|
||||
for day in visible:
|
||||
identity = day["identity"]
|
||||
if identity is None:
|
||||
continue
|
||||
summary = query_local_day_summary(
|
||||
conn, identity.local_date, identity.timezone, now)
|
||||
habit = _day_habit(conn, summary) if summary is not None else None
|
||||
if habit is not None:
|
||||
habit_days.append(dict(habit, day=identity.local_date))
|
||||
return {
|
||||
"window_label": label,
|
||||
"critical_warning": warning,
|
||||
"critical_warning_flags": decode_critical_warning(warning),
|
||||
"counters": _counter_deltas(conn, start, end),
|
||||
"days": tuple(habit_days),
|
||||
}
|
||||
|
||||
|
||||
@@ -792,3 +941,91 @@ def local_day_text(local_date: str, local: Dict[str, Any] | None) -> str:
|
||||
habit["temperature_min"], habit["temperature_max"],
|
||||
))
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def _temperature_triplet(
|
||||
low: float | None, avg: float | None, high: float | None,
|
||||
) -> str:
|
||||
"""Temperature as min/avg/max, or a plain note when none was recorded."""
|
||||
if low is None or high is None:
|
||||
return "no temp"
|
||||
mid = "%d" % round(avg) if avg is not None else "-"
|
||||
return "%d/%s/%d°C" % (low, mid, high)
|
||||
|
||||
|
||||
def _signed(delta: int) -> str:
|
||||
"""Counter change with an explicit sign; zero reads as no change."""
|
||||
return "%+d" % delta if delta else "±0"
|
||||
|
||||
|
||||
def _hour_diagnostic_line(hour: Dict[str, Any]) -> str:
|
||||
"""One compact row: hour, temperature, state split in minutes, coverage."""
|
||||
head = hour.get("local_label", "")
|
||||
if hour.get("is_future"):
|
||||
return "%s future" % head
|
||||
if hour.get("is_gap"):
|
||||
return "%s gap" % head
|
||||
minutes = lambda key: (hour.get(key) or 0) // 60 # noqa: E731
|
||||
return "%s %s A%dm I%dm Off%dm ?%dm %d%%" % (
|
||||
head,
|
||||
_temperature_triplet(
|
||||
hour.get("temperature_min"), hour.get("temperature_avg"),
|
||||
hour.get("temperature_max")),
|
||||
minutes("active_seconds"), minutes("idle_seconds"),
|
||||
minutes("powered_off_seconds"), minutes("unknown_seconds"),
|
||||
hour.get("coverage", 0) * 100,
|
||||
)
|
||||
|
||||
|
||||
def _day_diagnostic_line(day: Dict[str, Any]) -> str:
|
||||
"""One compact row: day, state split, temperature."""
|
||||
return "%s A%s I%s Off%s ?%s %s" % (
|
||||
day["day"][5:],
|
||||
_duration(day["active_seconds"]), _duration(day["idle_seconds"]),
|
||||
_duration(day["powered_off_seconds"]), _duration(day["unknown_seconds"]),
|
||||
_temperature_triplet(
|
||||
day["temperature_min"], day["temperature_avg"], day["temperature_max"]),
|
||||
)
|
||||
|
||||
|
||||
def _live_temperature_line(live: tuple[Dict[str, Any], ...]) -> str:
|
||||
"""Interval count and interval-end temperature range for the live window."""
|
||||
temps = [p["temperature_c"] for p in live if p.get("temperature_c") is not None]
|
||||
line = "%d intervals" % len(live)
|
||||
if temps:
|
||||
line = "%d intervals · %s" % (len(live), _temperature_triplet(
|
||||
min(temps), sum(temps) / len(temps), max(temps)))
|
||||
warned = sum(1 for p in live if p.get("critical_warning"))
|
||||
if warned:
|
||||
line += " · %d with critical warning" % warned
|
||||
return line
|
||||
|
||||
|
||||
def diagnostics_text(activity: ActivityReadout) -> str:
|
||||
"""Dense Diagnostics panel text for the readout's selection."""
|
||||
diag = activity.diagnostics
|
||||
if diag is None:
|
||||
return "Diagnostics unavailable"
|
||||
warning = diag["critical_warning"]
|
||||
lines = [
|
||||
"[bold]Diagnostics[/bold] · %s" % diag["window_label"],
|
||||
"Critical warning " + (
|
||||
"0x%02x · %s" % (warning, ", ".join(diag["critical_warning_flags"]))
|
||||
if warning else "none"),
|
||||
]
|
||||
for key, label, unit in DIAGNOSTIC_COUNTERS:
|
||||
counter = diag["counters"][key]
|
||||
if counter["value"] is None:
|
||||
lines.append("%s n/a" % label)
|
||||
continue
|
||||
delta = "Δ n/a" if counter["delta"] is None else "Δ " + _signed(counter["delta"])
|
||||
lines.append("%s %d%s %s" % (label, counter["value"], unit, delta))
|
||||
if activity.view == "live":
|
||||
lines += ["", _live_temperature_line(activity.live)]
|
||||
elif activity.view == "day":
|
||||
lines += ["", "Hours · temp min/avg/max · A active I idle Off off ? unknown · coverage"]
|
||||
lines += [_hour_diagnostic_line(hour) for hour in activity.hours]
|
||||
else:
|
||||
lines += ["", "Days · A active I idle Off off ? unknown · temp min/avg/max"]
|
||||
lines += [_day_diagnostic_line(day) for day in diag["days"]]
|
||||
return "\n".join(lines)
|
||||
|
||||
@@ -35,6 +35,7 @@ class ActivitySelection:
|
||||
self.selected_history_hour: str | None = None
|
||||
self.history_range_days = HISTORY_RANGE_DEFAULT
|
||||
self.measure = "written"
|
||||
self.diagnostics = False
|
||||
self.following_live = True
|
||||
self.selected_live_interval: IntervalIdentity | None = None
|
||||
self.live_interval_expired = False
|
||||
@@ -74,6 +75,11 @@ class ActivitySelection:
|
||||
self.measure = "read" if self.measure == "written" else "written"
|
||||
return self.measure
|
||||
|
||||
def toggle_diagnostics(self) -> bool:
|
||||
"""Show or hide the Diagnostics panel and read-beside-write bars."""
|
||||
self.diagnostics = not self.diagnostics
|
||||
return self.diagnostics
|
||||
|
||||
def follow_live(self) -> None:
|
||||
"""Resume following the newest interval and clear stale-pin notices."""
|
||||
self.view = "live"
|
||||
|
||||
@@ -161,14 +161,15 @@ def get_theme(name: str) -> Theme:
|
||||
def get_graph_colors(theme_name: str) -> Dict[str, str]:
|
||||
"""Return the graph colour roles for a theme preset.
|
||||
|
||||
Returns a dict with keys: allocated, unallocated, gap, zero, partial,
|
||||
selection and muted text. Falls back to Chalktone for unknown names.
|
||||
Returns a dict with keys: allocated, unallocated, secondary (the second
|
||||
series), gap, zero, partial, selection and muted text. Falls back to Chalktone for unknown names.
|
||||
"""
|
||||
theme = get_theme(theme_name)
|
||||
variables = theme.variables or {}
|
||||
return {
|
||||
"allocated": variables.get("graph-allocated", "#d4a017"),
|
||||
"unallocated": variables.get("graph-unallocated", "#8b6914"),
|
||||
"secondary": variables.get("graph-unallocated", "#8b6914"),
|
||||
"gap": variables.get("graph-gap", "#554422"),
|
||||
"zero": variables.get("graph-zero", "#665533"),
|
||||
"partial": variables.get("graph-partial", "#aa8822"),
|
||||
|
||||
+70
-20
@@ -34,7 +34,9 @@ from textual.widgets import Input, Static, Tab, Tabs
|
||||
|
||||
from .activity_readout import (
|
||||
LIVE_WINDOW_H,
|
||||
critical_warning_badge,
|
||||
day_readout_text,
|
||||
diagnostics_text,
|
||||
hour_readout_text,
|
||||
interval_readout_text,
|
||||
local_day_text,
|
||||
@@ -460,19 +462,19 @@ class HistoryGraph(Widget):
|
||||
)
|
||||
self.query_one("#bar-range").update(label)
|
||||
|
||||
def _render_bars(self) -> None:
|
||||
def _day_points(self, measure: str) -> list[VolumePoint]:
|
||||
points = []
|
||||
for index, day in enumerate(self._day_data):
|
||||
if "activity_state" in day:
|
||||
volume = day.get("total_read") if self.measure == "read" else day.get("total_bytes")
|
||||
volume = day.get("total_read") if measure == "read" else day.get("total_bytes")
|
||||
unallocated = day.get(
|
||||
"shared_bytes_read" if self.measure == "read" else "shared_bytes_written",
|
||||
"shared_bytes_read" if measure == "read" else "shared_bytes_written",
|
||||
0,
|
||||
)
|
||||
else:
|
||||
volume = day.get("total_read", 0) if self.measure == "read" else day.get("total_bytes", 0)
|
||||
volume = day.get("total_read", 0) if measure == "read" else day.get("total_bytes", 0)
|
||||
unallocated = day.get(
|
||||
"unallocated_read" if self.measure == "read" else "unallocated_bytes",
|
||||
"unallocated_read" if measure == "read" else "unallocated_bytes",
|
||||
0,
|
||||
)
|
||||
state = "unallocated" if unallocated else "gap" if day.get("is_gap") else (
|
||||
@@ -480,19 +482,35 @@ class HistoryGraph(Widget):
|
||||
)
|
||||
points.append(VolumePoint(index, None if state == "gap" else volume,
|
||||
day.get("day", "")[5:], state))
|
||||
self._plot(points, self.selected_index)
|
||||
return points
|
||||
|
||||
def _plot(self, points: list[VolumePoint], selected: int) -> None:
|
||||
def _render_bars(self) -> None:
|
||||
self._plot(
|
||||
self._day_points(self.measure), self.selected_index,
|
||||
self._day_points("written" if self.measure == "read" else "read"),
|
||||
)
|
||||
|
||||
def _plot(
|
||||
self, points: list[VolumePoint], selected: int,
|
||||
other: list[VolumePoint] | None = None,
|
||||
) -> None:
|
||||
"""Draw *points*; with Diagnostics on, *other* is drawn beside them."""
|
||||
both = self.selection.diagnostics and other is not None
|
||||
target = self.query_one("#bar-render")
|
||||
colors = get_graph_colors(getattr(self.app, "_current_theme_name", "chalktone"))
|
||||
chart, self._point_columns, unit = volume_plot(
|
||||
points, target.content_size.width or 40, target.content_size.height or 8,
|
||||
selected, colors,
|
||||
selected, colors, other if both else None,
|
||||
)
|
||||
target.update(chart)
|
||||
names = ("Reads", "Writes") if self.measure == "read" else ("Writes", "Reads")
|
||||
series = (
|
||||
"[%s]%s[/] · [%s]%s[/]" % (
|
||||
colors["allocated"], names[0], colors["secondary"], names[1])
|
||||
if both else names[0]
|
||||
)
|
||||
self.query_one("#bar-legend").update(
|
||||
("Reads" if self.measure == "read" else "Writes")
|
||||
+ " (%s) · ? Gap · · Zero · ~ Partial · u Unalloc" % unit
|
||||
series + " (%s) · ? Gap · · Zero · ~ Partial · u Unalloc" % unit
|
||||
)
|
||||
|
||||
def _render_readout(self) -> None:
|
||||
@@ -530,15 +548,21 @@ class HistoryGraph(Widget):
|
||||
self._show_constrained_hourly_summary()
|
||||
return
|
||||
|
||||
points = []
|
||||
for index, hour in enumerate(self._hour_data):
|
||||
state = "future" if hour.get("is_future") else (
|
||||
"gap" if hour.get("is_gap") else "partial" if hour.get("is_partial") else "measured"
|
||||
)
|
||||
volume = hour.get("bytes_read" if self.measure == "read" else "bytes_written", 0)
|
||||
points.append(VolumePoint(index, None if state in ("future", "gap") else volume,
|
||||
hour.get("local_label", ""), state))
|
||||
self._plot(points, self._hourly_selected)
|
||||
def hour_points(measure: str) -> list[VolumePoint]:
|
||||
points = []
|
||||
for index, hour in enumerate(self._hour_data):
|
||||
state = "future" if hour.get("is_future") else (
|
||||
"gap" if hour.get("is_gap") else "partial" if hour.get("is_partial") else "measured"
|
||||
)
|
||||
volume = hour.get("bytes_read" if measure == "read" else "bytes_written", 0)
|
||||
points.append(VolumePoint(index, None if state in ("future", "gap") else volume,
|
||||
hour.get("local_label", ""), state))
|
||||
return points
|
||||
|
||||
self._plot(
|
||||
hour_points(self.measure), self._hourly_selected,
|
||||
hour_points("written" if self.measure == "read" else "read"),
|
||||
)
|
||||
|
||||
self._render_hourly_readout()
|
||||
|
||||
@@ -1241,6 +1265,7 @@ class FenrisTuiApp(App):
|
||||
border-title-color: $accent;
|
||||
}
|
||||
#activity-panel { row-span: 2; height: 100%; }
|
||||
#diagnostics-panel { display: none; }
|
||||
#headline-band, #drive-health { height: auto; }
|
||||
#activity-tabs { height: 1; margin: 0; }
|
||||
#activity-tabs Underline { display: none; }
|
||||
@@ -1267,6 +1292,7 @@ class FenrisTuiApp(App):
|
||||
height: auto; min-height: 0;
|
||||
}
|
||||
#main-grid.constrained #endurance-panel { max-height: 16; }
|
||||
#main-grid.constrained #diagnostics-panel { max-height: 20; }
|
||||
#main-grid.constrained.zoomed .zoom-target { height: 24; }
|
||||
#confirm-text, #disc-text, #help-text { padding: 1 2; }
|
||||
"""
|
||||
@@ -1277,6 +1303,7 @@ class FenrisTuiApp(App):
|
||||
Binding("c", "collect", "Collect"),
|
||||
Binding("b", "baseline", "Rated TBW"),
|
||||
Binding("d", "disclose", "Disclosures"),
|
||||
Binding("i", "toggle_diagnostics", "Diagnostics"),
|
||||
Binding("z", "toggle_zoom", "Zoom"),
|
||||
Binding("escape", "exit_zoom", "Restore zoom", show=False),
|
||||
Binding("v", "next_view", "View"),
|
||||
@@ -1324,6 +1351,7 @@ class FenrisTuiApp(App):
|
||||
self._is_constrained_mode = False
|
||||
|
||||
self._zoomed_panel: Optional[str] = None
|
||||
self._outlook_badge = ""
|
||||
|
||||
@property
|
||||
def _browse_date(self) -> Optional[str]:
|
||||
@@ -1367,6 +1395,8 @@ class FenrisTuiApp(App):
|
||||
)
|
||||
with VerticalScroll(id="drive-panel", classes="dashboard-pane"):
|
||||
yield Static("", id="drive-health")
|
||||
with VerticalScroll(id="diagnostics-panel", classes="dashboard-pane"):
|
||||
yield Static("", id="diagnostics")
|
||||
with VerticalScroll(id="status-area"):
|
||||
yield Static("", id="service-strip")
|
||||
yield Static("", id="action-rail")
|
||||
@@ -1376,6 +1406,7 @@ class FenrisTuiApp(App):
|
||||
self.query_one("#endurance-panel").border_title = "Endurance outlook"
|
||||
self.query_one("#activity-panel").border_title = "Drive activity"
|
||||
self.query_one("#drive-panel").border_title = "Drive"
|
||||
self.query_one("#diagnostics-panel").border_title = "Diagnostics"
|
||||
self.query_one("#live-activity").border_title = "Live activity"
|
||||
# Tab visits panels only: scroll hosts and the view tabs stay out of the order.
|
||||
for selector in ("#dashboard-scroll", "#status-area", "#activity-tabs"):
|
||||
@@ -1494,6 +1525,8 @@ class FenrisTuiApp(App):
|
||||
self._refresh()
|
||||
|
||||
def _render_headline(self, body: str = "") -> None:
|
||||
if self._outlook_badge:
|
||||
body = self._outlook_badge + "\n" + body
|
||||
self.query_one("#identity").update(_IDENTITY_FULL if _can_render_wolf(self.size.width) else _IDENTITY_FALLBACK)
|
||||
self.query_one("#auth-notice").display = self._show_auth_notice
|
||||
self.query_one("#headline-band").update(body)
|
||||
@@ -1535,6 +1568,8 @@ class FenrisTuiApp(App):
|
||||
|
||||
def _render_empty_or_fault(self, comp: StatusComposition) -> None:
|
||||
"""Render empty history or the shared store-fault classification."""
|
||||
self._outlook_badge = ""
|
||||
self.query_one("#diagnostics").update("Diagnostics unavailable: no observations to read")
|
||||
self._show_baseline_banner(not (comp.newer_schema or comp.store_fault))
|
||||
if comp.newer_schema or comp.store_fault:
|
||||
message = comp.explanation[:1].upper() + comp.explanation[1:]
|
||||
@@ -1571,6 +1606,8 @@ class FenrisTuiApp(App):
|
||||
|
||||
def _render_all_regions(self, conn: sqlite3.Connection, comp: StatusComposition) -> None:
|
||||
"""Render all four regions from live store data."""
|
||||
activity = readout(conn, self._activity_selection, self._clock_now)
|
||||
self._outlook_badge = critical_warning_badge(activity.health)
|
||||
# --- Headline band (§7.2) ---
|
||||
if comp.sample_count == 0 and comp.day_count == 0:
|
||||
self._show_baseline_banner(
|
||||
@@ -1596,7 +1633,6 @@ class FenrisTuiApp(App):
|
||||
self._render_headline("[bold]No projection available[/bold]")
|
||||
|
||||
# --- Activity panel: live and historical volume plots ---
|
||||
activity = readout(conn, self._activity_selection, self._clock_now)
|
||||
graph = self.query_one("#usage-history")
|
||||
graph.set_data(
|
||||
list(activity.days), on_drill=self._on_graph_drill,
|
||||
@@ -1627,6 +1663,7 @@ class FenrisTuiApp(App):
|
||||
health["written_tb"],
|
||||
)
|
||||
self.query_one("#drive-health").update(health_text)
|
||||
self.query_one("#diagnostics").update(diagnostics_text(activity))
|
||||
|
||||
# --- Live activity graph (issue #91) ---
|
||||
self.query_one("#live-activity").set_data(list(activity.live))
|
||||
@@ -1694,6 +1731,7 @@ class FenrisTuiApp(App):
|
||||
activity = readout(conn, self._activity_selection, self._clock_now)
|
||||
graph.set_hour_data(list(activity.hours))
|
||||
self._render_local_day(activity.local_date, activity.local_day)
|
||||
self.query_one("#diagnostics").update(diagnostics_text(activity))
|
||||
|
||||
def _format_headline(self, proj: ProjectionResult) -> str:
|
||||
"""Format the lifespan headline (spec §6.11)."""
|
||||
@@ -1884,6 +1922,18 @@ class FenrisTuiApp(App):
|
||||
"""Show disclosures (spec §6.11, CI-4)."""
|
||||
self.push_screen(DisclosuresScreen())
|
||||
|
||||
def action_toggle_diagnostics(self) -> None:
|
||||
"""Swap the Drive pane for the Diagnostics panel and back."""
|
||||
self.action_exit_zoom()
|
||||
showing = self._activity_selection.toggle_diagnostics()
|
||||
self.query_one("#diagnostics-panel").display = showing
|
||||
self.query_one("#drive-panel").display = not showing
|
||||
hidden = self.query_one("#drive-panel" if showing else "#diagnostics-panel")
|
||||
if self.focused is None or hidden in self.focused.ancestors_with_self:
|
||||
self.query_one("#live-activity" if self._activity_view == "live" else "#usage-history").focus(
|
||||
scroll_visible=not self._is_constrained_mode)
|
||||
self._refresh()
|
||||
|
||||
def action_help(self) -> None:
|
||||
"""Show keyboard controls and sudo guidance."""
|
||||
self.push_screen(HelpScreen())
|
||||
|
||||
Reference in New Issue
Block a user