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

Commit

Permalink
#20 replace time finished with duration to simplify stats calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
podusowski committed Jun 14, 2017
1 parent ca4330c commit e14bb93
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion activities/strength/strength_workout.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def start_timer(user, excercise_id):
def stop_timer(user, excercise_id):
excercise = models.Excercise.objects.get(pk=excercise_id, workout__user=user)
timer = excercise.timers_set.latest('pk')
timer.time_finished = django.utils.timezone.now()
timer.duration = django.utils.timezone.now() - timer.time_started
timer.save()
return excercise.workout.id

Expand Down
7 changes: 5 additions & 2 deletions tests/test_strength.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest.mock import patch
from datetime import timedelta

from tests.utils import time, ClientTestCase
from tests import utils
Expand Down Expand Up @@ -77,6 +78,8 @@ def test_add_some_excercises_and_reps(self):
THREE_O_CLOCK = time(2016, 1, 1, 15, 0, 0)
FOUR_O_CLOCK = time(2016, 1, 1, 16, 0, 0)

ONE_HOUR = timedelta(hours=1)

def _timer_rep(self, excercise_id, time_start, time_finished):
with patch('django.utils.timezone.now', autospec=True) as now:
now.return_value = time_start
Expand All @@ -101,7 +104,7 @@ def test_timer_based_excercise(self):
first_timer = excercise.timers_set.all()[0]

self.assertEqual(self.ONE_O_CLOCK, first_timer.time_started)
self.assertEqual(self.TWO_O_CLOCK, first_timer.time_finished)
self.assertEqual(self.ONE_HOUR, first_timer.duration)

statistics = self._get_statistics_from_dashboard()
excercises = statistics.most_popular_workouts()
Expand All @@ -128,7 +131,7 @@ def test_timer_based_excercise_with_two_reps(self):
second_timer = excercise.timers_set.all()[1]

self.assertEqual(self.THREE_O_CLOCK, second_timer.time_started)
self.assertEqual(self.FOUR_O_CLOCK, second_timer.time_finished)
self.assertEqual(self.ONE_HOUR, second_timer.duration)

def test_undo_last_rep(self):
workout = self._start_workout()
Expand Down
24 changes: 24 additions & 0 deletions training/migrations/0039_auto_20170614_0711.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-06-14 07:11
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('training', '0038_auto_20170528_1931'),
]

operations = [
migrations.RemoveField(
model_name='timers',
name='time_finished',
),
migrations.AddField(
model_name='timers',
name='duration',
field=models.DurationField(default=None, null=True),
),
]
2 changes: 1 addition & 1 deletion training/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Timers(models.Model):
'''
excercise = models.ForeignKey(Excercise)
time_started = models.DateTimeField(null=True, default=None)
time_finished = models.DateTimeField(null=True, default=None)
duration = models.DurationField(null=True, default=None)

class Meta:
ordering = ['pk']
Expand Down

0 comments on commit e14bb93

Please sign in to comment.