diet-guard/app/lib/services/body_steps.dart
Krzysztof kuhy Rudnicki e761926df4
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
file-length / file length <= 250 lines (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Has been cancelled
Tests / test (push) Has been cancelled
release-apk / release (APK) (push) Has been cancelled
Body tab: weight/body-fat logs, BMI, ideal weight, goal-based kcal target, workouts + Health Connect steps, week planner
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-28 09:03:03 +02:00

31 lines
1.2 KiB
Dart

/// Daily steps (from Health Connect, phone-written) as exercise kcal.
///
/// Only steps above [stepBaseline] count: the `BMR x 1.2` sedentary
/// baseline the measured TDEE starts from already assumes a few thousand
/// steps of ordinary movement. The rest are walking at the per-km rate
/// (0.5 kcal per kg per km, net of resting) over a stride estimated from
/// height. Port of `diet_guard/_body_steps.py`.
library;
import 'package:diet_guard_app/services/body_calc.dart';
/// Steps a day the sedentary baseline already covers.
const int stepBaseline = 4000;
// Stride as a fraction of height (the common pedometer estimate).
const double _strideMale = 0.415;
const double _strideFemale = 0.413;
const double _walkKcalPerKgKm = 0.5;
const double _mPerKm = 1000;
/// Estimated walking stride in metres.
double strideM(Biometrics bio) =>
bio.heightCm / 100.0 * (bio.isMale ? _strideMale : _strideFemale);
/// Net kcal of the steps above the baseline, as walking.
double stepKcal(int steps, Biometrics bio) {
final extra = steps > stepBaseline ? steps - stepBaseline : 0;
final km = extra * strideM(bio) / _mPerKm;
return km * _walkKcalPerKgKm * bio.weightKg;
}