Skip to content

fix(tdee): resolve inverse calorie goal bug and improve calculation transparency#916

Merged
CodeWithCJ merged 1 commit intomainfrom
dev
Mar 14, 2026
Merged

fix(tdee): resolve inverse calorie goal bug and improve calculation transparency#916
CodeWithCJ merged 1 commit intomainfrom
dev

Conversation

@CodeWithCJ
Copy link
Owner

@CodeWithCJ CodeWithCJ commented Mar 14, 2026

Description

Provide a brief summary of your changes.

This PR addresses a technical bug in the Adaptive TDEE calculation and improves user guidance for health metrics.

Core Fixes:

Decoupled Activity Level from Goal Calculation: Fixed an issue where increasing the activity level setting mathematically decreased the final calorie goal. The calculation now uses a fixed 1.2x BMR (Sedentary) baseline to determine the user's "dietary intent" (deficit/surplus), ensuring the goal remains stable regardless of the activity setting.
Added Expenditure Transparency: Introduced a dedicated "Expenditure" line in the Adaptive TDEE information box on the Diary page. This allows users to see the raw maintenance burn calculated by the server.
Enhanced Settings Guidance: Added a helper note to the Activity Level setting in Calculation Settings to clarify its role as a fallback baseline when using Adaptive mode.
Technical Details:

Modified

DailyProgress.tsx
to standardize the calorieGoalOffset calculation.
Updated

CalculationSettings.tsx
with conditional i18n hints for Adaptive mode.
Verified mathematical stability via unit tests in calorieCalculations.test.ts.

Related Issue

PR type [x] Issue [ ] New Feature [ ] Documentation
Linked Issue: # #908

Checklist

Please check all that apply:

  • [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers
  • Tests: I have included automated tests for my changes.
  • [MANDATORY for UI changes] Screenshots: I have attached "Before" vs "After" screenshots below.
  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate (especially for Frontend).
  • Translations: I have only updated the English (en) translation file (if applicable).
  • Architecture: My code follows the existing architecture standards.
  • Database Security: I have updated rls_policies.sql for any new user-specific tables.
  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code(phishing, malware, etc.) and I agree to the License terms.

Screenshots (if applicable)

Before

[Insert screenshot/GIF here]

After

[Insert screenshot/GIF here]
image

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the Adaptive TDEE calculation that caused calorie goals to invert based on activity level changes. It refines the calculation logic to ensure consistent dietary intent and enhances the user interface by providing greater transparency into maintenance calorie expenditure and clearer guidance within the settings for adaptive mode.

Highlights

  • TDEE Calculation Bug Fix: Resolved an issue where increasing the activity level setting inversely affected the final calorie goal in Adaptive TDEE mode. The calorieGoalOffset now uses a fixed 'not_much' (1.2x BMR) baseline to ensure dietary intent remains stable regardless of the user's activity level setting.
  • Expenditure Transparency: Introduced a dedicated 'Expenditure' line within the Adaptive TDEE information box on the Diary page, allowing users to clearly see their raw maintenance burn calculated by the server.
  • Enhanced Settings Guidance: Added a helper note to the Activity Level setting in Calculation Settings to clarify its role as a fallback baseline when Adaptive mode is in use, improving user understanding.
Changelog
  • SparkyFitnessFrontend/src/pages/Diary/DailyProgress.tsx
    • Modified the calorieGoalOffset calculation to use a fixed 'not_much' activity level for baseline maintenance, ensuring dietary intent stability.
    • Introduced a new display element to show the calculated Expenditure (TDEE) in the daily progress view.
  • SparkyFitnessFrontend/src/pages/Settings/CalculationSettings.tsx
    • Added a conditional helper text paragraph below the Activity Level selector, providing clarification on its function when the calorie goal adjustment mode is set to 'adaptive'.
Activity
  • The author identified and addressed a technical bug in the Adaptive TDEE calculation.
  • The author implemented changes to decouple activity level from goal calculation and improve transparency.
  • Unit tests in calorieCalculations.test.ts were verified for mathematical stability.
  • The author ran pnpm run validate for frontend quality assurance.
  • The changes are linked to issue [Bug]: TDEE Activity level may possibly in reverse #908.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively resolves a critical bug in the adaptive TDEE calculation, where the calorie goal was inversely affected by the activity level setting. The solution, which decouples the user's dietary intent from the activity level by using a fixed baseline, is well-implemented and robust. Furthermore, the added transparency in the UI, such as displaying the raw expenditure and providing contextual hints in the settings, significantly improves the user experience and understanding of the feature. The code changes are clear, well-commented, and directly address the stated goals of the pull request.

@CodeWithCJ CodeWithCJ merged commit 5be2ac6 into main Mar 14, 2026
6 checks passed
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.

1 participant