Self hosted FLOSS fitness/workout, nutrition and weight tracker
Properly handle the max-* values when calculating progression rules
Roland Geider08fe8eb3c096
diff --git a/wger/manager/models/slot_entry.py b/wger/manager/models/slot_entry.pyindex f46748ce9..842072ebc 100644--- a/wger/manager/models/slot_entry.py+++ b/wger/manager/models/slot_entry.py@@ -399,15 +399,15 @@ class SlotEntry(models.Model):max_iterations = {'weight': 1,- 'max_weight': 1,+ 'maxweight': 1,'repetitions': 1,- 'max_repetitions': 1,+ 'maxrepetitions': 1,'rir': 1,- 'max_rir': 1,+ 'maxrir': 1,'rest': 1,- 'max_rest': 1,+ 'maxrest': 1,'sets': 1,- 'max_sets': 1,+ 'maxsets': 1,}def _requirement_met(log: WorkoutLog, field_name: str) -> bool:@@ -474,19 +474,19 @@ class SlotEntry(models.Model):breaksets = self.calculate_sets(max_iterations['sets'])- max_sets = self.calculate_maxsets(max_iterations['max_sets'])+ max_sets = self.calculate_maxsets(max_iterations['maxsets'])weight = self.calculate_weight(max_iterations['weight'])- max_weight = self.calculate_maxweight(max_iterations['max_weight'])+ max_weight = self.calculate_maxweight(max_iterations['maxweight'])repetitions = self.calculate_repetitions(max_iterations['repetitions'])- max_repetitions = self.calculate_maxrepetitions(max_iterations['max_repetitions'])+ max_repetitions = self.calculate_maxrepetitions(max_iterations['maxrepetitions'])rir = self.calculate_rir(max_iterations['rir'])- max_rir = self.calculate_maxrir(max_iterations['max_rir'])+ max_rir = self.calculate_maxrir(max_iterations['maxrir'])rest = self.calculate_rest(max_iterations['rest'])- max_rest = self.calculate_maxrest(max_iterations['max_rest'])+ max_rest = self.calculate_maxrest(max_iterations['maxrest'])result = SetConfigData(slot_entry_id=self.id,diff --git a/wger/manager/tests/test_slot_entry.py b/wger/manager/tests/test_slot_entry.pyindex 8bc2c421f..a0e0b2b59 100644--- a/wger/manager/tests/test_slot_entry.py+++ b/wger/manager/tests/test_slot_entry.py@@ -533,7 +533,10 @@ class SlotEntryTestCase(WgerTestCase):def test_weight_config_with_logs_and_range(self):"""Test that the weight is correctly calculated for each step / iteration- if there are logs and there is a weight / rep range+ if there are logs and there is a weight / rep range.++ Also covers that the upper bound of the range progresses across iterations+ and is not pinned to the value of the first iteration."""self.slot_entry.weight_rounding = 2.5@@ -555,6 +558,10 @@ class SlotEntryTestCase(WgerTestCase):value=100,).save()+ # Upper bound rises to 8 reps x 120 kg at iteration 3+ MaxWeightConfig(slot_entry=self.slot_entry, iteration=3, value=120).save()+ MaxRepetitionsConfig(slot_entry=self.slot_entry, iteration=3, value=8).save()+# Only did 4x82.5 at iteration 2WorkoutLog(exercise_id=1,@@ -619,6 +626,28 @@ class SlotEntryTestCase(WgerTestCase):),)+ # The upper bound has progressed to its iteration-3 value+ self.assertEqual(+ self.slot_entry.get_config_data(3),+ SetConfigData(+ slot_entry_id=self.slot_entry.pk,+ exercise=1,+ sets=1,+ weight=Decimal(80),+ weight_unit=1,+ weight_unit_name='kg',+ max_weight=Decimal(120),+ weight_rounding=Decimal('2.5'),+ repetitions=Decimal(4),+ repetitions_unit=1,+ repetitions_unit_name='Repetitions',+ repetitions_rounding=2,+ max_repetitions=Decimal(8),+ rir=None,+ rest=None,+ ),+ )+def test_weight_config_custom_python_class(self):"""Test that the weight is correctly calculated for each step / iteration