Skip to content

feat(webui): dense Analytics page redesign - #612

Merged
jatmn merged 1 commit into
mainfrom
feat/587-analytics-redesign
Nov 13, 2026
Merged

jatmn merged 1 commit into
mainfrom
feat/587-analytics-redesign

Conversation

@jatmn

@jatmn jatmn commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

🤖 Fixer (jatmn's agent)

Closes #587

Summary

The Analytics tab is now a dense, command-center grid. Every panel is visible at once and follows one 7 / 30 / 90-day range selector. Everything comes from one summary request per range that is aggregated in SQL from records the bot already stores. Nothing on the analytics path calls Discord for data.

  • Header: a one-line Analytics header with the server and range, the range selector (a labelled group of 7d / 30d / 90d toggle buttons with aria-pressed), and the "About these trends" text moved into the existing InfoTip.

  • KPI strip: nine equal tiles (Members, Net growth, Joins, Leaves, Warnings, Bans, Spam hits, Mod actions, Timeouts). Each shows a compact number, with the exact value in the title and accessible label, its change against the previous period of the same length, and a daily sparkline. Member coverage is a small partial / unverified badge instead of inline text. Numbers use a locale-independent compact format (10.4k, 1.2M, 2T), never wrap, and stay at most 18px.

  • Panels:

    • Enforcement per day: aligned bars for warnings, bans, spam hits, mod actions and timeouts.
    • Membership per day: joins above and leaves below a zero line, with a running net-change line with points.
    • Top automod rules, shown by configured rule name.
    • Mod actions by type.
    • Mod actions by moderator, with names from the stored member directory.
    • A weekday × UTC hour heat map.
  • Tooltips and axes: hover or arrow keys (Home/End/Escape) show exact per-day values in a readout, and every day column also has a native <title>. Axes use integer ticks for sparse counts, and day labels are evenly spaced and edge-aligned.

  • Backend: /api/guilds/{id}/analytics takes ?days=7|30|90 (default 30; anything else is refused). One core statement returns everything:

    • the daily series
    • previous-period totals
    • rule, kind and moderator breakdowns
    • the heat map

    Counted events are materialized once in a CTE, so events is scanned and its JSON parsed once. One guild-store statement returns the directory size, coverage and stored names for up to 8 moderators (bounded at 32 IDs).

  • Caching: the API caches complete answers for 30 s per guild, membership and range. The cache is checked only after authorization and page-membership checks, holds at most 256 entries, and is skipped when the directory is unavailable. The browser reuses a loaded range for 60 s, both when switching ranges and when returning to the tab, and clears it on sign-out or auth loss.

  • Progressive render: the header, KPI strip and all six panel frames render immediately with busy placeholders and fill in when the response arrives.

  • CSS: all new styles are in one delimited section at the end of frontend/style.css. Every selector there starts with .analytics-page or .an-, and a test enforces that. The series colors are scoped tokens for light and dark.

The owner Administration analytics still uses TrendChart / TrendMetricPicker unchanged. The branch is rebased onto #602 (icons). Its glyph-free source test caught the typographic minus sign, which is now written as the − escape. The rendered output is unchanged.

Already covered by #599/#605

  • Drop or shrink the hero to a one-line header: feat(webui): tighten global density to a desktop admin-console scale #599 replaced the hero with pageHeader("Analytics", …) in frontend/app.js tabAnalytics, styled by .page-header, .page-header-detail and .page-header-actions in frontend/style.css, and tested by "no page renders the old multi-line hero card markup" in scripts/frontend-state-test.mjs. I kept that header and only added the range selector and info tip to it.
  • Dense operator scale and no oversized headline numbers (shared tokens): feat(webui): tighten global density to a desktop admin-console scale #599 set the global density tokens in frontend/style.css (--ui-font-size, --ui-font-size-sm, --card-p, --ui-gap, --stat-value-size: 1.25rem, plus .stats .stat, .stat-title and .stat-value) for both themes. The analytics section builds on those tokens.
  • Collapsible info tooltip component: feat(webui): tighten global density to a desktop admin-console scale #599 added InfoTip in frontend/app.js (the .info-tip* rules in frontend/style.css), used then only on the Dashboard. I reuse it here for "About these trends", which was still an inline paragraph on main.
  • Chart summary visually hidden (accessibility): fix(webui): define sr-only so the chart summary is visually hidden #605 defined .sr-only in frontend/style.css, so the figcaption in frontend/charts.js TrendChart is hidden on screen but still read (scripts/frontend-sr-only-test.mjs). The new charts instead use role="img" with summary aria-labels and an aria-describedby readout.

Everything else in #587 was still open on main: the KPI comparisons, sparklines and badge, the multi-panel grid, breakdowns, heat map, tooltips and ticks, range selector, server and client caching, and profiling.

Profiling (before = main de11955, after = this branch)

I measured with the API's own test fixture: the real router, session, authorization, a local SQLite core database and an activated guild store, with the Discord OAuth endpoints stubbed and counted. I seeded 90 days of data at 30 or 300 enforcement records per day. Each figure is the first request for that URL and then the median of 20 repeats. This is a debug build (SQLite compiled at -O0), so absolute times are inflated; the release-SQLite table below gives the SQL cost alone.

Records/day Request Before: first / repeat After: first (cold) / repeat (cached)
30 7d 12.6 / 10.8 ms (actually 30d; range ignored) 16.1 / 1.1 ms
30 30d 10.9 / 10.5 ms 29.2 / 1.4 ms
30 90d 10.9 / 10.2 ms (actually 30d) 45.6 / 2.2 ms
300 7d 57.4 / 55.1 ms (actually 30d) 52.6 / 1.1 ms
300 30d 55.4 / 55.7 ms 185 / 1.4 ms
300 90d 60.1 / 55.5 ms (actually 30d) 339 / 2.2 ms

SQL statement only, release SQLite 3.46, same data with 180 days stored (best of 5):

Records/day Before (fixed 30d) After 7d After 30d After 90d
30 1.6 ms 1.9 ms 7.3 ms 21.5 ms
300 16.5 ms 14.6 ms 66.8 ms 205 ms
  • Browser requests: before, the tab made 1 request on every visit, always for 30 days. After, it makes 1 request the first time a range is viewed. Switching back to a loaded range, or returning to the tab within 60 s, makes 0 requests (tested).
  • Response size: before, about 3.3 KB, always 30 days. After, 2.9 KB for 7 days, 5.5–5.9 KB for 30 and 12.0–12.6 KB for 90, carrying every panel.
  • DB work per request:
    • Authorization is unchanged: one active-membership lookup.
    • Cold read, before and after: a snapshot with a membership check and 1 aggregate statement on the core database, plus a scope check and 1 statement on the guild store. That one aggregate statement now covers every panel, and the guild-store statement now also returns moderator names.
    • Cached read: 0 analytics statements.
  • Discord calls:
    • 0 bot-token calls before and after; the API has no bot token.
    • 0 member, /users/@me or token calls for analytics data.
    • The only Discord request is the user's OAuth guild-list snapshot, which guild authorization requires and reuses for 3 s. It is unchanged: at most 1 per measurement block in both runs.
  • Cold cost: the cold read costs more than the old single series because it also scans the previous period (needed for the comparisons) and builds five more panels. Materializing the events CTE once cut my first version from 228 ms to 185 ms (debug, 30 days at 300 records/day).

Tests

Run on the final head 172c2a0, rebased on main 96a5ad0:

  • bash scripts/ci-preflight.sh (full Linux preflight, no --only): passed, "CI test gates passed". Results:

    • workspace nextest 2354 passed, 6 skipped
    • API --no-default-features 216 passed
    • frontend-state 354/0 with 0 skipped, so the headless-Firefox checks ran
    • frontend-contrast 23/0, warmup 13/0, sr-only 1/0, package-webui 3/0, administration 46/0
    • dual_process_smoke --ignored passed
    • fmt, dylint, clippy -D warnings (also API --no-default-features), service boundaries, git diff --check, cargo deny and cargo audit all clean

    It also passed in full on the pre-rebase commit.

New and updated tests:

  • Backend aggregation (src/db/analytics/tests.rs):

    • empty data for all three ranges, with every panel key present
    • a single day of records, ranked rules, kinds and moderators, with exclusions for dry-run, non-punishing and corrupt-JSON events
    • unattributed mod actions, and a snowflake above 2^53 kept as a string
    • heat-map bucketing that counts each action once
    • previous-window totals, with no membership comparison at 90 days
    • exact sums of 2×10^12 joins
    • top-8 bounds
    • the existing remote libSQL snapshot-budget test now also checks the panels
  • Guild store (src/db/guild_data/tests/member_directory.rs): name precedence (nickname, then global name, then username), nameless and unknown IDs omitted, a snowflake above 2^53, and the 32-ID bound.

  • API (crates/api/src/web/enrollment_tests.rs, state.rs):

    • each range returns its window, and the default stays 30
    • moderator names come from the directory
    • only the authorization snapshot reaches the Discord stub
    • a cached range does not see new records
    • a new membership never reads the old membership's cache entry
    • days=14, 0, -7, abc and unknown parameters are refused
    • cache TTL and bound
  • Frontend (scripts/frontend-state-test.mjs, jsdom):

    • one-line header, range group, info tip and progressive placeholders
    • one POST per range with the page-membership header
    • KPI values, deltas and labels
    • several charts and no toggle
    • rule and moderator labels
    • range switching 7, 30, 90, then back, with no refetch, then a refetch after the TTL and after sign-out
    • keyboard and hover tooltips with exact values and native titles
    • coverage badge; unavailable on failure; empty and single-day data
    • large-number formatting and ticks

    Seven of these fail on the old frontend (checked); the eighth is the existing no-hero test.

  • Real browser (headless Firefox, same file): 1280×800, 1920×1080 and 700×800 in light and dark. It checks:

    • no horizontal scroll, no wrapped or clipped KPI numbers, long rule names truncated
    • numerals at most 20px
    • at desktop sizes, enforcement and membership side by side and both above the fold, with at most two KPI rows
    • a single column at 700px
    • series colors that change with the theme

    This test caught two layout bugs that I then fixed: a KPI delta overflowing at 700px, and daisyUI's card figure rule placing the readouts beside the charts.

  • CSS (scripts/frontend-contrast-test.mjs): every analytics selector stays inside its delimited section; series colors reach at least 3:1 on the panel and are distinct in both themes; muted text, badge and selected range meet 4.5:1; numbers use nowrap and tabular figures; the medium and narrow breakpoints restack the grid.

Simulated boundaries: local SQLite, the in-repo libSQL HTTP fixture (not a live remote database), stubbed Discord OAuth endpoints, and the built app against a stub API in headless Firefox. I didn't load it against a live server or test it with a screen reader.

Open questions and assumptions

  • Enforcement chart form: feat(webui): redesign the Analytics page so it is dense and informative #587 asks for stacked or grouped bars, but these records overlap. A warn command writes a warning row and a mod-action event; a ban command writes a ban row and a mod-action event; a timeout writes a timeout_add and a mod-action event. Stacking would double count, so I used aligned small multiples with one shared hover day. Is that acceptable, or do you want grouped bars despite the density at 90 days?
  • Member count trend (missing panel): no daily member count is stored, only today's directory size and the daily join/leave counters. The membership panel shows the running net change instead. A real member-count line needs a daily directory-size snapshot written by the bot, which means a core migration plus a bot write path. I didn't file anything for it.
  • Cold-read cost: there is no daily rollup for enforcement records, so a cold read scans the raw events, warns and bans rows for the range and the previous period (indexed by guild and time). A daily enforcement rollup table would make cold reads proportional to days rather than records. That needs a migration, bot writes and the paired update protocol, so I left it out. Should it be a follow-up?
  • Freshness: the cache is time-based (up to 30 s on the server and 60 s in the browser) rather than "until new events land". The API cannot observe the bot's runtime moderation writes without polling, and those writes intentionally don't bump config_version.
  • Moderator breakdown: it counts recorded mod-action events, which come from bot commands. Bans and timeouts done in Discord's own UI aren't attributed to a moderator there. Names come only from the stored member directory; departed or unknown moderators show User <id>, with the ID in the title.
  • Heat map scope: it counts automod enforcement, bot moderation commands and dedicated spam bans once each, in UTC. Manual Discord-UI bans and timeouts are left out to avoid double counting.
  • Comparisons: the previous period has the same length. At 90 days, joins, leaves and net show no comparison, because daily counters are kept for 92 days. For a newly added bot, the previous period compares against days that weren't recorded yet, and the info tip explains this.
  • Authorization: the guild-scoped authorization snapshot (a user OAuth call reused for 3 s) is unchanged, because the repository's security invariants require it. It isn't an analytics data call.

Summary by Sourcery

Replace the existing Analytics trends view with a dense, cached command-center dashboard backed by stored data and a unified range selector.

New Features:

  • Redesign the Analytics tab as a dense command-center dashboard with shared 7-, 30-, and 90-day ranges, KPI tiles, daily charts, ranked breakdowns, and an activity heat map.

Bug Fixes:

  • Prevent analytics data from being fetched from Discord and avoid treating unavailable member-directory data as zero values.

Enhancements:

  • Aggregate all analytics panels from stored records in a single range-aware summary read, including previous-period comparisons and stored moderator names.
  • Add authorization-aware short-lived server caching and browser caching for analytics summaries.
  • Improve analytics accessibility and responsive presentation with progressive loading, compact number formatting, keyboard and hover details, native chart titles, scoped theme-aware colors, and mobile layouts.

Documentation:

  • Update moderation-read and WebUI documentation for the expanded analytics endpoint, supported ranges, caching, and dashboard panels.

Tests:

  • Expand backend, guild-directory, API, frontend, accessibility, contrast, and browser layout coverage for analytics ranges, aggregation, caching, formatting, interaction, and responsive rendering.

@jatmn jatmn added the fixer PR produced by Fixer (jatmn's agent) label Nov 13, 2026
@jatmn
jatmn marked this pull request as ready for review November 13, 2026 02:27
@sourcery-ai

sourcery-ai Bot commented Nov 13, 2026

Copy link
Copy Markdown

Sorry @jatmn, this account has used its review budget of 1,500,000 diff characters for the last 7 days.

You can request another review in 1 day and 18 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@jatmn

jatmn commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

@pullfrog review

@jatmn jatmn self-assigned this Nov 13, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes across the Analytics frontend, API, database aggregation, tests, and documentation against #587 and its clarified scope.

  • Dashboard: Shared 7/30/90-day ranges, compact KPIs, enforcement and membership charts, ranked breakdowns, and a UTC heat map with progressive loading and chart readouts.
  • Stored-data summaries: SQL aggregates current and previous windows; moderator names come from bounded member-directory lookups, without new Discord data fetches.
  • Caching and authorization: Membership/range-scoped server and browser caches retain the existing permission and page-enrollment checks; browser entries clear on sign-out or authentication loss.
  • Validation: All 12 focused Analytics state, contrast, and headless-Firefox layout tests passed locally after building frontend assets. GitHub’s CI passed gate is green; Rust suites were not rerun locally. Browser tests use a stub API, not live Discord or Bunny.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

Replace the single-chart Analytics tab with a command-center grid that
renders every panel from one summary read per range (7, 30 or 90 days):

- compact KPI strip (members with a coverage badge, net growth, joins,
  leaves, warnings, bans, spam hits, mod actions, timeouts) with change
  against the previous period and daily sparklines;
- aligned daily enforcement bars, joins/leaves with a running net line,
  top automod rules, mod actions by type and by moderator, and a weekday
  by UTC hour heat map, with hover and keyboard readouts of exact values;
- the About text moved into the existing info tooltip.

The API takes a validated days parameter and aggregates all panels in one
core statement (counted events materialized once) plus one guild-store
statement for directory totals and stored moderator names. Complete
answers are cached for 30 seconds per membership and range after
authorization; the browser reuses loaded ranges for 60 seconds and clears
them on sign-out. No Discord call is made for analytics data.

Closes #587

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jatmn
jatmn force-pushed the feat/587-analytics-redesign branch from 172c2a0 to 64ce9dc Compare November 13, 2026 02:46
@jatmn

jatmn commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

@pullfrog review

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes across all 14 files, including the Analytics dashboard, stored-data aggregation, membership-aware caching, and regression coverage.

  • Dashboard: Shared date ranges, compact KPIs, daily enforcement and membership charts, ranked breakdowns, heat map, and responsive theme styling.
  • Backend: SQL summary aggregation, previous-period comparisons, bounded stored-name lookups, and authorization-before-cache access.
  • Validation: All 8 focused analytics frontend tests passed, including the headless Firefox layout check; all 26 contrast/CSS tests passed. Rust tests were not rerun locally; GitHub’s CI passed check is successful. Browser data was stubbed, with no live-provider validation.
  • Documented limits: Membership charts show cumulative net change rather than historical member counts; cold reads still aggregate retained raw enforcement records.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

@jatmn
jatmn merged commit b1707a2 into main Nov 13, 2026
20 checks passed
@jatmn
jatmn deleted the feat/587-analytics-redesign branch November 13, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixer PR produced by Fixer (jatmn's agent)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(webui): redesign the Analytics page so it is dense and informative

1 participant