Skip to content

sharing-server: add admin overview dashboard with aggregate stats and trend chart#696

Merged
rajbos merged 2 commits intomainfrom
rajbos/fluency-shared-server
Apr 29, 2026
Merged

sharing-server: add admin overview dashboard with aggregate stats and trend chart#696
rajbos merged 2 commits intomainfrom
rajbos/fluency-shared-server

Conversation

@rajbos
Copy link
Copy Markdown
Owner

@rajbos rajbos commented Apr 29, 2026

Why

The admin dashboard previously only showed a collapsed list of users — clicking "👑 Admin: All Users" revealed a table of usernames and join dates but no token usage data. Admins had no way to see aggregate usage across all users at a glance.

What changed

Admins now see a full overview section at the top of the dashboard (above their personal data), with the same quality of stats and charts that individual users have.

New admin section (visible only to is_admin users)

  • 👑 Admin Overview stats card — Input Tokens, Output Tokens, Interactions, and Active Users (distinct user count) for Today / Last 7 Days / Last 30 Days. "Today" values are patched client-side to the viewer's local timezone, matching the behaviour of the personal stats card.
  • Token Usage Trend — All Users chart — a full Chart.js stacked-bar chart of aggregate token usage, with the same controls as the personal chart (period, day/week/month bucketing, linear/log scale) plus a new "By User" grouping. The By-User view caps at the top 10 users by token volume; all others are grouped as "Other" to keep the chart readable.
  • Top Users by Token Usage table — ranked list of all users showing input/output tokens, interactions, and last active date; collapsible.
  • All Users list — the existing user-metadata table is unchanged, still collapsible at the bottom.

Implementation notes

  • db.ts: Added AdminUploadRow (extends UploadRow with github_login) and getAllUploads(days) which JOINs usage_uploads with users. Also added a day-column index on usage_uploads to make the cross-user date-range query efficient.
  • dashboard.ts: Admin chart uses fully namespaced DOM IDs (admin-*) and a separate Chart.js instance to avoid any state collision with the personal chart on the same page. Admin interactive JS is emitted only for admin sessions.
  • Non-admin sessions are completely unaffected — no extra queries, no extra HTML.

rajbos and others added 2 commits April 29, 2026 13:59
- Add getAllUploads() DB function with JOIN to get github_login per row
- Add day index on usage_uploads for faster admin queries
- Admin dashboard (shown to is_admin users) includes:
  - Aggregate stats card (today/7d/30d) with Active Users count
  - Token usage trend chart for all users (by model/editor/by user)
  - Top Users by token usage table (last 30 days)
  - All Users list (collapsible, unchanged)
- By User grouping caps at top 10 users; others shown as 'Other'
- Admin today stats patched client-side using browser local timezone
- Admin section appears above personal data for immediate visibility

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolve conflict in sharing-server/src/routes/dashboard.ts import line.
Both admin approaches coexist: inline admin section on /dashboard and
separate /admin route added by main.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rajbos rajbos merged commit 55985a8 into main Apr 29, 2026
25 of 27 checks passed
@rajbos rajbos deleted the rajbos/fluency-shared-server branch April 29, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant