diff --git a/meshterm/persistence/repository.py b/meshterm/persistence/repository.py index ac0d8d1..0b804db 100644 --- a/meshterm/persistence/repository.py +++ b/meshterm/persistence/repository.py @@ -28,15 +28,28 @@ from ..core.models import ( from . import db -#: The trailing window a channel's recent-activity view is computed over. Two hours is -#: "what's happening right now" territory: the activity sparkline reads as a live pulse of -#: the mesh rather than a long-term traffic log (the MSGS lane covers all-time volume). -ACTIVITY_WINDOW = timedelta(hours=2) +#: The trailing window the dashboard's live observation stats and packet feed prune to +#: — "what's happening right now" territory, labelled "reception over 2 h" on the RF +#: health card. Distinct from the deeper channel-activity window below: this bounds a +#: live view, that one only feeds a scaling peak. +OBSERVATION_WINDOW = timedelta(hours=2) -#: How many equal time buckets the activity window is split into — one per column of the -#: channel manager's braille sparkline (two columns per braille cell, so 24 buckets fill -#: its twelve characters). At a two-hour window each bucket spans five minutes. -ACTIVITY_BUCKETS = 24 +#: The trailing window a channel's activity histogram is computed over. Six hours is +#: deeper than the sparkline draws (see :data:`ACTIVITY_DRAWN_BUCKETS`) on purpose: the +#: extra history is what the shared scaling peak decays over, so it glides rather than +#: snaps as a busy stretch ages out (see :func:`~meshterm.ui.braillechart.activity_peak`). +#: All-time volume still lives in the MSGS lane; this stays a live-pulse window. +ACTIVITY_WINDOW = timedelta(hours=6) + +#: How many equal time buckets the window is split into — at six hours, five minutes each +#: (matching the drawn cadence). The histogram carries all of them for the scaling peak; +#: only the newest :data:`ACTIVITY_DRAWN_BUCKETS` are actually charted. +ACTIVITY_BUCKETS = 72 + +#: How many of the histogram's newest buckets the channel sparkline draws — two hours at +#: five minutes each, two columns per braille cell, so 24 buckets fill its twelve +#: characters. The rest of :data:`ACTIVITY_BUCKETS` feeds the scaling peak but isn't shown. +ACTIVITY_DRAWN_BUCKETS = 24 def _packet_raw(row: sqlite3.Row) -> Optional[dict]: @@ -107,7 +120,10 @@ class ChannelStats: histogram: The window's messages split into :data:`ACTIVITY_BUCKETS` equal time buckets, *newest first* — bucket 0 is the current five minutes, the order :func:`~meshterm.ui.braillechart.activity_sparkline` expects (it flips the - window so "now" draws at the right edge). ``recent`` is always its sum. + window so "now" draws at the right edge). ``recent`` is always its sum. The + sparkline charts only the newest :data:`ACTIVITY_DRAWN_BUCKETS`; the deeper + tail feeds the shared scaling peak (see + :func:`~meshterm.ui.braillechart.activity_peak`). """ total: int @@ -1562,10 +1578,11 @@ class Repository: Backs the channel manager's list lanes: each configured channel's row shows its total message count, the age of its last message, and an activity sparkline over the trailing :data:`ACTIVITY_WINDOW` — whose :data:`ACTIVITY_BUCKETS`-column - histogram is built here. Two passes, each grouped/filtered in SQL so the cost - tracks message volume, not channel count: an aggregate for the all-time totals, - then the window's individual timestamps, bucketed in Python (the window holds at - most two hours of chatter, so the row set stays small). + histogram is built here (the sparkline draws its newest + :data:`ACTIVITY_DRAWN_BUCKETS`; the rest feeds the shared scaling peak). Two + passes, each grouped/filtered in SQL so the cost tracks message volume, not + channel count: an aggregate for the all-time totals, then the window's individual + timestamps, bucketed in Python (a few hours of chatter, so the row set stays small). Timestamps are compared as strings: every ``created_at`` is written by ``utcnow().isoformat()`` (a fixed-width UTC ISO-8601 form), so lexicographic order diff --git a/meshterm/ui/braillechart.py b/meshterm/ui/braillechart.py index 358691e..7aa12b3 100644 --- a/meshterm/ui/braillechart.py +++ b/meshterm/ui/braillechart.py @@ -179,16 +179,16 @@ def activity_sparkline( repository keep — and is reversed here, so the current bucket lands on the right edge and traffic slides *left* as it ages, like every other MeshTerm timeline. - ``peak`` is the scaling ceiling, and it is how several sparklines drawn together - share one scale. Left ``None``, each sparkline self-scales to *its own* window's - busiest bucket — right for a chart that stands alone (the header pulse, alone on - its row). Passed a value, every sparkline handed the same one shares a scale, so - their bar heights are directly comparable — how the channel manager draws a whole - column of per-channel rows against the busiest channel on screen. The caller - computes that shared peak from the same data all the rows draw from (see the - channel manager's ``_LiveStats.peak``) and hands each row the one value; there is - deliberately no hidden cross-instance state here, so the scale is a pure function - of what each call is given. + ``peak`` is the scaling ceiling. Left ``None``, each sparkline self-scales to *its + own* drawn window's busiest bucket — the plain, jumpy relative scale. Passed a + value, that value is the ceiling, which does two things: it lets several sparklines + handed the *same* one share a scale so their bar heights are directly comparable + (a whole column of per-channel rows against the busiest channel on screen), and it + lets the caller substitute a *steadier* ceiling than the bare window maximum. + :func:`activity_peak` builds that steady, shared ceiling — a recency-weighted, + outlier-robust, floored peak over a deeper history than is drawn — and both the + header pulse and the channel manager pass its result here. The scale is otherwise a + pure function of what each call is given: no hidden cross-instance state lives here. Args: histogram: Per-bucket counts, newest first; padded/cropped to ``buckets``. @@ -224,6 +224,96 @@ def activity_sparkline( )[0] +#: Default half-life, in minutes, of :func:`activity_peak`'s recency weighting: a +#: bucket this many minutes old counts half as much toward the ceiling as the current +#: one, so an aging burst releases its grip on the scale smoothly (over minutes) rather +#: than snapping the instant it scrolls off the drawn window. One figure drives every +#: activity surface, so the pulse "feels" the same whether its buckets are one minute +#: (the header) or five (the channel rows) wide. +ACTIVITY_HALF_LIFE_MIN = 30.0 + +#: Default percentile :func:`activity_peak` reads its ceiling at, in place of the raw +#: maximum: a lone freak-busy bucket sits *above* this and clips to full height instead +#: of redefining the whole scale, so one outlier minute doesn't flatten every other bar. +#: High enough that ordinary sustained traffic still reaches the top. +ACTIVITY_PERCENTILE = 90.0 + + +def _percentile(values: Sequence[float], p: float) -> float: + """The linear-interpolated ``p``-th percentile of ``values`` (``0.0`` when empty). + + The two ranks either side of the fractional position blended together — NumPy's + default convention — so a small sample moves the mark smoothly instead of in + whole-element jumps. + """ + if not values: + return 0.0 + ordered = sorted(values) + if len(ordered) == 1: + return ordered[0] + rank = (p / 100.0) * (len(ordered) - 1) + lo = int(rank) + hi = min(lo + 1, len(ordered) - 1) + return ordered[lo] + (ordered[hi] - ordered[lo]) * (rank - lo) + + +def activity_peak( + *histograms: Sequence[int], + bucket_seconds: float, + half_life_min: float = ACTIVITY_HALF_LIFE_MIN, + percentile: float = ACTIVITY_PERCENTILE, + floor: float = 0.0, +) -> float: + """A steady scaling ceiling for :func:`activity_sparkline`, from newest-first counts. + + Relative-to-peak scaling reads its shape well but is jumpy: the plain window + maximum lurches whenever the busiest bucket enters or ages out of view, and a lone + packet in a quiet window fills the column because it *is* the maximum. This folds + three dampers into one ceiling, each acting on a different axis, so a whole column + of sparklines — or one that slides bucket by bucket — stays legible: + + * **Recency.** Each bucket's contribution is discounted by its age + (``count * decay ** age``), ``decay`` set from ``half_life_min`` and the bucket + width, so a burst weighs full when it happens and fades over minutes as it ages: + the ceiling *glides* down rather than snapping when the burst leaves the drawn + window. Handing this a deeper history than is drawn (the header's six hours, the + channel pool's) is what gives it the room to glide. + * **Robustness.** The ceiling is a high ``percentile`` of those weighted counts, + not their maximum, so a single freak-busy bucket sits above it and clips to full + height instead of shrinking every other bar to redefine the scale. + * **Floor.** The result never drops below ``floor``, so a stray packet in a + long-silent window draws a small nub against a meaningful scale instead of + shouting at full height. It is also the scale when everything is silent. + + Several histograms pool into one ceiling — every visible channel's, say — so a + column of rows shares one scale and their bars stay directly comparable (each + bucket is weighted by its own age, consistent across the histograms since bucket + ``i`` is the same age in every one). The result is a pure function of the counts + handed in: no hidden cross-frame state, so it is deterministic and decays on its + own as the data does. Pass it to each sparkline's ``peak``. + + Args: + histograms: One or more newest-first count series (bucket 0 is "now"); their + non-zero buckets pool into the ceiling. + bucket_seconds: How many seconds one bucket spans, so ``half_life_min`` reads + in real time whatever the bucket width. + half_life_min: Age, in minutes, at which a bucket's weight halves. + percentile: The percentile of weighted counts the ceiling reads (0–100). + floor: The lowest the ceiling may fall to (also the all-silent scale). + + Returns: + The scaling ceiling, ``>= floor``. + """ + decay = 0.5 ** ((bucket_seconds / 60.0) / half_life_min) if half_life_min > 0 else 0.0 + weighted = [ + count * decay**age + for histogram in histograms + for age, count in enumerate(histogram) + if count > 0 + ] + return max(float(floor), _percentile(weighted, percentile)) + + #: The meter's fill glyphs, ``(full step, half step)``, by profile. A *full-height* #: meter lights the top three dot rows and leaves the bottom row blank (``⠿`` both #: columns, ``⠇`` the left column alone), reading as a solid tally bar that lifts a diff --git a/meshterm/ui/channels.py b/meshterm/ui/channels.py index 08f4126..813744d 100644 --- a/meshterm/ui/channels.py +++ b/meshterm/ui/channels.py @@ -59,8 +59,12 @@ from ..core.channels import ( ) from ..core.connection import Device from ..core.models import Conversation -from ..persistence.repository import ACTIVITY_BUCKETS -from .braillechart import activity_sparkline +from ..persistence.repository import ( + ACTIVITY_BUCKETS, + ACTIVITY_DRAWN_BUCKETS, + ACTIVITY_WINDOW, +) +from .braillechart import activity_peak, activity_sparkline from .menus import back_rows, fit_cells, menu_rows, section_heading from .qr import qr_text from .tui import CANCEL, Choice, SelectScreen, Separator @@ -350,6 +354,16 @@ def _toggle_mute(ctx: "AppContext", slot: ChannelSlot) -> None: # --- message statistics -------------------------------------------------------- +#: Seconds one activity bucket spans (five minutes), so the shared scaling peak's +#: recency half-life reads in real time (see :func:`~meshterm.ui.braillechart.activity_peak`). +_ACTIVITY_BUCKET_SECONDS = ACTIVITY_WINDOW.total_seconds() / ACTIVITY_BUCKETS + +#: Floor for the shared channel-activity peak: with every channel quiet, a lone message +#: draws against at least this many per bucket, so a single stray stays a small nub +#: rather than filling its column. Low, since channel chatter is sparse to begin with. +_ACTIVITY_FLOOR = 2.0 + + class _LiveStats: """A self-refreshing view of every channel's stored-message statistics. @@ -366,6 +380,7 @@ class _LiveStats: self._ctx = ctx self._ttl = ttl self._cache: Optional[dict[str, "ChannelStats"]] = None + self._peak: Optional[float] = None self._at = 0.0 def _snapshot(self) -> dict[str, "ChannelStats"]: @@ -376,6 +391,7 @@ class _LiveStats: self._cache = self._ctx.repo.channel_stats() except Exception: # noqa: BLE001 - keep the last good snapshot on a read error self._cache = self._cache or {} + self._peak = None # derived from the snapshot; recompute on the next read self._at = now return self._cache @@ -383,21 +399,28 @@ class _LiveStats: """Return the stats for one channel identity, refreshing once the TTL lapses.""" return self._snapshot().get(channel_id) - def peak(self, buckets: int) -> int: - """The busiest bucket across *every* channel, the shared sparkline scale. + def peak(self) -> float: + """The shared sparkline scale across *every* channel, cached per snapshot. - Read live through the same cache/TTL as :meth:`get`, over each channel's - trailing ``buckets`` window. Handing this one value to every row's - :func:`~meshterm.ui.braillechart.activity_sparkline` scales the whole activity - column against the loudest channel on screen, so the rows' bar heights are - comparable at a glance — a quiet channel reads as short beside a busy one - instead of each self-scaling to its own ceiling. Zero when the window is - silent everywhere, which the sparkline draws as a flatline. + A steady ceiling over the pooled per-channel histograms (see + :func:`~meshterm.ui.braillechart.activity_peak`): recency-weighted so it glides + as chatter ages, outlier-robust so one busy burst doesn't flatten the column, + and floored so a lull's stray message stays a nub. Handing this one value to + every row's :func:`~meshterm.ui.braillechart.activity_sparkline` scales the whole + activity column against the busiest channel on screen, so the rows' bar heights + are comparable at a glance instead of each self-scaling to its own ceiling. + + Read live through the same cache/TTL as :meth:`get`, and memoised alongside that + snapshot so a full slot table doesn't recompute the pooled peak once per row. """ - return max( - (max(st.histogram[:buckets], default=0) for st in self._snapshot().values()), - default=0, - ) + snapshot = self._snapshot() + if self._peak is None: + self._peak = activity_peak( + *(st.histogram for st in snapshot.values()), + bucket_seconds=_ACTIVITY_BUCKET_SECONDS, + floor=_ACTIVITY_FLOOR, + ) + return self._peak #: Widest the name lane grows (longer names are ellipsized so the lanes stay put). @@ -408,15 +431,17 @@ _BADGE_WIDTH = 5 _COUNT_WIDTH = 5 #: Width of the right-aligned last-message-age lane (fits ``never``-length ages). _AGE_WIDTH = 5 -def _activity_sparkline(histogram: "tuple[int, ...]", peak: int) -> Text: +def _activity_sparkline(histogram: "tuple[int, ...]", peak: float) -> Text: """The channel's braille activity sparkline over the trailing two hours, now at the right. - The shared :func:`~meshterm.ui.braillechart.activity_sparkline` over the repository - histogram's :data:`ACTIVITY_BUCKETS` five-minute buckets, scaled to ``peak`` — the - busiest bucket across every channel (see :meth:`_LiveStats.peak`) — so the whole - activity column shares one scale and the rows' bars are comparable at a glance. + The shared :func:`~meshterm.ui.braillechart.activity_sparkline` over the newest + :data:`ACTIVITY_DRAWN_BUCKETS` five-minute buckets of the repository histogram, + scaled to ``peak`` — the shared ceiling across every channel (see + :meth:`_LiveStats.peak`) — so the whole activity column shares one scale and the + rows' bars are comparable at a glance. The histogram runs deeper than is drawn; the + tail past the drawn buckets shapes ``peak`` but isn't charted. """ - return activity_sparkline(histogram, ACTIVITY_BUCKETS, peak=peak) + return activity_sparkline(histogram, ACTIVITY_DRAWN_BUCKETS, peak=peak) # --- menus ------------------------------------------------------------------- @@ -498,9 +523,7 @@ def _slot_text( text.append(" ") # The shared peak across all channels, so every row's sparkline uses one scale. text.append_text( - _activity_sparkline( - st.histogram if st is not None else (), stats.peak(ACTIVITY_BUCKETS) - ) + _activity_sparkline(st.histogram if st is not None else (), stats.peak()) ) return text diff --git a/meshterm/ui/dashboard_screen.py b/meshterm/ui/dashboard_screen.py index 5e3d3e0..7711b0d 100644 --- a/meshterm/ui/dashboard_screen.py +++ b/meshterm/ui/dashboard_screen.py @@ -47,7 +47,7 @@ from rich.text import Text from ..core.channels import split_channel_sender from ..core.events import EventKind, MeshEvent from ..core.models import NODE_TYPE_REPEATER, Observation, utcnow -from ..persistence.repository import ACTIVITY_WINDOW +from ..persistence.repository import OBSERVATION_WINDOW from .braillechart import axis_chart, meter, timeline_rows from .menus import fit_cells from .widgets import TypeOf, path_text @@ -217,7 +217,7 @@ class DashboardScreen(Screen): def _prune(self) -> None: """Drop window observations that aged past the trailing window.""" - cutoff = utcnow() - ACTIVITY_WINDOW + cutoff = utcnow() - OBSERVATION_WINDOW while self._window and self._window[0].observed_at < cutoff: self._window.popleft() @@ -692,7 +692,7 @@ async def open_dashboard(ctx: "AppContext") -> None: type_of = trace_runner.make_node_type_resolver(contacts) prefix_bytes = await _routing_prefix_bytes(ctx) - window = ctx.repo.recent_observations(since=utcnow() - ACTIVITY_WINDOW) + window = ctx.repo.recent_observations(since=utcnow() - OBSERVATION_WINDOW) screen = DashboardScreen( session=session, resolve=resolve, diff --git a/meshterm/ui/menu.py b/meshterm/ui/menu.py index 10d6c6b..8c2e2c0 100644 --- a/meshterm/ui/menu.py +++ b/meshterm/ui/menu.py @@ -26,8 +26,9 @@ from .. import __version__ from ..context import AppContext from ..persistence.logging import get_logger from ..tools import all_tools +from ..services.monitor_service import ACTIVITY_BUCKET_S from .surface import TuiUi -from .braillechart import activity_sparkline +from .braillechart import activity_peak, activity_sparkline from .theme import make_console from .widgets import battery_cell from .tui import ( @@ -119,6 +120,11 @@ def _silence_console_logging() -> Iterator[None]: #: the compact " · " so a 72-column terminal still shows a readable stretch of pulse. _SPARK_MIN_CELLS = 24 +#: Floor for the header pulse's scaling ceiling (see :func:`~meshterm.ui.braillechart. +#: activity_peak`): a lone packet in a long-silent window draws against at least this +#: many packets-per-minute, so a single stray reads as a small nub, not a full column. +_HEADER_ACTIVITY_FLOOR = 3.0 + def _header(ctx: AppContext, cache: dict, width: int) -> Text: """Build the persistent one-line header: who's connected, unread mail, mesh pulse. @@ -164,13 +170,20 @@ def _header(ctx: AppContext, cache: dict, width: int) -> Text: styles = [ "ok" if live else "muted" for live in ctx.monitor.activity_session_flags() ] - # No shared peak: alone on its row, the pulse self-scales to its own window's - # busiest minute (whatever slice of history the room fits), like the dashboard's - # tall activity chart against its window peak. + # Scale to a steady ceiling over the monitor's *full* six-hour history — deeper + # than the row draws — not the drawn window's bare maximum: a recency-weighted, + # outlier-robust, floored peak (see activity_peak), so the pulse doesn't lurch as + # a busy minute scrolls off the edge and a lone packet in a lull stays a nub. + histogram = ctx.monitor.activity_histogram() header.append_text( activity_sparkline( - ctx.monitor.activity_histogram(), + histogram, room * 2, + peak=activity_peak( + histogram, + bucket_seconds=ACTIVITY_BUCKET_S, + floor=_HEADER_ACTIVITY_FLOOR, + ), column_styles=styles, ) ) diff --git a/tests/test_braillechart.py b/tests/test_braillechart.py index 4020106..b0c7c55 100644 --- a/tests/test_braillechart.py +++ b/tests/test_braillechart.py @@ -8,6 +8,7 @@ from __future__ import annotations from meshterm.ui.braillechart import ( GAP, + activity_peak, activity_sparkline, axis_chart, chart_span, @@ -15,6 +16,8 @@ from meshterm.ui.braillechart import ( y_axis_labels, ) +_INF = float("inf") # half_life → no decay, so a peak test isolates percentile/floor/pool + #: Dot bits for a column filled bottom-up to height 0–4 (left / right column). _L = (0x00, 0x40, 0x44, 0x46, 0x47) _R = (0x00, 0x80, 0xA0, 0xB0, 0xB8) @@ -201,6 +204,46 @@ def test_sparkline_pads_and_crops_to_the_window() -> None: assert cropped.plain == _BASE # only the two newest (silent) buckets survive +# --- activity_peak -------------------------------------------------------------------- + + +def test_activity_peak_reads_a_percentile_not_the_max() -> None: + """One freak-busy bucket sits above the ceiling instead of defining it.""" + # Ten steady buckets of 10 and a lone spike of 1000; no decay, so the ceiling is + # purely the 90th percentile of the counts — the steady level, not the spike. + peak = activity_peak( + (1000,) + (10,) * 10, bucket_seconds=60, half_life_min=_INF, percentile=90 + ) + assert peak == 10.0 + + +def test_activity_peak_weights_recent_buckets_over_old() -> None: + """The same burst weighs less toward the ceiling the older it is (recency).""" + # A one-minute half-life halves a bucket's weight each minute: a fresh 20-burst sets + # the ceiling at 20, the same burst two minutes back at a quarter of that. + now = activity_peak((20, 0, 0), bucket_seconds=60, half_life_min=1.0) + aged = activity_peak((0, 0, 20), bucket_seconds=60, half_life_min=1.0) + assert now == 20.0 + assert aged == 5.0 # two half-lives → 20 × ¼ + + +def test_activity_peak_floors_a_quiet_window() -> None: + """The floor holds the ceiling up so a lull's stray packet stays a nub, not a column.""" + assert activity_peak((0, 0, 0), bucket_seconds=60, floor=3.0) == 3.0 # silent → floor + lone = activity_peak((1,), bucket_seconds=60, half_life_min=_INF, floor=3.0) + assert lone == 3.0 # a single packet scales against the floor, not against itself + + +def test_activity_peak_pools_several_histograms_into_one_ceiling() -> None: + """Pooled channels share a scale: a quiet channel reads short beside a busy one.""" + pooled = activity_peak( + (10,) * 10, (1,), bucket_seconds=300, half_life_min=_INF, percentile=90 + ) + assert pooled == 10.0 # the busy channel's level sets the shared ceiling… + solo = activity_peak((1,), bucket_seconds=300, half_life_min=_INF, percentile=90) + assert solo == 1.0 # …where the quiet one alone would have set just 1 + + # --- y_axis_labels / axis_chart ------------------------------------------------------- diff --git a/tests/test_channels.py b/tests/test_channels.py index 0cc8274..bae1852 100644 --- a/tests/test_channels.py +++ b/tests/test_channels.py @@ -477,12 +477,12 @@ async def test_reorder_keeps_history_because_key_is_intrinsic(ctx: AppContext) - def test_channel_stats_aggregates_totals_window_and_recency(ctx: AppContext) -> None: - """Per-channel stats count all messages, the trailing-2h slice, and the last time.""" + """Per-channel stats count all messages, the trailing-window slice, and the last time.""" from datetime import timedelta from meshterm.core.models import ChatMessage, utcnow - stale = utcnow() - timedelta(days=30) # outside the two-hour activity window + stale = utcnow() - timedelta(days=30) # outside the activity window fresh = utcnow() - timedelta(minutes=2) for text, when in (("old a", stale), ("old b", stale), ("new", fresh)): ctx.repo.record_chat_message( @@ -503,8 +503,9 @@ def test_channel_stats_aggregates_totals_window_and_recency(ctx: AppContext) -> assert ops.last_at is not None assert abs((ops.last_at - fresh).total_seconds()) < 1 # The histogram spans the window newest-first: the 2-minute-old message lands in the - # "now" (first) bucket and the 30-day-old ones land nowhere. - assert len(ops.histogram) == 24 + # "now" (first) bucket and the 30-day-old ones land nowhere. It carries the full + # window (deeper than the sparkline draws) so the shared scaling peak has history. + assert len(ops.histogram) == 72 assert ops.histogram[0] == 1 and sum(ops.histogram) == 1 diff --git a/tests/test_header.py b/tests/test_header.py index a593766..76a2814 100644 --- a/tests/test_header.py +++ b/tests/test_header.py @@ -68,11 +68,11 @@ def test_header_wider_terminal_shows_deeper_history() -> None: def test_header_scales_to_the_window_peak() -> None: - """The pulse scales to its window's busiest minute, not a fixed threshold ladder. + """The pulse scales relative to a peak, not a fixed threshold ladder. - A 16/12/8/4 ramp against its own peak of 16 climbs one dot per step, so the four - newest minutes read heights 1,2,3,4 left→right in the row's final two cells — the - same relative scaling the dashboard's tall activity chart draws with. + A 16/12/8/4 ramp climbs one dot per step against the robust ceiling ``activity_peak`` + computes for it (~14.7 here — a recency-weighted, floored 90th percentile), so the + four newest minutes read heights 1,2,3,4 left→right in the row's final two cells. """ histogram = (16, 12, 8, 4) + (0,) * 356 header = _header(_ctx(histogram=histogram), {}, 80).plain