Skip to content

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

Mark a set as warm-up, working, drop or to failure, and log reps with no weight

InlitX08f7de5301d1
diff --git a/lib/models/live_session.dart b/lib/models/live_session.dart
index ac0cb5b..b89ff26 100644
--- a/lib/models/live_session.dart
+++ b/lib/models/live_session.dart
@@ -1,14 +1,25 @@
+import 'workout.dart';
+
class SessionSet {
- SessionSet(this.reps, this.weight, this.done);
+ SessionSet(this.reps, this.weight, this.done, {this.kind = SetKind.normal});
int reps;
double weight;
bool done;
+ SetKind kind;
+
+ bool get counts => kind != SetKind.warmup;
- Map<String, dynamic> toJson() => {'r': reps, 'w': weight, 'd': done};
+ Map<String, dynamic> toJson() => {
+ 'r': reps,
+ 'w': weight,
+ 'd': done,
+ if (kind != SetKind.normal) 'k': kind.index,
+ };
factory SessionSet.fromJson(Map<String, dynamic> j) => SessionSet(
(j['r'] as num).toInt(),
(j['w'] as num).toDouble(),
j['d'] as bool? ?? false,
+ kind: setKindFrom(j['k']),
);
}
@@ -39,6 +50,7 @@ class WorkoutSession {
List<SessionExercise> exercises = [];
int currentIndex = 0;
bool complete = false;
+ DateTime? loggedAt;
int? restRemaining;
int? summaryVolume;
int? summarySets;
@@ -48,6 +60,7 @@ class WorkoutSession {
'ex': exercises.map((e) => e.toJson()).toList(),
'i': currentIndex,
'c': complete,
+ 'at': loggedAt?.toIso8601String(),
'sv': summaryVolume,
'ss': summarySets,
'sd': summaryDuration,
@@ -58,6 +71,7 @@ class WorkoutSession {
(j['ex'] as List).map((e) => SessionExercise.fromJson((e as Map).cast<String, dynamic>())).toList()
..currentIndex = (j['i'] as num?)?.toInt() ?? 0
..complete = j['c'] as bool? ?? false
+ ..loggedAt = DateTime.tryParse((j['at'] as String?) ?? '')
..summaryVolume = (j['sv'] as num?)?.toInt()
..summarySets = (j['ss'] as num?)?.toInt()
..summaryDuration = (j['sd'] as num?)?.toInt();
diff --git a/lib/models/workout.dart b/lib/models/workout.dart
index 7b3fc9e..d577b6b 100644
--- a/lib/models/workout.dart
+++ b/lib/models/workout.dart
@@ -1,14 +1,31 @@
+enum SetKind { normal, warmup, drop, failure }
+
+SetKind setKindFrom(Object? raw) {
+ final i = (raw as num?)?.toInt() ?? 0;
+ return SetKind.values[i.clamp(0, SetKind.values.length - 1)];
+}
+
class LoggedSet {
- LoggedSet(this.reps, this.weight);
+ LoggedSet(this.reps, this.weight, {this.kind = SetKind.normal});
final int reps;
final double weight;
+ final SetKind kind;
+
+ bool get counts => kind != SetKind.warmup;
double get volume => reps * weight;
double get oneRm => weight * (1 + reps / 30);
- Map<String, dynamic> toJson() => {'r': reps, 'w': weight};
- factory LoggedSet.fromJson(Map<String, dynamic> j) =>
- LoggedSet((j['r'] as num).toInt(), (j['w'] as num).toDouble());
+ Map<String, dynamic> toJson() => {
+ 'r': reps,
+ 'w': weight,
+ if (kind != SetKind.normal) 'k': kind.index,
+ };
+ factory LoggedSet.fromJson(Map<String, dynamic> j) => LoggedSet(
+ (j['r'] as num).toInt(),
+ (j['w'] as num).toDouble(),
+ kind: setKindFrom(j['k']),
+ );
}
class LoggedExercise {
@@ -18,9 +35,18 @@ class LoggedExercise {
final String primary;
final List<LoggedSet> sets;
- double get volume => sets.fold(0.0, (s, x) => s + x.volume);
- double get topWeight => sets.isEmpty ? 0 : sets.map((s) => s.weight).reduce((a, b) => a > b ? a : b);
- double get bestOneRm => sets.isEmpty ? 0 : sets.map((s) => s.oneRm).reduce((a, b) => a > b ? a : b);
+ List<LoggedSet> get workingSets => sets.where((s) => s.counts).toList();
+
+ double get volume => workingSets.fold(0.0, (s, x) => s + x.volume);
+ double get topWeight {
+ final w = workingSets;
+ return w.isEmpty ? 0 : w.map((s) => s.weight).reduce((a, b) => a > b ? a : b);
+ }
+
+ double get bestOneRm {
+ final w = workingSets;
+ return w.isEmpty ? 0 : w.map((s) => s.oneRm).reduce((a, b) => a > b ? a : b);
+ }
Map<String, dynamic> toJson() => {
'id': id,
@@ -43,7 +69,7 @@ class LoggedSession {
final List<LoggedExercise> exercises;
double get volume => exercises.fold(0.0, (s, e) => s + e.volume);
- int get setCount => exercises.fold(0, (s, e) => s + e.sets.length);
+ int get setCount => exercises.fold(0, (s, e) => s + e.workingSets.length);
Map<String, dynamic> toJson() => {
'd': date.toIso8601String(),
@@ -67,16 +93,6 @@ class BodyweightEntry {
BodyweightEntry(DateTime.parse(j['d'] as String), (j['kg'] as num).toDouble());
}
-class ExerciseNote {
- ExerciseNote(this.date, this.text);
- final DateTime date;
- final String text;
-
- Map<String, dynamic> toJson() => {'d': date.toIso8601String(), 't': text};
- factory ExerciseNote.fromJson(Map<String, dynamic> j) =>
- ExerciseNote(DateTime.parse(j['d'] as String), j['t'] as String);
-}
-
class Routine {
Routine(this.id, this.name, this.exerciseIds);
final String id;
diff --git a/test/reps_only_test.dart b/test/reps_only_test.dart
new file mode 100644
index 0000000..9fc2380
--- /dev/null
+++ b/test/reps_only_test.dart
@@ -0,0 +1,101 @@
+import 'package:flutter_test/flutter_test.dart';
+import 'package:gymmane/catalog/exercise_catalog.dart';
+import 'package:gymmane/models/workout.dart';
+import 'package:gymmane/services/local_store.dart';
+import 'package:gymmane/state/fit_state.dart';
+import 'package:shared_preferences/shared_preferences.dart';
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
+ final pullUp = kExercises.firstWhere((e) => e.equipment == 'Bodyweight');
+ final bench = kExercises.firstWhere((e) => e.equipment == 'Barbell');
+
+ setUp(() async {
+ SharedPreferences.setMockInitialValues({});
+ await Store.instance.init();
+ fit.saveAndExit();
+ fit.sessions.clear();
+ fit.repsOnly.clear();
+ fit.repsOnlyOff.clear();
+ fit.exEquipmentFilter = null;
+ fit.clearExFilters();
+ });
+
+ void log(String id, double kg) => fit.sessions.add(LoggedSession(DateTime.now(), 600, [
+ LoggedExercise(id, 'x', 'chest', [LoggedSet(8, kg)])
+ ]));
+
+ test('a bodyweight exercise starts without weight, a barbell one does not', () {
+ expect(fit.isRepsOnly(pullUp.id), true);
+ expect(fit.isRepsOnly(bench.id), false);
+ });
+
+ test('history with lastre wins over the guess', () {
+ log(pullUp.id, 20);
+ expect(fit.isRepsOnly(pullUp.id), false, reason: 'ya lo ha cargado con peso');
+ });
+
+ test('the toggle sticks in both directions and survives a restart', () async {
+ fit.toggleRepsOnly(bench.id);
+ expect(fit.isRepsOnly(bench.id), true);
+
+ fit.toggleRepsOnly(pullUp.id);
+ expect(fit.isRepsOnly(pullUp.id), false, reason: 'desmarcarlo manda sobre el material');
+
+ fit.persistNow();
+ fit.repsOnly.clear();
+ fit.repsOnlyOff.clear();
+ fit.loadFromStore();
+ expect(fit.isRepsOnly(bench.id), true);
+ expect(fit.isRepsOnly(pullUp.id), false);
+ });
+
+ test('a fresh session opens reps-only exercises at zero weight', () {
+ fit.sessionPicks
+ ..clear()
+ ..addAll([pullUp.id, bench.id]);
+ fit.startSession();
+
+ final sets = {for (final e in fit.session!.exercises) e.id: e.sets};
+ expect(sets[pullUp.id]!.every((s) => s.weight == 0), true);
+ expect(sets[bench.id]!.every((s) => s.weight > 0), true);
+ });
+
+ test('adding one mid-session respects the flag too', () {
+ fit.sessionPicks
+ ..clear()
+ ..add(bench.id);
+ fit.startSession();
+ fit.addExerciseToSession(pullUp.id);
+
+ final added = fit.session!.exercises.last;
+ expect(added.id, pullUp.id);
+ expect(added.sets.every((s) => s.weight == 0), true);
+ expect(fit.inSession(pullUp.id), true);
+ });
+
+ test('the same exercise is never added twice', () {
+ fit.sessionPicks
+ ..clear()
+ ..add(bench.id);
+ fit.startSession();
+ fit.addExerciseToSession(bench.id);
+ expect(fit.session!.exercises.length, 1);
+ });
+
+ test('the equipment filter narrows the library and clears with the rest', () {
+ fit.setEquipmentFilter('Bodyweight');
+ final list = fit.exercisesFiltered;
+ expect(list, isNotEmpty);
+ expect(list.every((e) => e.equipment == 'Bodyweight'), true);
+ expect(list.length, lessThan(fit.allExercises.length));
+
+ fit.setEquipmentFilter('Bodyweight');
+ expect(fit.exEquipmentFilter, isNull, reason: 'el mismo chip lo quita');
+
+ fit.setEquipmentFilter('Barbell');
+ fit.clearExFilters();
+ expect(fit.exEquipmentFilter, isNull);
+ });
+}
diff --git a/test/set_kinds_test.dart b/test/set_kinds_test.dart
new file mode 100644
index 0000000..3c90b90
--- /dev/null
+++ b/test/set_kinds_test.dart
@@ -0,0 +1,206 @@
+import 'package:flutter_test/flutter_test.dart';
+import 'package:gymmane/models/workout.dart';
+import 'package:gymmane/services/local_store.dart';
+import 'package:gymmane/state/fit_state.dart';
+import 'package:shared_preferences/shared_preferences.dart';
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
+ setUp(() async {
+ SharedPreferences.setMockInitialValues({});
+ await Store.instance.init();
+ fit.resetAllData();
+ fit.setUnits('kg');
+ });
+
+ void startChestSession() {
+ fit.startWorkout();
+ fit.toggleMuscle('chest');
+ fit.trainContinue();
+ for (final id in fit.sessionPicks.toList().skip(1)) {
+ fit.togglePick(id);
+ }
+ fit.startSession();
+ }
+
+ test('a warm-up set stays out of the volume and the set count', () {
+ startChestSession();
+ fit.addSet(0);
+
+ fit.setSetKind(0, 0, SetKind.warmup);
+ fit.setSessionReps(0, 0, 10);
+ fit.setSessionWeight(0, 0, 20);
+ fit.toggleSet(0, 0);
+
+ fit.setSessionReps(0, 1, 5);
+ fit.setSessionWeight(0, 1, 100);
+ fit.toggleSet(0, 1);
+
+ fit.finishSession();
+
+ expect(fit.session!.summarySets, 1, reason: 'solo cuenta la efectiva');
+ expect(fit.session!.summaryVolume, 500);
+
+ final logged = fit.sessions.single.exercises.single;
+ expect(logged.sets, hasLength(2), reason: 'el calentamiento se guarda igual');
+ expect(logged.workingSets, hasLength(1));
+ expect(logged.volume, closeTo(500, 0.01));
+ expect(logged.topWeight, 100, reason: 'el calentamiento no marca récord');
+ expect(fit.sessions.single.setCount, 1);
+ });
+
+ test('an exercise that is only warm-up does not blow up the records', () {
+ startChestSession();
+ fit.setSetKind(0, 0, SetKind.warmup);
+ fit.setSessionReps(0, 0, 10);
+ fit.setSessionWeight(0, 0, 20);
+ fit.toggleSet(0, 0);
+ fit.finishSession();
+
+ final logged = fit.sessions.single.exercises.single;
+ expect(logged.topWeight, 0);
+ expect(logged.bestOneRm, 0);
+ expect(logged.volume, 0);
+ });
+
+ test('drop and failure sets still count as work', () {
+ startChestSession();
+ fit.setSetKind(0, 0, SetKind.failure);
+ fit.setSessionReps(0, 0, 8);
+ fit.setSessionWeight(0, 0, 60);
+ fit.toggleSet(0, 0);
+ fit.finishSession();
+
+ expect(fit.session!.summarySets, 1);
+ expect(fit.sessions.single.exercises.single.volume, closeTo(480, 0.01));
+ });
+
+ test('the kind survives a save and a reload of the live session', () {
+ startChestSession();
+ fit.setSetKind(0, 0, SetKind.drop);
+ fit.persistNow();
+
+ fit.session = null;
+ fit.loadFromStore();
+ expect(fit.session!.exercises.first.sets.first.kind, SetKind.drop);
+ });
+
+ test('a new set copies the kind of the one above it', () {
+ startChestSession();
+ final last = fit.session!.exercises.first.sets.length - 1;
+ fit.setSetKind(0, last, SetKind.warmup);
+ fit.addSet(0);
+ expect(fit.session!.exercises.first.sets.last.kind, SetKind.warmup);
+ });
+
+ test('an old backup with no kind reads as a working set', () {
+ final set = LoggedSet.fromJson({'r': 8, 'w': 60.0});
+ expect(set.kind, SetKind.normal);
+ expect(set.counts, true);
+ });
+
+ group('automatic warm-up', () {
+ test('it lays three ramp sets before the working ones', () {
+ startChestSession();
+ fit.setSessionWeight(0, 0, 100);
+ final before = fit.session!.exercises.first.sets.length;
+
+ fit.addWarmupSets(0);
+ final sets = fit.session!.exercises.first.sets;
+
+ expect(sets, hasLength(before + 3));
+ expect(sets.take(3).every((s) => s.kind == SetKind.warmup), true);
+ expect(sets.take(3).map((s) => s.weight), [40, 60, 80]);
+ expect(sets.take(3).map((s) => s.reps), [10, 5, 3]);
+ expect(sets[3].kind, SetKind.normal);
+ });
+
+ test('it will not stack a second ramp on top', () {
+ startChestSession();
+ fit.setSessionWeight(0, 0, 100);
+ fit.addWarmupSets(0);
+ final after = fit.session!.exercises.first.sets.length;
+ fit.addWarmupSets(0);
+ expect(fit.session!.exercises.first.sets, hasLength(after));
+ });
+
+ test('with no weight on the bar there is nothing to ramp up to', () {
+ startChestSession();
+ for (var i = 0; i < fit.session!.exercises.first.sets.length; i++) {
+ fit.setSessionWeight(0, i, 0);
+ }
+ fit.addWarmupSets(0);
+ expect(fit.hasWarmup(0), false);
+ });
+
+ test('the ramp rounds to the plates you actually have', () {
+ startChestSession();
+ fit.setUnits('kg');
+ fit.setSessionWeight(0, 0, 62.5);
+ fit.addWarmupSets(0);
+ expect(fit.session!.exercises.first.sets.first.weight, 25);
+ });
+ });
+
+ group('plates per side', () {
+ test('a barbell weight is broken down, in kilos and in pounds', () {
+ fit.setUnits('kg');
+ expect(fit.plateHint('Barbell', 100), '25 · 15');
+ expect(fit.plateHint('Barbell', 20), isNull, reason: 'la barra sola no lleva discos');
+ expect(fit.plateHint('Dumbbell', 100), isNull);
+
+ fit.setUnits('lb');
+ expect(fit.plateHint('Barbell', 100), isNotNull);
+ fit.setUnits('kg');
+ });
+
+ test('an odd weight is broken down as far as the plates allow', () {
+ fit.setUnits('kg');
+ expect(fit.plateHint('Barbell', 62.5), '20 · 1.25');
+ });
+ });
+
+ group('rest per exercise', () {
+ test('falls back to the global rest until you change it', () {
+ fit.setRestSeconds(90);
+ expect(fit.restFor('anything'), 90);
+ expect(fit.hasCustomRest('anything'), false);
+
+ fit.setExerciseRest('anything', 180);
+ expect(fit.restFor('anything'), 180);
+ expect(fit.hasCustomRest('anything'), true);
+ expect(fit.restFor('another'), 90);
+ });
+
+ test('it is clamped to something sane and can be handed back', () {
+ fit.setExerciseRest('x', 5);
+ expect(fit.restFor('x'), 15);
+ fit.setExerciseRest('x', 9000);
+ expect(fit.restFor('x'), 600);
+
+ fit.setExerciseRest('x', null);
+ expect(fit.hasCustomRest('x'), false);
+ });
+
+ test('it survives a save and a reload', () {
+ fit.setExerciseRest('bench', 150);
+ fit.persistNow();
+
+ fit.exerciseRest.clear();
+ fit.loadFromStore();
+ expect(fit.restFor('bench'), 150);
+ });
+
+ test('the session rest timer uses the exercise value', () {
+ startChestSession();
+ final id = fit.session!.exercises.first.id;
+ fit.setRestSeconds(60);
+ fit.setExerciseRest(id, 210);
+
+ fit.startRest();
+ expect(fit.session!.restRemaining, 210);
+ fit.skipRest();
+ });
+ });
+}