Skip to content

fix(frontend): average savings over the requested window - #467

Open
cristim wants to merge 1 commit into
mainfrom
fix/platform245-savings-window-average
Open

cristim wants to merge 1 commit into
mainfrom
fix/platform245-savings-window-average

Conversation

@cristim

@cristim cristim commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Sparse savings-history responses currently divide projected monthly savings by the number of returned rows. Three active hourly buckets totaling $1,680 over seven days display $560/mo. Use the actual requested elapsed window and interval so the same response displays $10/mo, including omitted zero buckets.

Preserves total, peak, display-unit conversions and the optional legacy summary average. The values remain projected monthly savings additions, not realized savings.

Closes #245

Independent gpt-6-astra review approved exact commit bdd09d1336d712914bac04b6b37ae5b0a51657d1 under the authorized local review alternative. Both implementation review passes were clean. Independent verification rebuilt the production bundle, passed 91 Jest tests and 11 Chromium regressions, and ran production SavePurchaseHistory, QueryHistory and response serialization on PostgreSQL 16 with the race detector. Replaying that fresh SQL response through the matching production bundle showed $10/mo, total $1.68K and peak $560/mo with no page or console errors. The committed regression failed against the original bundle with expected $10/mo and actual $560/mo; row-count and extra-endpoint divisor mutations also failed.

Coverage includes all four UI windows, omitted and explicit zero buckets, complete controls, display units, empty/error states, narrow viewport and both Berlin DST transitions. Local proof uses synthetic purchase inputs and HTTP auth fixtures; no live-cloud purchases were performed. CI remains a separate publication gate.

Summary by CodeRabbit

  • Bug Fixes
    • Savings averages now account for every interval in the selected time window, including intervals with no recorded data.
    • Average values display in the appropriate hourly, monthly, or yearly units for the selected period.
    • Statistics remain visible when a populated time window has zero savings.
    • Date ranges and interval counts now reflect the selected period, including across daylight-saving time changes.

Count elapsed hourly or daily periods, including periods without
purchases, while preserving projected monthly savings units.

Verify sparse and zero-filled windows, unit switches, partial endpoints,
and daylight saving transitions through the rendered production bundle.
@cristim cristim added severity/medium Moderate harm urgency/this-sprint Within the current sprint triaged Item has been triaged priority/p1 Next up; this sprint impact/all-users Affects every user effort/s Hours type/bug Defect labels Oct 1, 2026
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: LeanerCloud/cloud-commitments-platform/.coderabbit.yaml

Review profile: CHILL

Plan: Essentials

Run ID: 08b93f76-4e63-45be-a3fa-9735f6998b6d

📥 Commits

Reviewing files that changed from the base of the PR and between 6d9a70f and bdd09d1.

📒 Files selected for processing (3)
  • frontend/src/__tests__/savings-history.test.ts
  • frontend/src/modules/savings-history.ts
  • frontend/tests-e2e/savings-history-average.spec.ts

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.


📝 Walkthrough

Walkthrough

Savings history fallback averages now divide total savings by the hourly or daily intervals in the selected window, including intervals without data. Unit and end-to-end tests cover period lengths, display states, and daylight-saving transitions.

Changes

Requested-window savings averages

Layer / File(s) Summary
Requested-window average calculation and validation
frontend/src/modules/savings-history.ts, frontend/src/__tests__/savings-history.test.ts, frontend/tests-e2e/savings-history-average.spec.ts
The renderer receives the selected date bounds and interval. When the API does not provide an average, the fallback divides total savings by the elapsed intervals in the requested window. Unit and browser tests cover period calculations, average displays, empty and error responses, and daylight-saving transitions.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to bdd09

The average now reflects the selected window rather than purchase density. No actionable merge-blocking risk is established; merge after normal CI checks pass.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: calculating average savings over the requested window.
Linked Issues check ✅ Passed Issue #245 requires the average to use the requested window periods instead of only non-empty buckets. loadSavingsHistory now passes the selected start date, end date, and interval to `renderSavings…
Out of Scope Changes check ✅ Passed The changed source file implements the denominator correction. The unit tests and end-to-end tests verify requested windows, empty intervals, display units, zero values, errors, viewport behavior, and…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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

@cristim

cristim commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

The automatic CodeRabbit summary covers base 6d9a70f614afd72ded5b17d4bd3bae6960695077 through head bdd09d1336d712914bac04b6b37ae5b0a51657d1 and reports no actionable comments. Submitted reviews and inline comments are empty at this check.

The generic docstring-coverage suggestion is dismissed under the owner's sparse-comment convention: comments should explain a non-obvious constraint, rather than repeat clear code or test descriptions. No source change is warranted by that metric. Independent exact-commit local review and its reproduced evidence remain recorded in the PR body. CI is still running; this comment does not assert merge readiness.

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

effort/s Hours impact/all-users Affects every user priority/p1 Next up; this sprint severity/medium Moderate harm triaged Item has been triaged type/bug Defect urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(frontend): "Avg Monthly Savings" divides by non-empty buckets, not by periods

1 participant