Repository navigation
fix(stats): rank heatmap days by quartile and cover the full 42-day window - #20191
griffinmartin wants to merge 5 commits into
Conversation
…est day Daily token volume spans orders of magnitude across providers, so a linear ramp against the single best day put nearly every active day at the faintest level, indistinguishable from idle days. Each non-zero level now holds a quarter of the active days; idle days stay 0 and the best day stays 4.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe change adds rank-based intensity levels for active daily totals. Zero totals retain intensity 0, and tied totals receive the same level. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The heatmap data request covers the displayed days. No actionable merge-blocking risk is established. 🚥 Pre-merge checks | ✅ 2 | ❌ 1 | ❓ 2❌ Failed checks (1 warning, 2 inconclusive)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The overview heatmap renders 42 days but was fed the provider tabs' daily series, whose range defaults to 30d, so the first twelve cells always rendered as idle. The heatmap now fetches its own 90d series per enabled provider (keeping each tab's scope) and picks its best day from that window.
There was a problem hiding this comment.
Important
rankUsageIntensities is O(n²) on the number of scanned days — for every day it rescans the sorted active array from the end. The pre-existing 130k-day test now sits at 4.55s against Vitest's 5s default timeout, so this is a CI flake risk and seconds of renderer jank. A one-pass fix is suggested inline.
Reviewed changes
- Quartile rank shading —
rankUsageIntensitiesreplaces linear scaling: idle days stay 0, the best day stays 4, ties share the higher rank, a lone active day is 4. buildDailyOverviewsimplification — drops the manualmaxTokensloop in favor of the new rank function.- Tests — two unit tests cover a 200x spread, ties, single-day, and empty input; existing
bestDay/zero-padding expectations are unchanged.
ℹ️ Rank quartiles span the full scan history, not the rendered 42-day window
buildDailyOverview ranks every day in overview.daily, but UsageOverviewPane renders only RECENT_DAY_COUNT = 42. For a user with a long history, the visible window's shades are positions within all-time quartiles, so recent activity can still cluster at low levels whenever past volume was higher — close to the problem this PR set out to fix. Is all-time ranking intended, or should the quartiles be computed over the displayed window? If all-time is intentional, the JSDoc should say so.
Technical details
# Ranking window vs. rendering window
## Affected sites
- `src/renderer/src/components/stats/usage-overview-daily-series.ts:82` — ranks the full `entries` array.
- `src/renderer/src/components/stats/UsageOverviewPane.tsx:13,88` — renders only `RECENT_DAY_COUNT = 42` days via `getRecentUsageDays`.
## Open questions for the human
- Should quartiles be computed over all scanned days, or over the days actually rendered?
- If all-time is intended, can the JSDoc or legend make that explicit?ℹ️ Nitpicks
- The JSDoc claims "each non-zero level holds a quarter of the active days", but with fewer than four active days the low levels are unreachable — three distinct active days produce levels 2/3/4, and one active day jumps straight to 4. Worth softening the wording or noting the small-N behavior.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 94671355-818c-4ae2-8c46-2c3561f18380
📒 Files selected for processing (1)
src/renderer/src/components/stats/UsageOverviewPane.tsx
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
…ch failures - rankUsageIntensities uses a value-to-cumulative-count map instead of a per-day rescan (O(n^2) on 130k-day histories) - the overview re-ranks the 42 days it draws, so shades are quartiles of the visible window rather than of the whole fetched history - a failed provider snapshot logs and yields an empty series instead of rejecting the whole heatmap load
|
Review round-up as of 2d8555d: the O(n²) rank scan is replaced with a cumulative-count map; shades are now quartiles of the 42 rendered days, not all-time history (Pullfrog's window note); a failed provider snapshot no longer blanks the heatmap (CodeRabbit). The linked issue is now #20193, which describes the heatmap defects specifically, so the Linked Issues check no longer compares this PR against the token-count requirements in #20186. |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Two commits landed since the last Pullfrog review, both addressing the O(n²) finding and the ranking-window question raised there:
- O(n) rank lookup —
rankUsageIntensitiesnow builds a value→cumulative-countMap, so each day's intensity is O(1); ties still take the higher rank because the last index written for a value wins. The 130k-day test runs in 199ms instead of ~4.5s. - Window-scoped shading —
UsageOverviewPanere-ranks the exact 42 days it draws (and picks theBest:badge from the same window) rather than positioning them within all-time quartiles. - Heatmap window fetch — the pane fetches its own
range: '90d'daily series per enabled provider while keeping each tab's current scope, so every drawn cell is backed by data. - Per-provider fetch isolation — one provider's fetch failure logs and contributes an empty series instead of blanking the others.
Verified locally: pnpm test src/renderer/src/components/stats/usage-overview-model.test.ts (7 pass), pnpm tc:web, and oxlint on the changed files all clean. The prior O(n²) thread is resolved and the fix matches the suggested approach.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
Pullfrog's JSDoc nit is addressed in db6ab28: the rank doc now says "roughly a quarter" and spells out the small-N behaviour (one active day is level 4, three distinct days are 2/3/4). Same commit adds JSDoc to the other touched renderer helpers for the docstring check. Visual proof is in the description. |
Reconcile the rank-based heatmap intensity with the Muse provider that landed upstream. - usage-overview-daily-series.ts: keep upstream's emptyDailyTotals helper and the Muse accumulation loop, keep rank-based intensity, and drop the now-unused linear getIntensity ramp. - UsageOverviewPane.tsx: keep both store selector groups, and extend the heatmap's own wide-window fetch to Muse so its cells match the other three providers. - usage-overview-model.test.ts: keep both sides' tests. Co-Authored-By: Claude Opus 5 <[email protected]>

ELI5
Two reasons the "Daily intensity" heatmap on Stats & Usage looked empty even on busy days:
What Changed
Rank scale (
usage-overview-daily-series.ts):buildDailyOverviewno longer computesintensityastotalTokens / maxTokensbucketed at 25/50/75%. A new exportedrankUsageIntensities(totals)sorts the non-zero days and assigns each level a quartile of them via a value-to-cumulative-count map (O(n log n)); ties share the higher rank so equal days never render differently, a lone active day is level 4, and idle days stay 0. The overview pane re-ranks over the 42 days it actually draws, so shades are quartiles of the visible window rather than of all-time history. Tests cover a 200x spread, ties, the single-day case, and empty input; the existingbestDayand zero-padding expectations are unchanged.Heatmap window (
UsageOverviewPane.tsx): the pane now fetches its own daily series per enabled provider withrange: '90d'(covering the 42 rendered days) while keeping each tab's current scope, rebuilds the grid from that series, and picks theBest:badge from the same window. It refetches when a scope changes or a scan completes, and a failed provider fetch logs and contributes an empty series instead of blanking the others. The totals cards, the provider rows, and "Active days" still follow the tab filters exactly as before.No markup or styling changes; the legend and tooltips are untouched.
Why
Linear scaling answers "how close is this day to my record", which is what the
Best:badge already shows. The heatmap's job is to show when you were active and roughly how much, and a rank scale keeps that legible regardless of how far apart providers are in volume. And a 42-cell grid backed by 30 days of data cannot be read at all: the leading cells look identical to idle days. On my machine (Claude + Codex + OpenCode, best day 3.5B tokens), 30 of 33 active days in the last six weeks rendered at level 1, and Aug 1–12 rendered idle despite daily activity.Linked Issue
Fixes #20193 (heatmap). The token-count defect it was first noticed alongside is #20186 / #20187.
Visual Proof
Both screenshots are local packaged builds of the same profile, taken minutes apart. Before is #20187's branch alone (token fix, unchanged heatmap) with the default filters (Orca worktrees only, 30d). After is this branch on top of #20187 with the three provider tabs set to "All local usage / All", which is why the totals and active-day count also differ; the heatmap changes themselves are the shading spread and the previously blank Aug 1–12 cells.
Before
After
Testing
pnpm test src/renderer/src/components/stats/— 5 files, 15 tests passtsc --noEmit -p config/tsconfig.tc.web.json— cleanoxlint src/renderer/src/components/stats/— cleanRank scale verified in a local packaged build on macOS (Apple Silicon); the window fix is built and the screenshots above will come from that build. Renderer-only change; no platform, SSH, or mobile surface. The extra fetch is one
getSnapshotper enabled provider on mount, scope change, or scan completion.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Claude Fable 5.1 (via Claude Code) implemented the change and tests and drafted this description; I reviewed the diff and the rendered result.
Review
Small, renderer-only: one function replaced plus a heatmap-scoped fetch in the overview pane. Independent of #20187 (different files); either can merge first.
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Pure presentation change; no data, security, or cross-platform impact. In paired web clients the usage APIs resolve
undefined, which the fetch treats as an empty series, matching the existing slices.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)