Self hosted FLOSS fitness/workout, nutrition and weight tracker
Correctly calculate sets for one exercise
Roland Geider4b8913e27e89
diff --git a/wger/manager/models/slot.py b/wger/manager/models/slot.pyindex 979b19a0e..86c2342b4 100644--- a/wger/manager/models/slot.py+++ b/wger/manager/models/slot.py@@ -80,31 +80,42 @@ class Slot(models.Model):"""Calculates the sets as they would be performed in the gym- Note that this is only different from the list of sets in supersets, since- they will be "interleaved". E.g.:- - Exercise 1, 4 Sets- - Exercise 2, 3 Sets- - Exercise 3, 2 Sets+ * For supersets:+ The sets will be interleaved as well as possible, e.g.:+ - Exercise 1, 4 sets+ - Exercise 2, 3 sets+ - Exercise 3, 2 sets(the other weight, reps, etc. settings are not important here)Would result in:- - Exercise 1- - Exercise 2- - Exercise 3- - Exercise 1- - Exercise 2- - Exercise 3- - Exercise 1- - Exercise 2- - Exercise 1+ - Exercise 1, 1 set+ - Exercise 2, 1 set+ - Exercise 3, 1 set+ - Exercise 1, 1 set+ - Exercise 2, 1 set+ - Exercise 3, 1 set+ - Exercise 1, 1 set+ - Exercise 2, 1 set+ - Exercise 1, 1 set++ * For regular sets:+ The sets are just repeated, e.g.:+ - Exercise 1, 4 sets++ Would result in:+ - Exercise 1, 1 set+ - Exercise 1, 1 set+ - Exercise 1, 1 set+ - Exercise 1, 1 set"""set_data = self.set_data(iteration)- # If this is not a superset, just return the data+ # If this is not a superset, adjust the sets and just return the dataif len(set_data) == 1:- return [- set_data[0].data,- ]+ data = set_data[0].data+ nr_sets = int(data.sets)+ data.sets = 1+ return [data] * nr_setsresult = []sets = [slot.data.sets for slot in set_data]diff --git a/wger/manager/tests/test_slot.py b/wger/manager/tests/test_slot.pyindex 95193318a..359acafd8 100644--- a/wger/manager/tests/test_slot.py+++ b/wger/manager/tests/test_slot.py@@ -92,6 +92,7 @@ class SlotTestCase(WgerTestCase):result = self.slot.get_sets(1)- self.assertEqual(len(result), 1)- self.assertEqual(result[0].exercise, 1)- self.assertEqual(result[0].sets, Decimal(4))+ self.assertEqual(len(result), 4)+ for i in range(0, 3):+ self.assertEqual(result[i].exercise, 1)+ self.assertEqual(result[i].sets, 1)