feat: last-session recall when starting an exercise
When you start an exercise, the Mini App now fetches the most
recent time you logged it and shows a hint line in the sets card
("Last time: 8×60, 6×60, 5×60 · 3 days ago"), plus pre-fills the
weight input with the last set's weight.
- db.get_last_exercise(user_id, name): most recent non-deleted
entry, case-insensitive name match, sets_detail parsed.
- GET /api/exercises/last?name=<name>.
- webapp: loadLastSession() on startExercise + draft restore;
hint cleared on editExercise (the set rows are the reference
there). Pre-fill only when the weight field is empty and no
sets logged yet, so it never clobbers user input.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5e3636201f
commit
9f146d60fa
6 changed files with 168 additions and 1 deletions
|
|
@ -253,6 +253,48 @@ class TestAllExerciseNames:
|
|||
assert db.get_all_exercise_names() == ["Apple", "Mango", "Zebra"]
|
||||
|
||||
|
||||
# ── get_last_exercise ────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestGetLastExercise:
|
||||
def test_none_when_no_history(self, tmp_db):
|
||||
assert db.get_last_exercise(1, "Bench") is None
|
||||
|
||||
def test_returns_most_recent(self, tmp_db):
|
||||
t = lambda d: datetime(2024, 1, d, tzinfo=timezone.utc)
|
||||
db.save_workout(1, t(1), [[_make_exercise(name="Squat", weight=80.0)]])
|
||||
db.save_workout(1, t(5), [[_make_exercise(name="Squat", weight=90.0)]])
|
||||
last = db.get_last_exercise(1, "Squat")
|
||||
assert last is not None
|
||||
assert last["weight_kg"] == 90.0
|
||||
assert last["timestamp"].startswith("2024-01-05")
|
||||
|
||||
def test_case_insensitive(self, tmp_db):
|
||||
_save_simple(name="Bench Press")
|
||||
assert db.get_last_exercise(1, "bench press") is not None
|
||||
assert db.get_last_exercise(1, "BENCH PRESS") is not None
|
||||
|
||||
def test_sets_detail_parsed(self, tmp_db):
|
||||
detail = [{"reps": 8, "weight_kg": 25.0}, {"reps": 5, "weight_kg": 35.0}]
|
||||
ex = {
|
||||
"name": "Press", "machine_id": None,
|
||||
"sets": 2, "reps": 8, "weight_kg": 25.0,
|
||||
"sets_detail": detail, "raw_line": "Press: 8x25, 5x35",
|
||||
}
|
||||
db.save_workout(1, datetime.now(timezone.utc), [[ex]])
|
||||
last = db.get_last_exercise(1, "Press")
|
||||
assert last["sets_detail"] == detail
|
||||
|
||||
def test_scoped_to_user(self, tmp_db):
|
||||
_save_simple(user_id=1, name="Deadlift")
|
||||
assert db.get_last_exercise(2, "Deadlift") is None
|
||||
|
||||
def test_ignores_deleted(self, tmp_db):
|
||||
wid = _save_simple(name="Rows")
|
||||
db.delete_workout(1, wid)
|
||||
assert db.get_last_exercise(1, "Rows") is None
|
||||
|
||||
|
||||
# ── events / log_event ───────────────────────────────────────────
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue