Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

Commit

Permalink
#20 support timer volume in excercise
Browse files Browse the repository at this point in the history
  • Loading branch information
podusowski committed Jun 14, 2017
1 parent 25ea0a3 commit 7e2b4df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/test_strength.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 7 additions & 1 deletion training/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7e2b4df

Please sign in to comment.