Skip to content

fix: drive the calorie estimate from reps with a duration floor#914

Open
Anexus5919 wants to merge 1 commit into
Somil450:mainfrom
Anexus5919:fix/calorie-estimate-rep-primary
Open

fix: drive the calorie estimate from reps with a duration floor#914
Anexus5919 wants to merge 1 commit into
Somil450:mainfrom
Anexus5919:fix/calorie-estimate-rep-primary

Conversation

@Anexus5919

Copy link
Copy Markdown
Contributor

📌 Related Issue

Fixes #877


📝 Description

estimateCalories accepted totalReps but 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. HistoryPage separately used totalReps × 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) × accuracyMultiplier
    • The 1.5 kcal/rep base matches the per-rep convention already used in HistoryPage, so the two estimates are now consistent, and the existing label thresholds (30 / 100 / 200 kcal) stay meaningful.
    • The duration floor preserves time-based credit for holds (plank logs ~0 reps), so this is a strict improvement.
    • Non-finite/zero rep counts are treated as zero work.
  • src/utils/__tests__/calorieEstimator.test.ts: unit tests.

🔹 Why are these changes needed?

  • For a rep-counting fitness app, calories should reflect work done (reps), scaled by exercise intensity and body weight, not just wall-clock duration. This makes the estimate respond to reps and keeps the summary and history numbers consistent.

🛠️ Type of Change

  • 🐛 Bug Fix

🧪 Testing

✅ Tests Performed

  • Tested locally
  • 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

  • I have read the project's CONTRIBUTING guidelines
  • My code follows the project style guidelines
  • I have performed a self-review of my code
  • I have tested my changes locally
  • I have added/updated documentation where necessary (not applicable)
  • My changes do not introduce new warnings or errors
  • This PR is linked to an existing issue

💬 Additional Notes

Branched from latest upstream/main (5464425). A follow-up (not in this PR) could route HistoryPage's calorie filter through estimateCalories for a single source of truth.

@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

@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.

@Anexus5919

Copy link
Copy Markdown
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.
@Anexus5919 Anexus5919 force-pushed the fix/calorie-estimate-rep-primary branch from 300cd34 to 7e19e45 Compare June 23, 2026 17:34
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.

estimateCalories ignores totalReps (duration-only), inconsistent with HistoryPage's rep-based estimate

1 participant