Skip to content

feat(level): chart XP over time in /level check - #82

Merged
guirguispierre merged 1 commit into
guirguispierre:mainfrom
CommunityPokeOrg:devin/1791303198-level-xp-chart
Oct 6, 2026
Merged

guirguispierre merged 1 commit into
guirguispierre:mainfrom
CommunityPokeOrg:devin/1791303198-level-xp-chart

Conversation

@CommunityPoke

Copy link
Copy Markdown
Contributor

Summary

/level check now shows a chart of XP over time, addressing the feature request for a visible XP history graph.

There was no historical XP data — each levels doc only stored the current xp total. This PR adds a bounded xpByDay map ('YYYY-MM-DD' → cumulative total XP, UTC) written in the existing awardXP set(..., { merge: true }) call, so history accumulates at one field per day with no extra writes.

/level check renders the last 30 days as a line chart PNG and attaches it to the embed (attachment://xp-chart.png). The SVG is generated in src/utils/xpChart.js and rasterized with sharp — already a dependency — lazy-required so tests and non-chart paths never load the binary. The SVG deliberately contains no <text> elements: node:20-slim ships no fontconfig fonts, so labels would render blank; the date range is conveyed in the embed footer instead.

Behavior:

  • ≥ 2 days of history → chart attached, footer reads "XP over the last N days". Today's point is always synthesized from the live total so the chart ends at the true value even before today's award writes back.
  • < 2 days (new users / pre-existing docs) → plain embed with footer "XP history builds over time — check back tomorrow". History starts accumulating from the next awardXP onward; xpByDay[today] correctly reflects the all-time total rather than only new XP.
  • Chart render failure → caught, degrades to the stats embed without an image.

Tests

node --test — 550 tests pass, including 11 new in test/levelXpChart.test.js covering buildXPChartPoints (sorting, today upsert, malformed keys, 30-day cap), text-free SVG output, awardXP xpByDay writes/accumulation, and /level check attachment + footer behavior.

Record cumulative XP per UTC day (xpByDay map) on each awardXP write,
then render the last 30 days as a line chart in /level check replies.

- src/utils/xpChart.js: text-free SVG chart rasterized via existing
  sharp dep (lazy-required; no <text> so it works without fontconfig)
- /level check attaches xp-chart.png when >= 2 days of history exist,
  otherwise notes history is still being collected
- chart render failure degrades to the plain stats embed
- test/levelXpChart.test.js covers point building, SVG output, awardXP
  history writes, and /level check attachment behavior

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@guirguispierre
guirguispierre merged commit 69e2123 into guirguispierre:main Oct 6, 2026
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.

2 participants