feat: estimate missing calories from power/HR data - #83
Open
lrybak wants to merge 2 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #83 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 6 7 +1
Lines 1255 1468 +213
==========================================
+ Hits 1255 1468 +213
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Owner
|
This is super cool, thanks for the contribution! Can you make sure the test coverage gets up to 100%, and then I'll take a look when it's ready? Thanks! |
lrybak
marked this pull request as ready for review
July 21, 2026 08:09
Contributor
Author
|
Hello @jat255, any chance you will have a look into PR? |
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.
Summary
Some devices — most notably the Hammerhead Karoo — don't write
total_caloriesto their FIT files. After uploading, Garmin Connect shows the activity with 0 kcal, which also skews daily calorie totals and the nutrition module. This PR adds an opt-in, per-profile feature that estimates the missing value from data already recorded in the file and writes it into the Session and Lap messages.Full transparency: this change was vibe-coded with Claude Code — but every part of it was reviewed, tested against real FIT files from my own rides, and the uploaded results were verified in Garmin Connect.
How it works
A new
calorie_calculator.pymodule supports two methods, in order of preference:integrates mechanical work from the power samples and converts kJ → kcal
assuming 22% gross efficiency (
1 kJ ≈ 1.086 kcal), the same conventionused by Hammerhead, Garmin, and Strava. No personal data needed.
weight, age, and sex (stored in the profile, used for nothing else).
The estimation is defensive by design:
filled in,
Writing the value required a small workaround in
fit_editor.py: when the source file's definition message doesn't includetotal_calories, the field is not growable infit_tool, so the editor flips the flag and resets the cached definition soFitFileBuilder(auto_define=True)regenerates it.Configuration / UI
Profilefields:recalculate_calories,weight_kg,age,sex(all optional; existing configs load unchanged, no migration needed).--list-profiles/ TUI) got a "Kcal est." column showing which profiles have the feature enabled.Tests
config.pyandapp.pystays at 100%.tests/test_calorie_calculator.py(14 tests): power integration math, trapezoidal integration, single-sample and extended power dropouts (with and without HR data), HR fallback, method selection, gap clamping, per-lap split consistency including samples falling between or before laps.tests/test_fit_editor.py: end-to-end test on a real Karoo file (calories get injected and survive a rebuild/re-parse round trip) and a guard test proving existing calories are not touched (Zwift file).tests/test_config.py: new profile fields, legacy config compatibility, wizard flows including clearing anthropometric data, profiles table.Docs
README.md/docs/index.md.AGENTS.mdupdated with the new module.