Repository navigation
feat(dashboard): XP history chart + xpByDay tracking - #81
CommunityPoke wants to merge 1 commit into
Conversation
- awardXP records an xpByDay map (UTC day -> XP earned) on each levels doc - New src/services/xpHistory.js aggregates level docs into daily series - New GET /api/xp-history endpoint (auth'd, days/guildId params) - Dashboard renders a responsive SVG chart with member selector, loading/empty/error states, and a screen-reader data table - 12 new node:test cases covering the helpers and awardXP recording Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Code review — XP history chartReviewed the full diff, ran the suite on this branch locally: 551/551 tests pass (verified the claim). Index claim also checks out — Findings, ordered by severity: Medium —
|
|
To use Codex here, create a Codex account and connect to github. |
Summary
Adds an XP history chart to the dashboard. XP was previously stored only as cumulative totals on
levelsdocs, so there was nothing to chart —awardXPnow also maintains anxpByDaymap (UTCYYYY-MM-DD→ XP earned) on each member's level doc. One map key per active day keeps doc growth bounded; the existingguildId+xpcomposite index covers the new query.src/services/xpHistory.js(new): pure helpers —dayKey,listDayKeys,addXpToDay, andbuildXpHistory(docs, {days, topUsers})which returns{days, totals, users[]}(guild-wide daily totals across all members + per-member daily series for the top N).src/services/firestore.js: new gatedgetGuildLevels(guildId, limit); returns[]when Firebase is disabled, same contract as the other helpers.GET /api/xp-history?days=&guildId=on the dashboard (behind the existing API-key auth): days clamped 7–90 (default 30), guild defaults toDISCORD_GUILD_ID.index.html: new "XP History" panel — hand-rolled responsive SVG line/area chart (no new deps, matches the dashboard's vanilla JS + gold/glass styling), member selector for top-10 users, hover tooltips, loading/empty/error states,role="img"+aria-label, and a.sr-onlydata table for screen readers. Redraws on resize and refreshes with the existing 30s poll.Validation
npm test: 551/551 pass (12 new cases intest/xpHistory.test.jscovering the aggregation helpers andawardXP'sxpByDaywrite via the in-memory Firestore fake).Note: history accumulates from deploy forward — existing
xptotals aren't backfillable into per-day buckets. README + CHANGELOG updated.