Files
meshcore-bot/modules/web_viewer/static/css/dashboard.css
T
agessaman 7e3ab04b53 feat(web-viewer): rebuild dashboard on a background snapshot
The landing page re-ran ~50 aggregate queries five times per load, then
repeated the whole sequence every 30 seconds forever — including in
backgrounded tabs. Against the live 1.44 GB database that was roughly 20
seconds of SQLite work per page load.

Move the work off the request path. A refresher thread in the viewer
process (which already runs migrations, so it works for a split-DB
install) writes two tables: daily_rollup, one row per local date, and
dashboard_snapshot, a single JSON row. A page load now reads one row.

Measured on the live database: first paint 6 requests -> 2,
/api/dashboard/summary p50 1.1 ms (304 in 0.8 ms), /api/stats 130 ms,
and a 0.32 s refresh once a minute in the background.

Make the numbers mean what they say:

- Window selectors are built from each source's retention. The page
  offered "30d" and "All" against tables pruned at 7 days, so three of
  four choices returned the same figure under a label that denied it.
- The incoming-packet chart reports its measured window instead of
  claiming 7 days for a table pruned at 3 — it sat beside a genuine
  7-day contacts chart inviting an invalid comparison.
- Days with no source data store NULL and render as gaps. Writing 0
  would put a fake cliff at every retention boundary.
- Signal metrics are stored as sums and counts, never means, so any
  window re-aggregates correctly.
- Delta chips compare the last two complete calendar days and say so;
  the headline above them is a rolling 24 hours.
- Unmapped role ordinals (type0..type15) bucket into "Unknown".
- SNR comes from message_stats, where it is populated on every row, not
  from complete_contact_tracking, where it is populated on 7%.

Kill the json_extract scans: packet_stream gains denormalized
route_type_name, payload_type_name, path_len and bytes_per_hop, written
at capture time. Aggregating those from JSON cost 3-6 s per query.
Existing rows convert a bounded batch per tick rather than in one
migration that would rewrite ~180 MB into the WAL and stall bot startup.
A partial index serves as the backfill worklist — without it the "any
rows left?" probe is a full scan costing 4.6 s per tick, and it costs
that after the backfill finishes, because finding nothing still means
reading everything.

Also: replace the per-contact hop-prefix scan with the existing bucketed
matcher and memoize the 7-day chunk set (264 ms -> 35 ms on a synthetic
100k-row database, regression-locked by a test); move the dashboard's JS
and CSS to static files, which removes the CSP nonce requirement for the
bulk of the page; and give cleanup_old_stats a future-timestamp guard,
without which rows dated 2103 are never older than the cutoff and so
live forever.

Deletes the orphaned /stats page, unreachable from the nav and rendering
stub charts that never populated. /api/stats stays as a shim with every
key name intact plus Deprecation and Sunset headers.

All schema changes are additive, so a downgraded codebase can read the
data; it would however need the new schema_version rows removed, since
MigrationRunner rejects versions it does not know.
2026-07-29 21:56:09 -07:00

395 lines
9.0 KiB
CSS

/* Dashboard (landing page) styles.
*
* Only the theme tokens declared in base.html are used (--bg-*, --text-*,
* --border-color, --card-*, --shadow-color), and every rule that hard-codes a
* colour has a matching [data-theme="dark"] override — Bootstrap 5.1.3 has no
* native dark theme here, so nothing inherits one for free.
*/
/* ── Health strip ──────────────────────────────────────────────────────── */
.health-strip {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.25rem 1.5rem;
min-height: 56px;
padding: 0.5rem 1rem;
margin-bottom: 1.25rem;
background-color: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: 10px;
box-shadow: 0 1px 3px var(--shadow-color);
}
.health-strip__item {
display: flex;
align-items: center;
gap: 0.45rem;
font-size: 0.875rem;
color: var(--text-color);
white-space: nowrap;
}
.health-strip__label {
color: var(--text-muted);
text-transform: uppercase;
font-size: 0.7rem;
letter-spacing: 0.04em;
}
.health-strip__spacer {
flex: 1 1 auto;
}
.health-strip .btn-refresh {
padding: 0.1rem 0.4rem;
line-height: 1;
border: none;
background: transparent;
color: var(--text-muted);
cursor: pointer;
}
.health-strip .btn-refresh:hover,
.health-strip .btn-refresh:focus {
color: #0d6efd;
}
.health-strip .btn-refresh[disabled] {
opacity: 0.5;
cursor: progress;
}
/* ── Section headings ──────────────────────────────────────────────────── */
.dashboard-section-title {
display: flex;
align-items: baseline;
gap: 0.6rem;
margin: 1.75rem 0 0.75rem;
font-size: 0.8rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--text-muted);
}
.dashboard-section-title::after {
content: "";
flex: 1 1 auto;
height: 1px;
background-color: var(--border-color);
}
/* ── Stat tiles ────────────────────────────────────────────────────────── */
.stat-tile {
display: flex;
flex-direction: column;
height: 100%;
padding: 0.75rem 0.9rem 0.5rem;
background-color: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: 10px;
box-shadow: 0 1px 3px var(--shadow-color);
}
.stat-tile__label {
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.04em;
color: var(--text-muted);
margin-bottom: 0.2rem;
}
.stat-tile__row {
display: flex;
align-items: baseline;
gap: 0.5rem;
flex-wrap: wrap;
}
.stat-tile__value {
font-size: 1.6rem;
font-weight: 700;
line-height: 1.1;
color: var(--text-color);
font-variant-numeric: tabular-nums;
}
.stat-tile__value--muted {
color: var(--text-muted);
}
.stat-tile__sub {
font-size: 0.75rem;
color: var(--text-muted);
}
.stat-tile__spark {
position: relative;
height: 48px;
margin-top: auto;
}
/* Sparkline canvases are sized by their container, not by their attributes. */
.stat-tile__spark canvas {
width: 100% !important;
height: 48px !important;
}
/* ── Delta chips ───────────────────────────────────────────────────────── */
.delta-chip {
display: inline-flex;
align-items: center;
gap: 0.15rem;
padding: 0.05rem 0.35rem;
border-radius: 999px;
font-size: 0.72rem;
font-weight: 600;
font-variant-numeric: tabular-nums;
background-color: var(--bg-tertiary);
color: var(--text-muted);
}
.delta-chip--up {
background-color: rgba(25, 135, 84, 0.12);
color: #146c43;
}
.delta-chip--down {
background-color: rgba(220, 53, 69, 0.12);
color: #b02a37;
}
[data-theme="dark"] .delta-chip--up {
background-color: rgba(25, 135, 84, 0.22);
color: #75b798;
}
[data-theme="dark"] .delta-chip--down {
background-color: rgba(220, 53, 69, 0.22);
color: #ea868f;
}
/* ── Mini bar (tracked vs known) ───────────────────────────────────────── */
.mini-bar {
height: 6px;
width: 100%;
margin-top: 0.4rem;
border-radius: 3px;
background-color: var(--bg-tertiary);
overflow: hidden;
}
.mini-bar__fill {
height: 100%;
background-color: #0d6efd;
border-radius: 3px;
}
/* ── Stacked route-mix bar ─────────────────────────────────────────────── */
.stacked-bar {
display: flex;
height: 26px;
width: 100%;
border-radius: 6px;
overflow: hidden;
background-color: var(--bg-tertiary);
}
.stacked-bar__segment {
display: flex;
align-items: center;
justify-content: center;
font-size: 0.72rem;
font-weight: 600;
color: #fff;
white-space: nowrap;
overflow: hidden;
min-width: 0;
}
.stacked-bar__legend {
display: flex;
flex-wrap: wrap;
gap: 0.25rem 1rem;
margin-top: 0.5rem;
font-size: 0.78rem;
color: var(--text-muted);
}
.stacked-bar__swatch {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 2px;
margin-right: 0.35rem;
vertical-align: baseline;
}
/* ── Horizontal mix rows (role / device) ───────────────────────────────── */
.mix-row {
display: grid;
grid-template-columns: minmax(5.5rem, 8rem) 1fr auto;
align-items: center;
gap: 0.6rem;
margin-bottom: 0.35rem;
font-size: 0.82rem;
}
.mix-row__name {
color: var(--text-color);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.mix-row__track {
height: 10px;
border-radius: 5px;
background-color: var(--bg-tertiary);
overflow: hidden;
}
.mix-row__fill {
height: 100%;
border-radius: 5px;
}
.mix-row__count {
color: var(--text-muted);
font-variant-numeric: tabular-nums;
}
/* ── Signal percentile readout ─────────────────────────────────────────── */
.signal-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 0.5rem;
text-align: center;
}
.signal-grid__value {
font-size: 1.1rem;
font-weight: 700;
color: var(--text-color);
font-variant-numeric: tabular-nums;
}
.signal-grid__label {
font-size: 0.68rem;
text-transform: uppercase;
letter-spacing: 0.04em;
color: var(--text-muted);
}
/* ── Leaderboard rows ──────────────────────────────────────────────────── */
.top-list-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 0.5rem;
padding: 0.25rem 0;
}
.top-list-row + .top-list-row {
border-top: 1px solid var(--border-color);
}
.top-list-row__name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* ── Chart wrappers ────────────────────────────────────────────────────── */
.chart-box {
position: relative;
width: 100%;
height: 200px;
}
.chart-box--tall {
height: 240px;
}
.doughnut-box {
position: relative;
max-width: 190px;
width: 100%;
margin: 0 auto;
}
.dashboard-note {
font-size: 0.75rem;
color: var(--text-muted);
}
.dashboard-empty {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
min-height: 100px;
color: var(--text-muted);
font-size: 0.85rem;
font-style: italic;
}
/* Info affordance shared by tooltip triggers in card headers. */
.dashboard-info-btn {
padding: 0;
border: 0;
background: none;
color: var(--text-muted);
line-height: 1;
}
.dashboard-info-btn:hover,
.dashboard-info-btn:focus {
color: #0dcaf0;
text-decoration: none;
}
.tooltip.dashboard-hint .tooltip-inner {
max-width: min(22rem, 92vw);
text-align: left;
}
/* ── Live activity feed ────────────────────────────────────────────────── */
.live-feed {
height: 260px;
overflow-y: auto;
background-color: var(--bg-secondary);
padding: 0.5rem;
}
.live-feed__entry {
padding: 3px 8px;
margin-bottom: 3px;
font-size: 0.82rem;
border-radius: 2px;
border-left: 3px solid var(--border-color);
}
@media (max-width: 575.98px) {
.stat-tile__value {
font-size: 1.35rem;
}
.health-strip {
gap: 0.25rem 1rem;
}
}