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

Commit

Permalink
#20 strength workout.volume is now MultiVolume
Browse files Browse the repository at this point in the history
  • Loading branch information
podusowski committed Jul 15, 2017
1 parent 85ec919 commit d72fee5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
13 changes: 9 additions & 4 deletions activities/strength/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ def redirect_to_workout(workout):

def volume(workout):
duration = models.Timers.objects.filter(excercise__workout=workout).aggregate(value=Sum('duration'))['value']
reps = models.Reps.objects.filter(excercise__workout=workout).aggregate(Sum('reps'))['reps__sum'] or 0
reps = models.Reps.objects.filter(excercise__workout=workout).aggregate(Sum('reps'))['reps__sum']

values = []

if duration:
return units.Volume(seconds=duration.total_seconds())
else:
return units.Volume(reps=reps)
values.append(units.Volume(seconds=duration.total_seconds()))

if reps:
values.append(units.Volume(reps=reps))

return units.MultiVolume(values)
16 changes: 16 additions & 0 deletions tests/test_strength.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ def test_timer_based_excercise(self):

self.assertEqual(units.Volume(seconds=ONE_HOUR.total_seconds()), workout.volume)

def test_timer_mixed_with_reps_workout(self):
workout = self._start_workout()

self.post('/strength/add_excercise/{}/'.format(workout.id), {'name': 'plank front'})
excercise = workout.excercise_set.latest('pk')
self._timer_rep(excercise.id, ONE_O_CLOCK, TWO_O_CLOCK)

self.post('/strength/add_excercise/{}/'.format(workout.id), {'name': 'push-up'})
excercise = workout.excercise_set.latest('pk')
self.post('/strength/add_reps/{}/'.format(excercise.id), {'reps': '2'})
self.post('/strength/add_reps/{}/'.format(excercise.id), {'reps': '1'})

self.assertEqual(units.MultiVolume([units.Volume(seconds=ONE_HOUR.total_seconds()),
units.Volume(reps=3)]),
workout.volume)

def test_undo_last_rep(self):
workout = self._start_workout()

Expand Down

0 comments on commit d72fee5

Please sign in to comment.