Self hosted FLOSS fitness/workout, nutrition and weight tracker
Clamp gated progression pointer to the current iteration
Roland Geiderf2c1dcbedf80
diff --git a/wger/manager/models/slot_entry.py b/wger/manager/models/slot_entry.pyindex 551f2d866..2b4edd918 100644--- a/wger/manager/models/slot_entry.py+++ b/wger/manager/models/slot_entry.py@@ -474,7 +474,9 @@ class SlotEntry(models.Model):# Advance exactly one earned increment per qualifying iteration# instead of jumping to the calendar index, which would# back-fill increments for skipped, non-qualifying iterations.- max_iterations[field] += 1+ # Clamped to i so that logs stamped with iteration 0 can't+ # advance the pointer into a future iteration's config.+ max_iterations[field] = min(max_iterations[field] + 1, i)breaksets = self.calculate_sets(max_iterations['sets'])diff --git a/wger/manager/tests/test_slot_entry.py b/wger/manager/tests/test_slot_entry.pyindex 271d2c590..9d26896b3 100644--- a/wger/manager/tests/test_slot_entry.py+++ b/wger/manager/tests/test_slot_entry.py@@ -530,7 +530,7 @@ class SlotEntryTestCase(WgerTestCase):self.assertEqual(config_data.rir, None)self.assertEqual(config_data.weight, 80)- def _setup_gated_weight_progression(self):+ def _setup_gated_weight_progression(self, gate_base_config: bool = False):"""Base weight of 20, +2.5 kg per iteration (repeating), gated on reachingthe prescribed 5 repetitions@@ -543,6 +543,7 @@ class SlotEntryTestCase(WgerTestCase):slot_entry=self.slot_entry,iteration=1,value=20,+ requirements={'rules': ['repetitions']} if gate_base_config else None,).save()WeightConfig(slot_entry=self.slot_entry,@@ -609,6 +610,18 @@ class SlotEntryTestCase(WgerTestCase):self.assertEqual(self.slot_entry.get_config_data(3).weight, Decimal(25))self.assertEqual(self.slot_entry.get_config_data(4).weight, Decimal('27.5'))+ def test_requirements_iteration_zero_log_does_not_advance(self):+ """+ A log stamped with iteration 0 doesn't advance a gated progression into+ the config of a later iteration+ """+ self._setup_gated_weight_progression(gate_base_config=True)++ self._log_repetitions(iteration=0, repetitions=5)++ # The +2.5 config only takes effect at iteration 2+ self.assertEqual(self.slot_entry.get_config_data(1).weight, Decimal(20))+def test_weight_config_with_logs_and_range(self):"""Test that the weight is correctly calculated for each step / iteration