Skip to content

fix(stats): rank heatmap days by quartile and cover the full 42-day window - #20191

Open
griffinmartin wants to merge 5 commits into
stablyai:mainfrom
griffinmartin:fix/usage-heatmap-rank-scale
Open

griffinmartin wants to merge 5 commits into
stablyai:mainfrom
griffinmartin:fix/usage-heatmap-rank-scale

Conversation

@griffinmartin

@griffinmartin griffinmartin commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Two reasons the "Daily intensity" heatmap on Stats & Usage looked empty even on busy days:

  1. It shaded each day relative to your single biggest day. When one provider has multi-billion-token days and another has hundred-million-token days, the second one's days all land in the faintest shade, which in the dark theme reads as "no activity". Days are now ranked: the top quarter of active days get the darkest shade, the next quarter the next, and so on. Idle days still render empty, and the best day is still the darkest.
  2. It draws 42 days but was fed the provider tabs' data, whose range defaults to 30 days, so the first twelve cells were always blank no matter what you did. The heatmap now fetches a window that covers every cell it draws.

What Changed

Rank scale (usage-overview-daily-series.ts): buildDailyOverview no longer computes intensity as totalTokens / maxTokens bucketed at 25/50/75%. A new exported rankUsageIntensities(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 existing bestDay and zero-padding expectations are unchanged.

Heatmap window (UsageOverviewPane.tsx): the pane now fetches its own daily series per enabled provider with range: '90d' (covering the 42 rendered days) while keeping each tab's current scope, rebuilds the grid from that series, and picks the Best: 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

image

After

image

Testing

  • pnpm test src/renderer/src/components/stats/ — 5 files, 15 tests pass

  • tsc --noEmit -p config/tsconfig.tc.web.json — clean

  • oxlint src/renderer/src/components/stats/ — clean

  • Rank 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 getSnapshot per 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

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and 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

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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.
@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 507dc5e0-b876-4e31-a06d-89f67684de6f
📥 Commits

Reviewing files that changed from the base of the PR and between db6ab28 and 0262a7b.

📒 Files selected for processing (3)
  • src/renderer/src/components/stats/UsageOverviewPane.tsx
  • src/renderer/src/components/stats/usage-overview-daily-series.ts
  • src/renderer/src/components/stats/usage-overview-model.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change adds rank-based intensity levels for active daily totals. Zero totals retain intensity 0, and tied totals receive the same level. buildDailyOverview sorts daily entries before assigning ranked intensities. UsageOverviewPane loads separate 90-day snapshots for enabled providers and uses the fetched data to build its 42-day heatmap and select its highlighted best day. Tests cover spread, ties, a single active value, empty input, and all-zero input.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 0262a

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive The linked issue assessment could not be completed. Retry the assessment when the required review evidence is available.
Out of Scope Changes check ❓ Inconclusive The linked issue assessment could not be completed. Retry the assessment when the required review evidence is available.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main changes: quartile-based heatmap ranking and coverage of the full 42-day window.
Description check ✅ Passed The description covers the required sections with clear change details, rationale, linked issue, before-and-after screenshots, testing, and checklist responses.
  • Fix all pre-merge checks with AI

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 — rankUsageIntensities replaces linear scaling: idle days stay 0, the best day stays 4, ties share the higher rank, a lone active day is 4.
  • buildDailyOverview simplification — drops the manual maxTokens loop 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@griffinmartin griffinmartin changed the title fix(stats): rank heatmap days by quartile instead of scaling to the best day fix(stats): rank heatmap days by quartile and cover the full 42-day window Sep 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 94671355-818c-4ae2-8c46-2c3561f18380

📥 Commits

Reviewing files that changed from the base of the PR and between 4dbe276 and e485989.

📒 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
@griffinmartin

Copy link
Copy Markdown
Contributor Author

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

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

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 — rankUsageIntensities now builds a value→cumulative-count Map, 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 — UsageOverviewPane re-ranks the exact 42 days it draws (and picks the Best: 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.

Pullfrog  | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@griffinmartin

Copy link
Copy Markdown
Contributor Author

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]>

This branch has not been deployed

No deployments
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.

Stats heatmap shows active days as idle: linear scale to the best day, and a 42-cell grid fed by 30 days of data

1 participant