-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve summary report monthly average calculation #4302
improve summary report monthly average calculation #4302
Conversation
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Bundle Stats — desktop-clientHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset
View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger
Smaller No assets were smaller Unchanged
|
Bundle Stats — loot-coreHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset No files were changed View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller No assets were smaller Unchanged
|
db357b7
to
df95ad2
Compare
df95ad2
to
7e1dcba
Compare
WalkthroughThe changes involve significant updates to date handling and calculations in the Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts (1)
202-206
: LGTM! Average calculation now correctly handles partial months.The implementation accurately calculates averages by:
- Using actual elapsed days for the current month
- Maintaining full month counts for past months
- Properly handling the transition between months
This aligns perfectly with the PR objective of improving average accuracy throughout the month.
Consider improving readability with descriptive variable names and comments:
- const dayOfMonth = months.at(-1)!.getDate(); - const daysInMonth = monthUtils.getDay( - monthUtils.lastDayOfMonth(months.at(-1)!), - ); - const numMonths = months.length - 1 + dayOfMonth / daysInMonth; + // Calculate the fraction of the last month that has elapsed + const lastMonthElapsedDays = months.at(-1)!.getDate(); + const lastMonthTotalDays = monthUtils.getDay( + monthUtils.lastDayOfMonth(months.at(-1)!), + ); + // Add the elapsed fraction to the count of full months + const effectiveMonths = months.length - 1 + lastMonthElapsedDays / lastMonthTotalDays; - const averageAmountPerMonth = totalAmount / numMonths; + const averageAmountPerMonth = totalAmount / effectiveMonths; - divisor: numMonths, + divisor: effectiveMonths,Also applies to: 209-209, 214-214
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
upcoming-release-notes/4302.md
is excluded by!**/*.md
📒 Files selected for processing (1)
packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Functional
- GitHub Check: Visual regression
🔇 Additional comments (1)
packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts (1)
51-54
: LGTM! End date determination logic aligns with PR objectives.The updated logic correctly handles both current and past months by:
- Using the current day for the current month
- Using the last day for past months
This change improves average calculation accuracy by preventing future days from affecting current month averages.
Let's verify the edge cases:
✅ Verification successful
🏁 Script executed:
#!/bin/bash # Description: Verify edge cases in date handling # Test: Search for date-related error handling rg -A 5 'catch.*error.*date' # Test: Search for date validation checks rg -A 5 'isValid.*date'Length of output: 2778
LGTM! Edge case verification confirms the updated end date logic is sound.
The shell scripts did not reveal any issues with date validation or error handling that would impact the new logic. The edge case checks indicate that:
- The current month correctly utilizes the actual day (via
monthUtils.currentDay()
).- Past months appropriately compute the last day using
monthUtils.lastDayOfMonth(end)
.This aligns with the PR objectives for improving the monthly average calculation accuracy by avoiding future day values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, I also tested it on preview 👍
packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts
Outdated
Show resolved
Hide resolved
163080a
to
4c9cf92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me. @lelemm What do you think?
I will take a look tomorrow if possible. No PC access until tomorrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
At the moment summary reports take into account the entire current month when doing the average calculation.
This makes the average too low at the start of the month and is only accurate at the end.
This changes the divisor to accurately calculate for the amount of time through the current month (Screenshots taken on the 6th of February).
Before:

After:
