fix: drive the calorie estimate from reps with a duration floor#914
Open
Anexus5919 wants to merge 1 commit into
Open
fix: drive the calorie estimate from reps with a duration floor#914Anexus5919 wants to merge 1 commit into
Anexus5919 wants to merge 1 commit into
Conversation
|
@Anexus5919 is attempting to deploy a commit to the somiljain2024-4175's projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
@Somil450 @diksha78dev Kindly have a review on this pr. Thanks! |
estimateCalories accepted totalReps but computed calories purely from session duration (MET x weight x hours), so an idle-long session scored higher than an intense short one and the rep count had no effect. Make work done the primary driver: reps x 1.5 x (MET / default MET) x (weight / 70), keeping the MET x weight x duration term as a floor so isometric holds (plank) still get time-based credit. The 1.5 kcal/rep base matches the per-rep convention already used in HistoryPage, so the two estimates are consistent.
300cd34 to
7e19e45
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Related Issue
Fixes #877
📝 Description
estimateCaloriesacceptedtotalRepsbut computed calories purely from session duration (MET × weight × hours), so the rep count had no effect and an idle, long session out-scored an intense, short one.HistoryPageseparately usedtotalReps × 1.5, so the summary and history estimates disagreed.🔹 What has been changed?
src/utils/calorieEstimator.ts: make work done the primary driver, keeping a duration floor for isometric holds:calories = max(reps × 1.5 × (MET / default MET) × (weight / 70), MET × weight × hours) × accuracyMultiplier1.5 kcal/repbase matches the per-rep convention already used inHistoryPage, so the two estimates are now consistent, and the existing label thresholds (30 / 100 / 200 kcal) stay meaningful.src/utils/__tests__/calorieEstimator.test.ts: unit tests.🔹 Why are these changes needed?
🛠️ Type of Change
🧪 Testing
✅ Tests Performed
npx vitest run src/utils/__tests__/calorieEstimator.test.ts-> 9 tests pass (reps drive the result, MET scaling, weight scaling, accuracy multiplier, the duration floor for holds, the 1-calorie floor, default-MET fallback, NaN-rep guard).npx tsc --noEmit: changed files clean;npx eslint: 0 problems.🌐 Browsers Tested
Not applicable (pure calculation logic; verified via unit tests).
📷 Screenshots / Demo (if applicable)
Not applicable.
📋 Checklist
💬 Additional Notes
Branched from latest
upstream/main(5464425). A follow-up (not in this PR) could routeHistoryPage's calorie filter throughestimateCaloriesfor a single source of truth.