Skip to content

Offline gym log for Android. No account, no ads, no internet.

Estimate cardio calories and show strength per bodyweight

InlitXc258f5c5f4a0
diff --git a/lib/screens/progress_screen.dart b/lib/screens/progress_screen.dart
index 61d7d44..4a0f114 100644
--- a/lib/screens/progress_screen.dart
+++ b/lib/screens/progress_screen.dart
@@ -1447,6 +1447,10 @@ class _StrengthCard extends StatelessWidget {
),
],
),
+ if (fit.relativeStrength(id) case final rel?) ...[
+ const SizedBox(height: 10),
+ _relative(gc, rel),
+ ],
const SizedBox(height: 12),
TrendChart(values: [for (final v in series) fit.toDisplayWeight(v)], height: 96, scale: fmt),
const SizedBox(height: 8),
@@ -1465,6 +1469,52 @@ class _StrengthCard extends StatelessWidget {
];
}
+ Widget _relative(GymColors gc, ({double ratio, int level, double toNext}) rel) {
+ return Semantics(
+ label: '${t.timesBodyweight(decimalText(rel.ratio.toStringAsFixed(2)))} · ${t.dotsLevelName(rel.level)}',
+ excludeSemantics: true,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Row(children: [
+ Expanded(
+ child: Text(t.timesBodyweight(decimalText(rel.ratio.toStringAsFixed(2))),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.s(12.5, weight: FontWeight.w600, color: gc.textSecondary)),
+ ),
+ const SizedBox(width: 8),
+ Text(t.dotsLevelName(rel.level),
+ style: AppTheme.f(12, weight: FontWeight.w700, color: gc.brass)),
+ ]),
+ const SizedBox(height: 7),
+ Row(children: [
+ for (var i = 0; i < 5; i++) ...[
+ if (i > 0) const SizedBox(width: 3),
+ Expanded(
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(2),
+ child: SizedBox(
+ height: 4,
+ child: ColoredBox(
+ color: gc.bgRaised2,
+ child: FractionallySizedBox(
+ alignment: AlignmentDirectional.centerStart,
+ widthFactor: i < rel.level ? 1 : (i == rel.level ? rel.toNext : 0),
+ heightFactor: 1,
+ child: ColoredBox(color: gc.brass),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ]),
+ ],
+ ),
+ );
+ }
+
void _pick(BuildContext context, String current, List<({String id, String name, int sessions})> tracked) {
showAppSheet<void>(
context: context,
@@ -1916,6 +1966,7 @@ class _DaySheet extends StatelessWidget {
Widget _loggedRow(BuildContext context, GymColors gc, LoggedSession s, LoggedExercise e) {
final detail = fit.setsSummary(e.sets);
+ final kcal = fit.cardioKcal(s, e);
return Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Row(
@@ -1937,6 +1988,11 @@ class _DaySheet extends StatelessWidget {
Text(t.catalogName(e.id, e.name), style: AppTheme.s(13, weight: FontWeight.w600, color: gc.text)),
const SizedBox(height: 2),
Text(detail, style: AppTheme.s(11, color: gc.textSecondary)),
+ if (kcal != null) ...[
+ const SizedBox(height: 2),
+ Text('${kcal.own ? '' : '≈ '}${fit.energyOf(kcal.active)} ${fit.energyUnit} ${t.kcalActive}',
+ style: AppTheme.s(11, weight: FontWeight.w600, color: gc.warn)),
+ ],
],
),
),
@@ -2125,6 +2181,10 @@ void showEditLoggedSheet(BuildContext context, LoggedSession s, LoggedExercise e
weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 1)),
),
),
+ if (fit.loggedDistance(e) && fit.walksOrRuns(e)) ...[
+ const SizedBox(height: 12),
+ _cardioKcalCard(sheetCtx, gc, s, e),
+ ],
const SizedBox(height: 16),
PrimaryButton(label: t.done, onTap: () => Navigator.pop(sheetCtx), height: 52),
],
@@ -2137,6 +2197,89 @@ void showEditLoggedSheet(BuildContext context, LoggedSession s, LoggedExercise e
);
}
+Widget _cardioKcalCard(BuildContext context, GymColors gc, LoggedSession s, LoggedExercise e) {
+ final kcal = fit.cardioKcal(s, e);
+ final incline = e.incline ?? 0;
+ Widget link(String label, VoidCallback onTap) => GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 8),
+ child: Text(label, style: AppTheme.s(13, weight: FontWeight.w600, color: gc.accent)),
+ ),
+ );
+ return Container(
+ padding: const EdgeInsets.fromLTRB(14, 12, 14, 6),
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(14)),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ Icon(PhosphorIconsFill.fire, size: 18, color: gc.warn),
+ const SizedBox(width: 8),
+ if (kcal == null)
+ Expanded(child: Text(t.kcalNeedsData, style: AppTheme.s(13, color: gc.textSecondary)))
+ else ...[
+ Text('${kcal.own ? '' : '≈ '}${fit.energyOf(kcal.active)} ${fit.energyUnit}',
+ style: AppTheme.d(20, weight: FontWeight.w700, color: gc.text)),
+ const SizedBox(width: 6),
+ Expanded(
+ child: Text('${t.kcalActive} · ${kcal.own ? t.kcalYours : t.kcalEstimated}',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.s(12, color: gc.textSecondary)),
+ ),
+ ],
+ ],
+ ),
+ if (kcal != null) ...[
+ const SizedBox(height: 4),
+ Text(t.kcalTotalRest('${fit.energyOf(kcal.total)} ${fit.energyUnit}'),
+ style: AppTheme.s(11.5, color: gc.textTertiary)),
+ ],
+ const SizedBox(height: 10),
+ Row(
+ children: [
+ Expanded(child: Text(t.inclineLabel, style: AppTheme.s(13, weight: FontWeight.w500, color: gc.text))),
+ StepperControl(
+ value: '${fmt(incline)} %',
+ onDec: () => fit.setLoggedIncline(e, incline - 0.5),
+ onInc: () => fit.setLoggedIncline(e, incline + 0.5),
+ onEdit: () async {
+ final v = await askNumber(context, title: t.inclineLabel, initial: fmt(incline), decimal: true);
+ if (v != null) fit.setLoggedIncline(e, v);
+ },
+ minWidth: 52,
+ btnSize: 26,
+ gap: 8,
+ fontSize: 14,
+ ),
+ ],
+ ),
+ if (kcal != null && !kcal.own) ...[
+ const SizedBox(height: 6),
+ Text(t.kcalHowEstimated, style: AppTheme.s(11, color: gc.textTertiary, height: 1.35)),
+ ],
+ Row(
+ children: [
+ link(t.kcalUseOwn, () async {
+ final v = await askNumber(context,
+ title: t.kcalOwnTitle, initial: kcal == null ? '' : '${fit.energyOf(kcal.active)}', decimal: false);
+ if (v != null) fit.setLoggedKcal(e, fit.kcalFromShown(v).round());
+ }),
+ if (e.kcal != null) ...[
+ const SizedBox(width: 18),
+ link(t.kcalBackToEstimate, () => fit.setLoggedKcal(e, null)),
+ ],
+ ],
+ ),
+ ],
+ ),
+ );
+}
+
Widget _editSetRow(GymColors gc, LoggedSession s, LoggedExercise e, int i, bool repsOnly) {
final set = e.sets[i];
final distance = fit.loggedDistance(e);
diff --git a/lib/state/stats_state.dart b/lib/state/stats_state.dart
index 2d9be2e..62ae7da 100644
--- a/lib/state/stats_state.dart
+++ b/lib/state/stats_state.dart
@@ -422,6 +422,68 @@ mixin StatsState on FitCore, ToolsState, LibraryState, SettingsState, TimelineSt
bool loggedDistance(LoggedExercise e) => isCardio(e.id) || e.sets.any((s) => (s.km ?? 0) > 0);
+ static const double _walkRunMpm = 120;
+ static const _walkRunIds = {'running', 'walking', 'treadmill-incline-walk', 'hiking'};
+ static final _walkRunName = RegExp(r'\b(walk|run|jog|treadmill|hik|camin|corr|carrer|trot|cinta|sender|marcha)');
+
+ bool walksOrRuns(LoggedExercise e) =>
+ _walkRunIds.contains(e.id) || (isCustom(e.id) && _walkRunName.hasMatch(e.name.toLowerCase()));
+
+ double _weightOn(DateTime day) {
+ BodyweightEntry? best;
+ for (final b in bodyweight) {
+ if (!b.date.isAfter(day) && (best == null || b.date.isAfter(best.date))) best = b;
+ }
+ final kg = best?.kg ?? latestBodyweight?.kg ?? profile.weightKg;
+ return kg > 0 ? kg : 75;
+ }
+
+ ({int active, int total, int sec, bool own})? cardioKcal(LoggedSession s, LoggedExercise e) {
+ if (!walksOrRuns(e)) return null;
+ final grade = (e.incline ?? 0) / 100;
+ final kg = _weightOn(s.day);
+ var active = 0.0, total = 0.0;
+ var sec = 0;
+ for (final st in e.sets) {
+ final km = st.km ?? 0, t = st.sec ?? 0;
+ if (km <= 0 || t <= 0) continue;
+ final min = t / 60;
+ final speed = km * 1000 / min;
+ final vo2 = speed < _walkRunMpm
+ ? 0.1 * speed + 1.8 * speed * grade + 3.5
+ : 0.2 * speed + 0.9 * speed * grade + 3.5;
+ total += vo2 * kg * min / 200;
+ active += (vo2 - 3.5) * kg * min / 200;
+ sec += t;
+ }
+ final own = e.kcal;
+ if (own != null) return (active: own, total: own + (3.5 * kg * sec / 60 / 200).round(), sec: sec, own: true);
+ if (sec == 0) return null;
+ return (active: active.round(), total: total.round(), sec: sec, own: false);
+ }
+
+ double? lastIncline(String id) {
+ for (final s in sessions.reversed) {
+ for (final e in s.exercises) {
+ if (e.id == id && e.incline != null) return e.incline;
+ }
+ }
+ return null;
+ }
+
+ void setLoggedIncline(LoggedExercise e, double pct) {
+ final v = (pct.clamp(0, 40) * 2).round() / 2;
+ e.incline = v > 0 ? v : null;
+ persistNow();
+ notifyListeners();
+ }
+
+ void setLoggedKcal(LoggedExercise e, int? kcal) {
+ e.kcal = kcal?.clamp(0, 9999);
+ persistNow();
+ notifyListeners();
+ }
+
void setLoggedWeightShown(LoggedExercise e, int i, double shown) =>
setLoggedWeight(e, i, fromDisplayWeight(shown));
@@ -941,6 +1003,34 @@ mixin StatsState on FitCore, ToolsState, LibraryState, SettingsState, TimelineSt
String? strengthExerciseId;
+ static const _ratioSteps = {
+ 'EIeI8Vf': ([0.8, 1.15, 1.5, 2.0], [0.5, 0.7, 1.0, 1.3]),
+ 'qXTaZnJ': ([1.0, 1.4, 1.9, 2.5], [0.75, 1.1, 1.5, 1.9]),
+ 'ila4NZS': ([1.25, 1.75, 2.25, 3.0], [1.0, 1.35, 1.75, 2.3]),
+ 'Kyd9Rz5': ([0.5, 0.7, 0.95, 1.25], [0.35, 0.45, 0.65, 0.85]),
+ 'kTbSH9h': ([0.5, 0.7, 0.95, 1.25], [0.35, 0.45, 0.65, 0.85]),
+ 'eZyBC3j': ([0.6, 0.85, 1.15, 1.5], [0.4, 0.6, 0.8, 1.05]),
+ };
+
+ ({double ratio, int level, double toNext})? relativeStrength(String id) {
+ final steps = _ratioSteps[id];
+ final body = latestBodyweight?.kg ?? profile.weightKg;
+ if (steps == null || body <= 0) return null;
+ final since = DateTime.now().subtract(const Duration(days: 90));
+ var best = 0.0;
+ for (final h in exerciseHistory(id)) {
+ if (h.date.isBefore(since)) break;
+ best = math.max(best, h.ex.bestOneRm);
+ }
+ if (best <= 0) return null;
+ final ratio = best / body;
+ final cuts = profile.sex == 'female' ? steps.$2 : steps.$1;
+ final level = cuts.where((c) => ratio >= c).length;
+ final lo = level == 0 ? 0.0 : cuts[level - 1];
+ final toNext = level >= cuts.length ? 1.0 : ((ratio - lo) / (cuts[level] - lo)).clamp(0.0, 1.0);
+ return (ratio: ratio, level: level, toNext: toNext);
+ }
+
List<({String id, String name, int sessions})> get trackedExercises {
final count = <String, int>{};
final names = <String, String>{};