repwise 3.2.0__tar.gz → 3.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. {repwise-3.2.0/src/repwise.egg-info → repwise-3.3.0}/PKG-INFO +3 -3
  2. {repwise-3.2.0 → repwise-3.3.0}/README.md +2 -2
  3. {repwise-3.2.0 → repwise-3.3.0}/pyproject.toml +1 -1
  4. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/__init__.py +1 -1
  5. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/app/update.py +10 -2
  6. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/domain/progression.py +122 -25
  7. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/planner.py +27 -5
  8. {repwise-3.2.0 → repwise-3.3.0/src/repwise.egg-info}/PKG-INFO +3 -3
  9. {repwise-3.2.0 → repwise-3.3.0}/tests/test_planner.py +9 -1
  10. {repwise-3.2.0 → repwise-3.3.0}/tests/test_progression.py +160 -22
  11. {repwise-3.2.0 → repwise-3.3.0}/tests/test_update.py +18 -0
  12. {repwise-3.2.0 → repwise-3.3.0}/LICENSE +0 -0
  13. {repwise-3.2.0 → repwise-3.3.0}/setup.cfg +0 -0
  14. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/__main__.py +0 -0
  15. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/app/__init__.py +0 -0
  16. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/app/checking.py +0 -0
  17. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/app/fetch.py +0 -0
  18. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/app/importing.py +0 -0
  19. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/app/listing.py +0 -0
  20. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/app/logout.py +0 -0
  21. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/app/report.py +0 -0
  22. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/checker.py +0 -0
  23. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/cli/__init__.py +0 -0
  24. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/cli/completion.py +0 -0
  25. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/cli/parser.py +0 -0
  26. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/config.py +0 -0
  27. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/domain/__init__.py +0 -0
  28. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/domain/effort.py +0 -0
  29. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/domain/matching.py +0 -0
  30. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/domain/models.py +0 -0
  31. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/dumps.py +0 -0
  32. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/errors.py +0 -0
  33. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/garmin/__init__.py +0 -0
  34. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/garmin/catalog.py +0 -0
  35. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/garmin/client.py +0 -0
  36. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/garmin/payloads.py +0 -0
  37. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/importer.py +0 -0
  38. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/log.py +0 -0
  39. {repwise-3.2.0 → repwise-3.3.0}/src/repwise/yamlio.py +0 -0
  40. {repwise-3.2.0 → repwise-3.3.0}/src/repwise.egg-info/SOURCES.txt +0 -0
  41. {repwise-3.2.0 → repwise-3.3.0}/src/repwise.egg-info/dependency_links.txt +0 -0
  42. {repwise-3.2.0 → repwise-3.3.0}/src/repwise.egg-info/entry_points.txt +0 -0
  43. {repwise-3.2.0 → repwise-3.3.0}/src/repwise.egg-info/requires.txt +0 -0
  44. {repwise-3.2.0 → repwise-3.3.0}/src/repwise.egg-info/top_level.txt +0 -0
  45. {repwise-3.2.0 → repwise-3.3.0}/tests/test_catalog.py +0 -0
  46. {repwise-3.2.0 → repwise-3.3.0}/tests/test_checker.py +0 -0
  47. {repwise-3.2.0 → repwise-3.3.0}/tests/test_checking.py +0 -0
  48. {repwise-3.2.0 → repwise-3.3.0}/tests/test_cli.py +0 -0
  49. {repwise-3.2.0 → repwise-3.3.0}/tests/test_client.py +0 -0
  50. {repwise-3.2.0 → repwise-3.3.0}/tests/test_completion.py +0 -0
  51. {repwise-3.2.0 → repwise-3.3.0}/tests/test_config.py +0 -0
  52. {repwise-3.2.0 → repwise-3.3.0}/tests/test_dumps.py +0 -0
  53. {repwise-3.2.0 → repwise-3.3.0}/tests/test_effort.py +0 -0
  54. {repwise-3.2.0 → repwise-3.3.0}/tests/test_fetch.py +0 -0
  55. {repwise-3.2.0 → repwise-3.3.0}/tests/test_importer.py +0 -0
  56. {repwise-3.2.0 → repwise-3.3.0}/tests/test_importing.py +0 -0
  57. {repwise-3.2.0 → repwise-3.3.0}/tests/test_listing.py +0 -0
  58. {repwise-3.2.0 → repwise-3.3.0}/tests/test_log.py +0 -0
  59. {repwise-3.2.0 → repwise-3.3.0}/tests/test_logout.py +0 -0
  60. {repwise-3.2.0 → repwise-3.3.0}/tests/test_main.py +0 -0
  61. {repwise-3.2.0 → repwise-3.3.0}/tests/test_matching.py +0 -0
  62. {repwise-3.2.0 → repwise-3.3.0}/tests/test_models.py +0 -0
  63. {repwise-3.2.0 → repwise-3.3.0}/tests/test_payloads.py +0 -0
  64. {repwise-3.2.0 → repwise-3.3.0}/tests/test_report.py +0 -0
  65. {repwise-3.2.0 → repwise-3.3.0}/tests/test_yamlio.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: repwise
3
- Version: 3.2.0
3
+ Version: 3.3.0
4
4
  Summary: Advance Garmin strength workout targets using double progression
5
5
  Author-email: Adam Żmuda <adam@zmuda.pro>
6
6
  License-Expression: MIT
@@ -81,8 +81,8 @@ session, so training A and then B and running once brings both up to date:
81
81
 
82
82
  1. Start at the bottom of the rep range.
83
83
  2. Add a rep to every set each session.
84
- 3. Once every set reaches the top of the range, add weight and reset to the
85
- bottom.
84
+ 3. Once every set reaches the top of the range twice, add weight and reset to
85
+ the bottom.
86
86
  4. If you missed the target, repeat it unchanged.
87
87
  5. A load only counts once you can carry it for the bottom of the range.
88
88
 
@@ -54,8 +54,8 @@ session, so training A and then B and running once brings both up to date:
54
54
 
55
55
  1. Start at the bottom of the rep range.
56
56
  2. Add a rep to every set each session.
57
- 3. Once every set reaches the top of the range, add weight and reset to the
58
- bottom.
57
+ 3. Once every set reaches the top of the range twice, add weight and reset to
58
+ the bottom.
59
59
  4. If you missed the target, repeat it unchanged.
60
60
  5. A load only counts once you can carry it for the bottom of the range.
61
61
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "repwise"
7
- version = "3.2.0"
7
+ version = "3.3.0"
8
8
  description = "Advance Garmin strength workout targets using double progression"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -1,4 +1,4 @@
1
1
  """Advance Garmin strength workout targets using double progression."""
2
2
 
3
3
  __all__ = ["__version__"]
4
- __version__ = "3.2.0"
4
+ __version__ = "3.3.0"
@@ -15,6 +15,7 @@ from ..config import ConfigError, record_workout_id
15
15
  from ..domain.matching import normalise
16
16
  from ..domain.models import Config, ExerciseSpec, Workout
17
17
  from ..domain.progression import (
18
+ CONFIRMED_AFTER,
18
19
  PerformedSet,
19
20
  Session,
20
21
  Target,
@@ -187,7 +188,7 @@ def sessions_before(
187
188
  def wants_more(
188
189
  spec: ExerciseSpec, logged: list[PerformedSet], earlier: list[Session]
189
190
  ) -> bool:
190
- """Whether one more session back could still change this exercise's streak.
191
+ """Whether one more session back could still change this exercise's answer.
191
192
 
192
193
  The walk that counts a streak stops of its own accord at a session that
193
194
  hit, at a change of load, or at `sets - 1` misses. If instead it ran off
@@ -195,8 +196,15 @@ def wants_more(
195
196
  back is worth fetching; anything else is already settled. So one activity
196
197
  answers a smoothly progressing exercise, and only a genuine stall reads
197
198
  deeper.
199
+
200
+ The floor of `CONFIRMED_AFTER` is what rule 3's two-session confirmation
201
+ needs, and it only ever binds on a single-set exercise. Everything else
202
+ already reads at least one session back for the miss streak, which is the
203
+ same session the confirmation asks about; at one set `sets - 1` is none at
204
+ all, and without the floor a single-set exercise would arrive at the top of
205
+ its range with no history to confirm against and hold there forever.
198
206
  """
199
- limit = max(spec.sets - 1, 0)
207
+ limit = max(spec.sets - 1, CONFIRMED_AFTER)
200
208
  if not logged or len(earlier) >= limit:
201
209
  # Not trained in the session being judged, so there is nothing for a
202
210
  # streak to explain -- or already as deep as the rules can read.
@@ -11,8 +11,8 @@ The rules, as written in README.md:
11
11
  2. Each workout, add a rep to every set, e.g. 7-7-7, then 8-8-8 -- but after a
12
12
  stall, to only some of them, so that the way back up is gentler than the way
13
13
  that failed.
14
- 3. Once all sets reach the upper end, increase the weight and reset to the
15
- lower end.
14
+ 3. Once all sets reach the upper end, hold it there for a second session, then
15
+ increase the weight and reset to the lower end.
16
16
  4. If you didn't match the previous result, stay at the same weight and reps.
17
17
  5. A load is only adopted once it can be carried for the bottom of the range.
18
18
  Lift something other than what was prescribed and come up short of rep_low
@@ -131,6 +131,37 @@ def working_weight(performed: list[PerformedSet]) -> float:
131
131
  return max(counts, key=lambda weight: (counts[weight], weight))
132
132
 
133
133
 
134
+ def _counted_reps(performed: list[PerformedSet], weight: float) -> list[int]:
135
+ """The reps a session at `weight` is judged on, hardest sets included.
136
+
137
+ The sets at the working weight, plus any carried at a *heavier* load for at
138
+ least the reps those managed: harder than asked is not worse than asked,
139
+ and a session split across two loads is still a whole session. Without this
140
+ the set count is taken from one load alone, and three sets done as two at
141
+ 20 kg and one at 30 kg read as an abandoned session rather than a finished
142
+ one.
143
+
144
+ What a heavier set contributes is its own rep count, which is a lower bound
145
+ on what it would have managed at the lighter load, so this can only ever
146
+ add sets to the tally - never flatter the reps, since every set it adds is
147
+ at or above the floor and `min` is left where it was. A set that came up
148
+ *short* at the heavier load counts for nothing, which is what keeps a
149
+ failed top set from reading as a completed session.
150
+
151
+ Empty when nothing was done at `weight`, which only a caller inventing a
152
+ load can produce: `working_weight` always names one of the loads used.
153
+ """
154
+ at_weight = [entry.reps for entry in performed if entry.weight == weight]
155
+ if not at_weight:
156
+ return []
157
+ floor = min(at_weight)
158
+ return at_weight + [
159
+ entry.reps
160
+ for entry in performed
161
+ if entry.weight > weight and entry.reps >= floor
162
+ ]
163
+
164
+
134
165
  def hit(spec: ExerciseSpec, target: Target, reps: list[int]) -> bool:
135
166
  """Whether a session met what was asked of it.
136
167
 
@@ -187,6 +218,62 @@ def miss_streak(spec: ExerciseSpec, history: list[Session], weight: float) -> in
187
218
  return streak
188
219
 
189
220
 
221
+ #: How many sessions must already have cleared the top of the range for this
222
+ #: one to earn the load. One, so the weight moves on the *second* session at
223
+ #: `rep_high` rather than on the first.
224
+ #:
225
+ #: This is ACSM's own condition for adding load, which asks for the surplus on
226
+ #: "two consecutive training sessions" - see `top_streak` for the quote and
227
+ #: `docs/progression.md` for the reference. A single session at the top of the
228
+ #: range can be a good day rather than a new capacity: better sleep, a longer
229
+ #: rest, a kinder rep judgement. Rule 3 spending that day on a load increase is
230
+ #: what sets up the stall rule 4 then has to unwind, and asking for it twice is
231
+ #: the cheapest filter there is - one extra session, only ever at the top of
232
+ #: the range, and only ever immediately before a jump.
233
+ CONFIRMED_AFTER = 1
234
+
235
+
236
+ def top_streak(spec: ExerciseSpec, history: list[Session], weight: float) -> int:
237
+ """How many sessions in a row cleared the top of the range, before the latest.
238
+
239
+ ACSM's 2009 position stand asks for a "2-10% increase in load [...] when the
240
+ individual can perform the current workload for one to two repetitions over
241
+ the desired number on two consecutive training sessions". This counts the
242
+ consecutive sessions; `CONFIRMED_AFTER` says how many rule 3 wants.
243
+
244
+ `history` is the sessions before the one being judged, newest first, and
245
+ `weight` the load that one was worked at - the same arguments `miss_streak`
246
+ takes, because this is its mirror: not how long an exercise has been
247
+ failing its target, but how long it has been clearing the top of its range
248
+ at one load. The walk stops at:
249
+
250
+ - the first session that did not clear it, which is what ends a run;
251
+ - a change of load, because clearing the top at 20 kg says nothing about
252
+ whether 22.5 kg has been earned - the confirmation belongs to the load
253
+ being confirmed;
254
+ - `CONFIRMED_AFTER`, past which nothing could change the answer: the load
255
+ moves on that session and the next one restarts at `rep_low`, so a longer
256
+ run does not exist to be found.
257
+
258
+ A session too short to judge does not clear anything. That is rule 3's own
259
+ set count, applied to history for the same reason: a session that would
260
+ have consolidated rather than advanced cannot confirm a jump either.
261
+ """
262
+ streak = 0
263
+
264
+ for session in history:
265
+ if streak >= CONFIRMED_AFTER:
266
+ break
267
+ if not session.performed or working_weight(session.performed) != weight:
268
+ break
269
+ counted = _counted_reps(session.performed, weight)
270
+ if len(counted) < spec.sets or min(counted) < spec.rep_high:
271
+ break
272
+ streak += 1
273
+
274
+ return streak
275
+
276
+
190
277
  #: How many sessions must have missed *before* this one for it to count as a
191
278
  #: stall rather than a bad day. One, so the target eases on the second miss in
192
279
  #: a row - and, because easing has to bottom out in the range before the load
@@ -356,6 +443,7 @@ def _advance( # noqa: PLR0913 - each argument is one independent input
356
443
  streak: int,
357
444
  *,
358
445
  bodyweight: float = 0.0,
446
+ topped: int = 0,
359
447
  ) -> tuple[Target, str]:
360
448
  """Move a session that counted, by an amount the streak behind it decides.
361
449
 
@@ -414,6 +502,21 @@ def _advance( # noqa: PLR0913 - each argument is one independent input
414
502
  Target(spec.rep_high, weight),
415
503
  f"top of the range, {sits} the {shown:g} kg maximum",
416
504
  )
505
+ # ACSM's two-session confirmation: the top of the range has to be
506
+ # cleared twice at one load before the load moves.
507
+ #
508
+ # Placed *after* the two endings above rather than before them, because
509
+ # both of those leave the target exactly where this would. There is
510
+ # nothing to confirm when there is nothing to add, and an exercise that
511
+ # is bodyweight or out of rack would otherwise be told, every run, to
512
+ # hold once more for a jump that is never coming.
513
+ if topped < CONFIRMED_AFTER:
514
+ return (
515
+ Target(spec.rep_high, weight),
516
+ f"hit {floor} on every set{lifted}, top of the range, "
517
+ "hold it once more before the load goes up",
518
+ )
519
+
417
520
  # Three shapes of the same move, and the report is the only place they
418
521
  # differ: a plain step, a step shortened to land on the rack's own
419
522
  # ceiling, and a step that ran off the end of one rack onto the next.
@@ -474,12 +577,14 @@ def _advance( # noqa: PLR0913 - each argument is one independent input
474
577
  )
475
578
 
476
579
 
477
- def next_target(
580
+ def next_target( # noqa: PLR0913 - each argument is one independent input
478
581
  spec: ExerciseSpec,
479
582
  current: Target,
480
583
  performed: list[PerformedSet],
481
584
  streak: int = 0,
585
+ *,
482
586
  bodyweight: float = 0.0,
587
+ topped: int = 0,
483
588
  ) -> tuple[Target, str]:
484
589
  """Decide the next prescription for one exercise.
485
590
 
@@ -495,6 +600,13 @@ def next_target(
495
600
  most of any routine and harmless for the rest, because a step chosen a size
496
601
  small still progresses.
497
602
 
603
+ `topped` is how many sessions in a row already cleared the top of the range
604
+ at this load, from `top_streak`, and gates rule 3's load increase alone.
605
+ Like `streak` it defaults to none, which is the reading to give when there
606
+ is no history to consult - a first-ever session, or one too old to look
607
+ behind - and costs a single held session at the top of the range, which the
608
+ session after it then confirms.
609
+
498
610
  Returns the new target plus a short human-readable reason.
499
611
  """
500
612
  if not performed:
@@ -503,32 +615,15 @@ def next_target(
503
615
  # Judge everything at the load actually used, which may not be the load the
504
616
  # workout still has stored.
505
617
  weight = working_weight(performed)
506
- at_weight = [entry.reps for entry in performed if entry.weight == weight]
507
618
  rebased = weight != current.weight
619
+ counted = _counted_reps(performed, weight)
508
620
 
509
621
  # Progress from the weakest set, not from the stored target. The next
510
622
  # target has to be achievable on every set, so extra reps on the easy sets
511
623
  # earn nothing while the floor stays put -- but beating the target on all
512
- # of them does count.
513
- floor = min(at_weight)
514
-
515
- # A set carried at a *heavier* load, for at least the reps the working sets
516
- # managed, counts as one of them: harder than asked is not worse than
517
- # asked, and a session split across two loads is still a whole session.
518
- # Without this the set count is taken from one load alone, and three sets
519
- # done as two at 20 kg and one at 30 kg read as an abandoned session rather
520
- # than a finished one.
521
- #
522
- # What it contributes is its own rep count, which is a lower bound on what
523
- # it would have managed at the lighter load, so this can only ever add sets
524
- # to the tally - never flatter the reps. A set that came up short at the
525
- # heavier load counts for nothing, which is what keeps a failed top set
526
- # from reading as a completed session.
527
- counted = at_weight + [
528
- entry.reps
529
- for entry in performed
530
- if entry.weight > weight and entry.reps >= floor
531
- ]
624
+ # of them does count. The heavier sets `_counted_reps` folds in never sit
625
+ # below this, so taking it from the whole tally is the same figure.
626
+ floor = min(counted)
532
627
 
533
628
  # Rule 5: a load is only worth keeping once it can be carried for at least
534
629
  # the bottom of the range. Falling short of rep_low means the jump was too
@@ -560,4 +655,6 @@ def next_target(
560
655
  return _deload(spec, current, weight, counted, bodyweight=bodyweight)
561
656
  return current, _missed(floor)
562
657
 
563
- return _advance(spec, current, weight, floor, streak, bodyweight=bodyweight)
658
+ return _advance(
659
+ spec, current, weight, floor, streak, bodyweight=bodyweight, topped=topped
660
+ )
@@ -26,6 +26,7 @@ from .domain.progression import (
26
26
  miss_streak,
27
27
  missed,
28
28
  next_target,
29
+ top_streak,
29
30
  working_weight,
30
31
  )
31
32
  from .errors import ActivityNotFound
@@ -418,6 +419,23 @@ def _streak(
418
419
  return miss_streak(spec, past, working_weight(logged))
419
420
 
420
421
 
422
+ def _topped(
423
+ spec: ExerciseSpec, logged: list[PerformedSet], history: History | None
424
+ ) -> int:
425
+ """How many sessions in a row already cleared the top of this range.
426
+
427
+ Read the same way as `_streak`, and no history means the same thing here:
428
+ nothing has been confirmed yet, so a first top-out is held once and the
429
+ session after it earns the load.
430
+ """
431
+ if not history:
432
+ return 0
433
+ past = history.get(normalise(spec.garmin_name))
434
+ if not past:
435
+ return 0
436
+ return top_streak(spec, past, working_weight(logged))
437
+
438
+
421
439
  #: Why a target that was part-way up a ramp is evened out. Worth saying in the
422
440
  #: report because nothing else in the run accounts for it: no session earned
423
441
  #: it, and the figure in workouts.yaml did not move.
@@ -554,7 +572,9 @@ def _judge( # noqa: PLR0913 - each argument is one independent input
554
572
  logged = [entry.as_time() for entry in logged]
555
573
 
556
574
  streak = _streak(spec, logged, history)
557
- new, why = next_target(spec, current, logged, streak)
575
+ new, why = next_target(
576
+ spec, current, logged, streak, topped=_topped(spec, logged, history)
577
+ )
558
578
  # A session that fell short leaves the number on the watch for you to try
559
579
  # again, and the note says so - see `_refresh_note`. Anything else clears
560
580
  # the marker rather than leaving it None: a session that advanced, or one
@@ -1080,10 +1100,12 @@ def plan_workout( # noqa: PLR0913 - each argument is one independent input
1080
1100
  only for the exercises it actually contains: pass no `performed` at all for
1081
1101
  a workout with no session behind it, and only the first kind happens.
1082
1102
 
1083
- `history` is the sessions before this one, newest first, from which how
1084
- badly each exercise had been stalling is read. Without it every exercise is
1085
- treated as having hit last time, which is the smooth case and the behaviour
1086
- this tool had before granular progression existed.
1103
+ `history` is the sessions before this one, newest first, and answers two
1104
+ questions: how badly each exercise had been stalling, and whether one at the
1105
+ top of its range has already been there once. Without it every exercise is
1106
+ treated as having hit last time - the smooth case, and the behaviour this
1107
+ tool had before granular progression existed - and as having nothing behind
1108
+ it to confirm a load increase, so a first top-out is held rather than taken.
1087
1109
 
1088
1110
  `asked` is what this session itself was performed against. Without it the
1089
1111
  stored target is assumed to be that, which is only true until something
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: repwise
3
- Version: 3.2.0
3
+ Version: 3.3.0
4
4
  Summary: Advance Garmin strength workout targets using double progression
5
5
  Author-email: Adam Żmuda <adam@zmuda.pro>
6
6
  License-Expression: MIT
@@ -81,8 +81,8 @@ session, so training A and then B and running once brings both up to date:
81
81
 
82
82
  1. Start at the bottom of the rep range.
83
83
  2. Add a rep to every set each session.
84
- 3. Once every set reaches the top of the range, add weight and reset to the
85
- bottom.
84
+ 3. Once every set reaches the top of the range twice, add weight and reset to
85
+ the bottom.
86
86
  4. If you missed the target, repeat it unchanged.
87
87
  5. A load only counts once you can carry it for the bottom of the range.
88
88
 
@@ -1508,9 +1508,17 @@ def test_a_session_that_tops_the_new_range_earns_the_load_and_needs_no_clamp():
1508
1508
  earned in the ordinary way. Resetting to `rep_low` lands inside the range
1509
1509
  on its own, leaving the clamp - which never touches a weight - nothing to
1510
1510
  do. The clamp is for the workout no session has anything to say about.
1511
+
1512
+ The history is the session that confirms it: rule 3 wants the top of the
1513
+ range twice, so without one behind it this would hold rather than step.
1511
1514
  """
1512
1515
  built = a_stored_squat(12)
1513
- plan = plan_workout(a_workout(exercises=[NARROWED]), built, a_squat_session(12))
1516
+ plan = plan_workout(
1517
+ a_workout(exercises=[NARROWED]),
1518
+ built,
1519
+ a_squat_session(12),
1520
+ {"barbellbacksquat": [Session(Target(12, 20.0), [PerformedSet(12, 20.0)] * 3)]},
1521
+ )
1514
1522
 
1515
1523
  assert plan.moved[0].new == Target(6, 22.5)
1516
1524
  assert plan.changes[0].reason == "hit 12 on every set, top of the range"
@@ -4,16 +4,18 @@ import pytest
4
4
  from builders import held, spec
5
5
 
6
6
  from repwise.domain.models import LoadTier
7
- from repwise.domain.progression import PerformedSet as P
8
7
  from repwise.domain.progression import (
8
+ CONFIRMED_AFTER,
9
9
  Session,
10
10
  Target,
11
11
  _ladder,
12
12
  hit,
13
13
  miss_streak,
14
14
  next_target,
15
+ top_streak,
15
16
  working_weight,
16
17
  )
18
+ from repwise.domain.progression import PerformedSet as P
17
19
  from repwise.domain.progression import missed as is_miss
18
20
 
19
21
  SQUAT = spec()
@@ -75,12 +77,12 @@ def test_exceeding_target_still_counts_as_met():
75
77
 
76
78
 
77
79
  def test_top_of_range_adds_weight_and_resets():
78
- target, why = next_target(SQUAT, Target(10, 20.0), [P(10, 20.0)] * 3)
80
+ target, why = next_target(SQUAT, Target(10, 20.0), [P(10, 20.0)] * 3, topped=1)
79
81
  assert target == Target(6, 25.0), why
80
82
 
81
83
 
82
84
  def test_dumbbell_uses_its_own_step():
83
- target, _ = next_target(LUNGE, Target(12, 4.0), [P(12, 4.0)] * 5)
85
+ target, _ = next_target(LUNGE, Target(12, 4.0), [P(12, 4.0)] * 5, topped=1)
84
86
  assert target == Target(8, 5.0)
85
87
 
86
88
 
@@ -127,14 +129,17 @@ def test_matching_the_target_exactly_does_not_mention_beating_it():
127
129
 
128
130
  def test_reaching_top_of_range_adds_weight_even_if_target_was_lower():
129
131
  """Performing 10s on every set tops out the range, whatever was asked."""
130
- target, why = next_target(SQUAT, Target(7, 20.0), [P(10, 20.0)] * 4)
132
+ target, why = next_target(SQUAT, Target(7, 20.0), [P(10, 20.0)] * 4, topped=1)
131
133
  assert target == Target(6, 25.0), why
132
134
 
133
135
 
134
136
  def test_overshoot_is_capped_at_top_of_range():
135
137
  """A set above rep_high still resets rather than targeting 11+."""
136
138
  target, _ = next_target(
137
- SQUAT, Target(9, 20.0), [P(12, 20.0), P(11, 20.0), P(10, 20.0), P(10, 20.0)]
139
+ SQUAT,
140
+ Target(9, 20.0),
141
+ [P(12, 20.0), P(11, 20.0), P(10, 20.0), P(10, 20.0)],
142
+ topped=1,
138
143
  )
139
144
  assert target == Target(6, 25.0)
140
145
 
@@ -172,26 +177,32 @@ def test_full_sets_at_new_weight_progress_from_there():
172
177
 
173
178
 
174
179
  def test_new_weight_at_top_of_range_still_adds_load():
175
- target, why = next_target(FOUR_SET_SQUAT, Target(7, 20.0), [P(10, 22.5)] * 4)
180
+ target, why = next_target(
181
+ FOUR_SET_SQUAT, Target(7, 20.0), [P(10, 22.5)] * 4, topped=1
182
+ )
176
183
  assert target == Target(6, 25.0), why
177
184
 
178
185
 
179
186
  def test_bottom_of_range_to_top_at_a_heavier_load_adds_load_again():
180
187
  """Planned 6 x 20, did 10 x 22.5: the session's load is the new baseline."""
181
- target, why = next_target(FOUR_SET_SQUAT, Target(6, 20.0), [P(10, 22.5)] * 4)
188
+ target, why = next_target(
189
+ FOUR_SET_SQUAT, Target(6, 20.0), [P(10, 22.5)] * 4, topped=1
190
+ )
182
191
  assert target == Target(6, 25.0), why
183
192
  assert why == "hit 10 on every set at 22.5 kg, top of the range"
184
193
 
185
194
 
186
195
  def test_top_of_range_at_a_heavier_load_adds_load_from_what_was_lifted():
187
196
  """Planned 10 x 20, did 10 x 22.5: step up from 22.5, not from 20."""
188
- target, why = next_target(FOUR_SET_SQUAT, Target(10, 20.0), [P(10, 22.5)] * 4)
197
+ target, why = next_target(
198
+ FOUR_SET_SQUAT, Target(10, 20.0), [P(10, 22.5)] * 4, topped=1
199
+ )
189
200
  assert target == Target(6, 25.0), why
190
201
  assert why == "hit 10 on every set at 22.5 kg, top of the range"
191
202
 
192
203
 
193
204
  def test_top_of_range_at_the_planned_load_does_not_mention_the_load():
194
- _, why = next_target(FOUR_SET_SQUAT, Target(10, 20.0), [P(10, 20.0)] * 4)
205
+ _, why = next_target(FOUR_SET_SQUAT, Target(10, 20.0), [P(10, 20.0)] * 4, topped=1)
195
206
  assert why == "hit 10 on every set, top of the range"
196
207
 
197
208
 
@@ -254,7 +265,9 @@ def test_same_load_below_the_range_still_reads_as_a_missed_target():
254
265
 
255
266
  def test_heavier_load_can_still_top_out_the_range():
256
267
  """Rule 5 gates rule 3 rather than replacing it."""
257
- target, why = next_target(LATERAL_RAISE, Target(13, 3.0), [P(15, 4.0)] * 3)
268
+ target, why = next_target(
269
+ LATERAL_RAISE, Target(13, 3.0), [P(15, 4.0)] * 3, topped=1
270
+ )
258
271
  assert target == Target(12, 5.0), why
259
272
 
260
273
 
@@ -311,7 +324,9 @@ def test_rep_step_does_not_overshoot_the_range():
311
324
 
312
325
 
313
326
  def test_rep_step_still_earns_the_weight_jump_at_the_top():
314
- target, why = next_target(LUNGE_DOUBLED, Target(24, 4.0), [P(24, 4.0)] * 4)
327
+ target, why = next_target(
328
+ LUNGE_DOUBLED, Target(24, 4.0), [P(24, 4.0)] * 4, topped=1
329
+ )
315
330
  assert target == Target(16, 5.0), why
316
331
 
317
332
 
@@ -399,7 +414,7 @@ def test_missing_the_high_sets_of_a_ramp_is_a_miss():
399
414
  def test_beating_a_ramp_everywhere_levels_it_and_advances_from_there():
400
415
  """10 on every set tops the range, ramp or no ramp."""
401
416
  target, why = next_target(
402
- FOUR_SET_SQUAT, Target(8, 20.0, lead=2), [P(10, 20.0)] * 4
417
+ FOUR_SET_SQUAT, Target(8, 20.0, lead=2), [P(10, 20.0)] * 4, topped=1
403
418
  )
404
419
  assert target == Target(6, 22.5), why
405
420
 
@@ -420,7 +435,7 @@ def test_a_ramp_does_not_survive_a_short_session():
420
435
  def test_the_streak_cannot_push_a_target_past_the_top_of_the_range():
421
436
  """At the top it is still a weight jump, whatever the streak was."""
422
437
  target, why = next_target(
423
- FOUR_SET_SQUAT, Target(10, 20.0), [P(10, 20.0)] * 4, streak=3
438
+ FOUR_SET_SQUAT, Target(10, 20.0), [P(10, 20.0)] * 4, streak=3, topped=1
424
439
  )
425
440
  assert target == Target(6, 22.5), why
426
441
 
@@ -594,6 +609,129 @@ def test_a_ramped_target_is_judged_as_a_ramp_when_counting_the_streak():
594
609
  assert miss_streak(FOUR_SET_SQUAT, history, 20.0) == 1
595
610
 
596
611
 
612
+ # --- confirming the top of the range ---------------------------------------
613
+ #
614
+ # Rule 3 wants the top of the range cleared twice at one load before it adds
615
+ # weight, which is ACSM's "two consecutive training sessions". `top_streak`
616
+ # counts what is behind the session being judged; the gate is in `_advance`.
617
+
618
+
619
+ def topped_out(reps=10, weight=20.0, sets=4):
620
+ return Session(Target(reps, weight), [P(reps, weight)] * sets)
621
+
622
+
623
+ def test_no_history_confirms_nothing():
624
+ assert top_streak(FOUR_SET_SQUAT, [], 20.0) == 0
625
+
626
+
627
+ def test_a_session_at_the_top_confirms():
628
+ assert top_streak(FOUR_SET_SQUAT, [topped_out()], 20.0) == 1
629
+
630
+
631
+ def test_the_count_stops_at_a_session_that_did_not_reach_the_top():
632
+ assert top_streak(FOUR_SET_SQUAT, [topped_out(9)], 20.0) == 0
633
+
634
+
635
+ def test_a_session_past_the_top_still_confirms():
636
+ """Rule 3 fires at `rep_high` or above, and so does the confirmation."""
637
+ assert top_streak(FOUR_SET_SQUAT, [topped_out(12)], 20.0) == 1
638
+
639
+
640
+ def test_the_count_stops_at_a_change_of_load():
641
+ """Clearing the top at 17.5 says nothing about whether 22.5 is earned."""
642
+ assert top_streak(FOUR_SET_SQUAT, [topped_out(weight=17.5)], 20.0) == 0
643
+
644
+
645
+ def test_the_count_stops_at_a_session_with_nothing_logged():
646
+ assert top_streak(FOUR_SET_SQUAT, [Session(Target(10, 20.0), [])], 20.0) == 0
647
+
648
+
649
+ def test_a_session_too_short_to_judge_confirms_nothing():
650
+ """Rule 3's own set count: a session that would have consolidated cannot
651
+ confirm a jump either."""
652
+ short = Session(Target(10, 20.0), [P(10, 20.0)] * 2)
653
+ assert top_streak(FOUR_SET_SQUAT, [short], 20.0) == 0
654
+
655
+
656
+ def test_the_count_is_bounded_at_what_the_rule_asks_for():
657
+ """Nothing above CONFIRMED_AFTER exists to find - the load moves there and
658
+ the next session restarts at rep_low - so the walk stops rather than
659
+ reading history it cannot use."""
660
+ assert top_streak(FOUR_SET_SQUAT, [topped_out()] * 9, 20.0) == CONFIRMED_AFTER
661
+
662
+
663
+ def test_a_heavier_set_counts_towards_confirming_too():
664
+ """The same credit rule 3 gives the session it is judging."""
665
+ mixed = Session(Target(10, 20.0), [P(10, 20.0)] * 3 + [P(10, 22.5)])
666
+ assert top_streak(FOUR_SET_SQUAT, [mixed], 20.0) == 1
667
+
668
+
669
+ def test_the_first_top_of_the_range_holds_instead_of_adding_load():
670
+ target, why = next_target(FOUR_SET_SQUAT, Target(10, 20.0), [P(10, 20.0)] * 4)
671
+ assert target == Target(10, 20.0), why
672
+ assert why == (
673
+ "hit 10 on every set, top of the range, hold it once more "
674
+ "before the load goes up"
675
+ )
676
+
677
+
678
+ def test_holding_at_the_top_is_not_a_miss():
679
+ """It is a session that did everything asked of it, so nothing marks the
680
+ watch and nothing in the report calls it a failure."""
681
+ _, why = next_target(FOUR_SET_SQUAT, Target(10, 20.0), [P(10, 20.0)] * 4)
682
+ assert not is_miss(why)
683
+
684
+
685
+ def test_the_second_top_of_the_range_adds_the_load():
686
+ target, why = next_target(
687
+ FOUR_SET_SQUAT, Target(10, 20.0), [P(10, 20.0)] * 4, topped=1
688
+ )
689
+ assert target == Target(6, 22.5), why
690
+
691
+
692
+ def test_the_hold_lands_on_the_top_of_the_range_from_below_it():
693
+ """A session that beat a lower target still ends up at rep_high, so the
694
+ confirming session is asked for what it just did rather than for less."""
695
+ target, why = next_target(FOUR_SET_SQUAT, Target(7, 20.0), [P(10, 20.0)] * 4)
696
+ assert target == Target(10, 20.0), why
697
+
698
+
699
+ def test_an_overshoot_is_still_capped_at_the_top_while_it_holds():
700
+ target, _ = next_target(FOUR_SET_SQUAT, Target(9, 20.0), [P(12, 20.0)] * 4)
701
+ assert target == Target(10, 20.0)
702
+
703
+
704
+ def test_a_rebased_load_needs_confirming_at_that_load():
705
+ """Rule 5 admits 22.5 and the session tops the range on it, but the top of
706
+ the range at 22.5 has still only been reached once."""
707
+ target, why = next_target(FOUR_SET_SQUAT, Target(7, 20.0), [P(10, 22.5)] * 4)
708
+ assert target == Target(10, 22.5), why
709
+ assert "at 22.5 kg" in why
710
+
711
+
712
+ def test_bodyweight_is_not_asked_to_confirm():
713
+ """There is no load to add, so a confirmation would buy nothing and the
714
+ report would promise a jump that is never coming."""
715
+ _, why = next_target(PLANK, Target(60, 0.0), [P(60, 0.0)] * 3)
716
+ assert why == "top of the range, and bodyweight, so nothing to add"
717
+
718
+
719
+ def test_an_exercise_out_of_rack_is_not_asked_to_confirm():
720
+ """The same ending reached from the other side."""
721
+ _, why = next_target(HOME_PRESS, Target(18, 10.0), [P(18, 10.0)] * 3)
722
+ assert "already at the 10 kg maximum" in why
723
+
724
+
725
+ def test_a_stall_at_the_top_is_still_a_stall():
726
+ """The hold repeats rep_high; missing it twice deloads as it always did,
727
+ so the confirmation cannot trap an exercise at the top of its range."""
728
+ target, why = next_target(
729
+ FOUR_SET_SQUAT, Target(10, 20.0), [P(9, 20.0)] * 4, streak=1
730
+ )
731
+ assert target.reps < 10, why
732
+ assert is_miss(why)
733
+
734
+
597
735
  # --- deloading ------------------------------------------------------------
598
736
  #
599
737
  # Missing once is a bad day and repeats. Missing the same target twice is a
@@ -807,14 +945,14 @@ def test_a_capped_exercise_holds_at_the_top_of_the_range():
807
945
 
808
946
  def test_the_last_step_is_shortened_to_land_on_the_maximum():
809
947
  """9 + 2.5 is 11.5, which does not exist - but the 10 kg pair does."""
810
- target, why = next_target(HOME_PRESS, Target(16, 9.0), [P(16, 9.0)] * 3)
948
+ target, why = next_target(HOME_PRESS, Target(16, 9.0), [P(16, 9.0)] * 3, topped=1)
811
949
  assert target == Target(HOME_PRESS.rep_low, 10.0), why
812
950
  assert "up to the 10 kg maximum" in why
813
951
 
814
952
 
815
953
  def test_the_shortened_step_is_taken_once_and_then_holds():
816
954
  """Reaching the ceiling is a rung to climb, not a place to hover below."""
817
- stepped, why = next_target(HOME_PRESS, Target(16, 9.0), [P(16, 9.0)] * 3)
955
+ stepped, why = next_target(HOME_PRESS, Target(16, 9.0), [P(16, 9.0)] * 3, topped=1)
818
956
  assert stepped == Target(10, 10.0), why
819
957
 
820
958
  held, why = next_target(HOME_PRESS, stepped, [P(16, 10.0)] * 3)
@@ -830,14 +968,14 @@ def test_a_load_already_past_the_maximum_is_not_pulled_down():
830
968
 
831
969
  def test_below_the_maximum_the_weight_still_climbs():
832
970
  """The ceiling is a stop, not a brake: every step under it is taken."""
833
- target, why = next_target(HOME_PRESS, Target(16, 7.5), [P(16, 7.5)] * 3)
971
+ target, why = next_target(HOME_PRESS, Target(16, 7.5), [P(16, 7.5)] * 3, topped=1)
834
972
  assert target == Target(HOME_PRESS.rep_low, 10.0), why
835
973
 
836
974
 
837
975
  def test_no_maximum_means_the_weight_keeps_climbing():
838
976
  """The default, and what every config written before ceilings did."""
839
977
  assert SQUAT.max_weight is None
840
- target, _ = next_target(SQUAT, Target(10, 20.0), [P(10, 20.0)] * 3)
978
+ target, _ = next_target(SQUAT, Target(10, 20.0), [P(10, 20.0)] * 3, topped=1)
841
979
  assert target == Target(SQUAT.rep_low, 25.0)
842
980
 
843
981
 
@@ -943,13 +1081,13 @@ FLYE = spec(
943
1081
 
944
1082
  def test_topping_out_a_rack_graduates_to_the_next_one():
945
1083
  """10 kg is the heaviest pair on the small rack, so rule 3 crosses over."""
946
- target, why = next_target(FLYE, Target(14, 10.0), [P(14, 10.0)] * 3)
1084
+ target, why = next_target(FLYE, Target(14, 10.0), [P(14, 10.0)] * 3, topped=1)
947
1085
  assert target == Target(10, 12.0), why
948
1086
  assert "onto the next rack at 12 kg" in why
949
1087
 
950
1088
 
951
1089
  def test_climbing_within_a_rack_says_nothing_about_racks():
952
- target, why = next_target(FLYE, Target(14, 12.0), [P(14, 12.0)] * 3)
1090
+ target, why = next_target(FLYE, Target(14, 12.0), [P(14, 12.0)] * 3, topped=1)
953
1091
  assert target == Target(10, 14.0), why
954
1092
  assert "rack" not in why
955
1093
 
@@ -982,8 +1120,8 @@ def test_the_increment_chosen_grows_with_the_load():
982
1120
  min_weight=5.0,
983
1121
  tiers=(LoadTier(5.0, None, (1.25, 2.5, 5.0)),),
984
1122
  )
985
- light, _ = next_target(stack, Target(15, 5.0), [P(15, 5.0)] * 3)
986
- heavy, _ = next_target(stack, Target(15, 45.0), [P(15, 45.0)] * 3)
1123
+ light, _ = next_target(stack, Target(15, 5.0), [P(15, 5.0)] * 3, topped=1)
1124
+ heavy, _ = next_target(stack, Target(15, 45.0), [P(15, 45.0)] * 3, topped=1)
987
1125
  assert light == Target(10, 6.25)
988
1126
  assert heavy == Target(10, 50.0)
989
1127
 
@@ -998,7 +1136,7 @@ def test_rule_three_never_resets_the_range_without_adding_load():
998
1136
  stepping = spec(
999
1137
  rep_low=6, rep_high=10, sets=3, load="barbell", weight_step=2.2, min_weight=0.0
1000
1138
  )
1001
- target, why = next_target(stepping, Target(10, 33.0), [P(10, 33.0)] * 3)
1139
+ target, why = next_target(stepping, Target(10, 33.0), [P(10, 33.0)] * 3, topped=1)
1002
1140
  assert target.weight > 33.0, why
1003
1141
  assert target.reps == 6
1004
1142
 
@@ -806,6 +806,24 @@ def test_a_smooth_session_reads_back_one_activity_and_stops(stalling):
806
806
  assert stalling.read_back == ["800"]
807
807
 
808
808
 
809
+ def test_a_single_set_exercise_still_reads_one_session_back(stalling):
810
+ """`sets - 1` is no history at all at one set, which used to mean none was
811
+ fetched. Rule 3's confirmation needs the session before this one, so an
812
+ exercise at the top of its range would otherwise hold there forever with
813
+ nothing to confirm against."""
814
+ one_set = Config(
815
+ {
816
+ "Workout A": Workout(
817
+ "Workout A", "111", ["workout a"], [replace(SQUAT, sets=1)]
818
+ )
819
+ }
820
+ )["Workout A"]
821
+ earlier = sessions_before(stalling.activities, one_set, "900")
822
+ gather_history(stalling, one_set, earlier, performed_sets(stalling.sets["900"]))
823
+
824
+ assert stalling.read_back == ["800"]
825
+
826
+
809
827
  def test_a_change_of_load_ends_the_walk(stalling):
810
828
  """A different weight is a different ladder, so its misses do not count."""
811
829
  stalling.sets["800"] = sets_of(*squats(7, weight=27500.0))
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes