Subtract dietary fiber caloric contribution from calorie target before calculating macro targets - #1531
Conversation
…e calculating macro targets Description: Deducts dietary fiber calories (2 kcal/g) from the daily calorie goal before applying percentage-based macro splits across onboarding, food goals, presets, and backend services.
PR Validation ResultsChange Detection
|
There was a problem hiding this comment.
Code Review
This pull request updates the macronutrient calculations across the frontend and backend to adjust the total calories by subtracting the energy contribution of dietary fiber (calculated as fiber grams multiplied by 2) before computing macro percentages or grams. The review feedback highlights two key areas for improvement: first, in NutrientGoals.tsx, using Math.max(1, ...) as a divisor can lead to abnormally high percentages if adjusted calories are near zero, so it is safer to conditionally divide only when adjusted calories are positive; second, in the backend services, defensive checks should be added to handle cases where calories might be undefined or non-numeric to prevent NaN propagation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Tip
Help us review and merge your PR faster!
Please ensure you have completed the Checklist below.
For Frontend changes, please run
pnpm run validateto check for any errors.PRs that include tests and clear screenshots are highly preferred!
Note: AI-generated descriptions must be manually edited for conciseness. Do not paste raw AI summaries.
Description
What problem does this PR solve?
(Keep it concise. 1–2 sentences.)
Deducts dietary fiber calories (2 kcal/g) from the daily calorie goal before applying percentage-based macro splits across onboarding, food goals, presets, and backend services.
How did you implement the solution?
(Brief technical approach.)
Updated the percentage-to-gram calculators across both the frontend (onboarding, daily goals, presets, previews) and backend (goal services) to deduct dietary_fiber * 2 from the total calorie pool before dividing the remaining budget into protein, carb, and fat targets.
Linked Issue: Closes # #1509
How to Test
...PR Type
Checklist
All PRs:
New features only:
Frontend changes (
SparkyFitnessFrontend/):pnpm run validateand it passes.en) translation file.Backend changes (
SparkyFitnessServer/):rls_policies.sqlfor any new user-specific tables.UI changes (components, screens, pages):
Mobile changes (
SparkyFitnessMobile/):Screenshots
Click to expand
Before
After
Notes for Reviewers