Skip to content

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

Match imported exercises by their translated name too

InlitXddcb4cc082af
diff --git a/lib/catalog/exercise_aliases.dart b/lib/catalog/exercise_aliases.dart
index c3078f4..98933aa 100644
--- a/lib/catalog/exercise_aliases.dart
+++ b/lib/catalog/exercise_aliases.dart
@@ -122,12 +122,13 @@ const Map<String, List<String>> kExerciseAliases = {
'Power Clean': ['Power Clean (Barbell)'],
'Pull-up': ['Pull Up'],
'Push-up': ['Push Up (Bodyweight)', 'Press Up'],
+ 'Mountain Climber': ['Mountain Climbers'],
'Reverse Lunge': ['Reverse Lunge (Bodyweight)'],
'Rope Tricep Pushdown': ['Triceps Rope Pushdown (Cable)'],
'Rowing Machine': ['Rowing (Machine)', 'Rowing'],
'Russian Twist': ['Russian Twist (Bodyweight)'],
'Seated Leg Curl': ['Leg Curl (Machine)', 'Seated Leg Curl (Machine)'],
- 'Single Dumbbell Skullcrusher': ['Skullcrusher (Dumbbell)'],
+ 'Single Dumbbell Skullcrusher': ['Skullcrusher (Dumbbell)', 'Skull Crusher'],
'Single-Arm Cable Row': ['Seated Row Single Arm (Cable)'],
'Ski Erg': ['Ski Machine'],
'Smith Bench Press': ['Bench Press (Smith Machine)'],
diff --git a/lib/services/exercise_match.dart b/lib/services/exercise_match.dart
index 220fae4..07a9a1a 100644
--- a/lib/services/exercise_match.dart
+++ b/lib/services/exercise_match.dart
@@ -14,6 +14,7 @@ const _syn = {
'pushup': 'push up', 'pushups': 'push up', 'pullup': 'pull up', 'pullups': 'pull up',
'chinup': 'chin up', 'chinups': 'chin up', 'situp': 'sit up', 'situps': 'sit up',
'curls': 'curl', 'rows': 'row', 'presses': 'press',
+ 'ups': 'up', 'downs': 'down', 'climbers': 'climber', 'crushers': 'crusher',
'squats': 'squat', 'raises': 'raise', 'extensions': 'extension',
'flyes': 'fly', 'flies': 'fly', 'flys': 'fly',
'deadlifts': 'deadlift', 'lunges': 'lunge', 'dips': 'dip', 'pulldowns': 'pulldown',
@@ -48,13 +49,15 @@ List<String> nameTokens(String raw) {
String searchKey(String raw) => nameTokens(raw).join(' ');
+String sortedKey(String raw) => (nameTokens(raw)..sort()).join(' ');
+
final Map<String, String> _keyCache = {};
String _keyOf(String name) => _keyCache.putIfAbsent(name, () => searchKey(name));
final Map<String, String> _aliasIndex = {
for (final entry in kExerciseAliases.entries)
- for (final alias in entry.value) searchKey(alias): entry.key,
+ for (final alias in entry.value) sortedKey(alias): entry.key,
};
typedef ExerciseFilter = bool Function(Exercise);
@@ -117,7 +120,7 @@ Exercise? matchExercise(String name, Iterable<Exercise> pool) {
final key = searchKey(name);
if (key.isEmpty) return null;
- final alias = _aliasIndex[key];
+ final alias = _aliasIndex[sortedKey(name)];
if (alias != null) {
final wanted = searchKey(alias);
for (final e in pool) {
@@ -125,6 +128,11 @@ Exercise? matchExercise(String name, Iterable<Exercise> pool) {
}
}
+ for (final e in pool) {
+ final label = exerciseName(e);
+ if (label != e.name && _keyOf(label) == key) return e;
+ }
+
final q = key.split(' ').toSet();
final qMeaning = q.difference(_equipment);
if (qMeaning.isEmpty) return null;
diff --git a/test/exercise_alias_test.dart b/test/exercise_alias_test.dart
index 634a61f..409f611 100644
--- a/test/exercise_alias_test.dart
+++ b/test/exercise_alias_test.dart
@@ -73,6 +73,27 @@ void main() {
expect(_search('pec deck').single.name, 'Pec Deck');
});
+ test('the names an AI writes land on a real exercise', () {
+ const written = [
+ 'Bench Press', 'Squat', 'Deadlift', 'Overhead Press', 'Barbell Row',
+ 'Lat Pulldown', 'Bicep Curl', 'Tricep Pushdown', 'Leg Press',
+ 'Romanian Deadlift', 'Plank', 'Face Pull', 'Pull-ups', 'Push-ups',
+ 'Dumbbell Shoulder Press', 'Incline Bench Press', 'Leg Curl',
+ 'Calf Raises', 'Lateral Raises', 'Hip Thrust', 'Cable Fly',
+ 'Seated Row', 'Hammer Curls', 'Skull Crushers', 'Bulgarian Split Squat',
+ 'Goblet Squat', 'Russian Twist', 'Mountain Climbers',
+ ];
+ final missed = [for (final n in written) if (matchExercise(n, kExercises) == null) n];
+ expect(missed, isEmpty, reason: 'sin emparejar: ${missed.join(", ")}');
+ });
+
+ test('the order of the words does not matter for an alias', () {
+ expect(matchExercise('Dumbbell Shoulder Press', kExercises)?.name,
+ 'Dumbbell Standing Overhead Press');
+ expect(matchExercise('Shoulder Press (Dumbbell)', kExercises)?.name,
+ 'Dumbbell Standing Overhead Press');
+ });
+
test('an empty search keeps the whole catalog', () {
expect(_search(' ').length, kExercises.length);
});