From 7e2b4df18b6f9314514fc88f8d00e34073db9193 Mon Sep 17 00:00:00 2001 From: Piotr Podusowski Date: Wed, 14 Jun 2017 19:32:13 +0200 Subject: [PATCH] #20 support timer volume in excercise --- tests/test_strength.py | 2 +- training/models.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_strength.py b/tests/test_strength.py index 7f2db50..3f640b5 100644 --- a/tests/test_strength.py +++ b/tests/test_strength.py @@ -112,8 +112,8 @@ def test_timer_based_excercise(self): self.assertEqual('plank front', excercises[0].name) self.assertEqual(1, excercises[0].count) - #self.assertEqual(units.Volume(seconds=15), excercises[0].volume) + self.assertEqual(units.Volume(seconds=self.ONE_HOUR.total_seconds()), excercise.volume) self.assertEqual(units.Volume(seconds=60*60), workout.volume) def test_timer_based_excercise_with_two_reps(self): diff --git a/training/models.py b/training/models.py index 3cfe80b..c444e59 100644 --- a/training/models.py +++ b/training/models.py @@ -73,7 +73,13 @@ class Meta: class Excercise(models.Model): @property def volume(self): - return units.Volume(reps=self.reps_set.aggregate(Sum('reps'))['reps__sum'] or 0) + reps = self.reps_set.aggregate(Sum('reps'))['reps__sum'] + duration = self.timers_set.aggregate(value=Sum('duration'))['value'] + + if reps: + return units.Volume(reps=reps) + else: + return units.Volume(seconds=duration.total_seconds()) def duration(self): if self.time_started is not None and self.time_finished is not None: