Ejemplo n.º 1
0
    def test_calculate_intervals(self):
        """
        Calculates intervals for a set and returns nothing.
        """
        week = test.create_week()
        week.populate()
        team = test.create_team(self.user)
        swimmer1 = test.create_swimmer(team)
        swimmer2 = test.create_swimmer(team, first='Dave', last='Thornton')
        base1_free = test.create_event(swimmer1, 'base free',
                                       timedelta(seconds=25))
        base2_free = test.create_event(swimmer2, 'base free',
                                       timedelta(seconds=24))

        training_model = test.create_training_model(team)
        training_mult = test.create_training_multiplier(training_model,
                                                        multiplier=0.07)

        practice = test.create_practice(team, week)
        setInstance = test.create_set(practice, swimmers=[swimmer1, swimmer2])
        rep1 = test.create_rep(setInstance)

        funct.calculate_intervals(setInstance, training_model)
        intervals = Interval.objects.filter(rep=rep1)
        self.assertEqual(intervals[0].swimmer.l_name, 'Gridley')
        self.assertEqual(intervals[1].swimmer.l_name, 'Thornton')
        self.assertEqual(intervals[0].time, timedelta(seconds=55))
        self.assertEqual(intervals[1].time, timedelta(seconds=55))
Ejemplo n.º 2
0
    def test_clean_weekday(self):
        """
        Only one practice can exist on a weekday for each given week.
        """
        week1 = test.create_week(monday=date.today())
        week1.populate()
        week2 = test.create_week(monday=(date.today() + relativedelta(days=7)))
        week2.populate()
        team = test.create_team(user=self.user)
        practice1 = test.create_practice(team, week1)
        practice2 = test.create_practice(team, week1)
        practice3 = test.create_practice(team, week2)

        funct.clean_weekday(team, practice2)

        practices = Practice.objects.all()
        self.assertQuerysetEqual(practices,
                                 ['<Practice: monday>', '<Practice: monday>'],
                                 ordered=False)
        self.assertTrue(practice1 not in practices)
Ejemplo n.º 3
0
    def test_get_practices_and_dates(self):
        """
        Returns a list of practices and a list of dates.
        """
        weeks = funct.get_or_create_weeks(0)
        team = test.create_team(user=self.user)
        swimmer1 = test.create_swimmer(team)
        base_free = test.create_event(swimmer1,
                                      event='base free',
                                      time=timedelta(seconds=25))
        swimmer2 = test.create_swimmer(team, first='Dave', last='Thornton')
        practice = test.create_practice(team, weeks['current'])
        setInstance = test.create_set(practice=practice,
                                      swimmers=[swimmer1, swimmer2])
        rep1 = test.create_rep(setInstance)

        training_model = test.create_training_model(team)
        training_mult = test.create_training_multiplier(training_model,
                                                        multiplier=0.07)
        funct.calculate_intervals(setInstance, training_model)

        practices, dates = funct.get_practices_and_dates(team, weeks)

        test_dates = []
        for day in weeks['current'].date_range():
            test_dates.append(day)

        intervals = Interval.objects.filter(rep=rep1)
        self.assertEqual(practices, [
            ((practice, [(setInstance, [(swimmer1, [(rep1, intervals[0])]),
                                        (swimmer2, [(rep1, None)])])
                         ]), 'monday'),
            ((None, (None, (None, (None, None)))), 'tuesday'),
            ((None, (None, (None, (None, None)))), 'wednesday'),
            ((None, (None, (None, (None, None)))), 'thursday'),
            ((None, (None, (None, (None, None)))), 'friday'),
            ((None, (None, (None, (None, None)))), 'saturday'),
            ((None, (None, (None, (None, None)))), 'sunday'),
        ])
        self.assertEqual(dates, [
            ('monday', test_dates[0]),
            ('tuesday', test_dates[1]),
            ('friday', test_dates[4]),
            ('wednesday', test_dates[2]),
            ('thursday', test_dates[3]),
            ('sunday', test_dates[6]),
            ('saturday', test_dates[5]),
        ])
Ejemplo n.º 4
0
    def test_get_zipped_set(self):
        """
        Returns list of tuples containing the rep, swimmer, and interval.
        """
        week = test.create_week()
        week.populate()
        team = test.create_team(self.user)
        swimmer1 = test.create_swimmer(team)
        swimmer2 = test.create_swimmer(team, first='Dave', last='Thornton')
        base1_free = test.create_event(swimmer1, 'base free',
                                       timedelta(seconds=25))
        base2_free = test.create_event(swimmer2, 'base free',
                                       timedelta(seconds=24))

        practice = test.create_practice(team, week)
        setInstance = test.create_set(practice, swimmers=[swimmer1, swimmer2])
        rep1 = test.create_rep(setInstance)

        training_model = test.create_training_model(team)

        funct.calculate_intervals(setInstance, training_model)
        intervals = Interval.objects.filter(rep=rep1)
        set_zip = funct.get_zipped_set(setInstance)

        self.assertEqual(set_zip, [
            (swimmer1, [(rep1, None)]),
            (swimmer2, [(rep1, None)]),
        ])

        training_mult = test.create_training_multiplier(training_model,
                                                        multiplier=0.07)

        funct.calculate_intervals(setInstance, training_model)
        intervals = Interval.objects.filter(rep=rep1)
        set_zip = funct.get_zipped_set(setInstance)

        self.assertEqual(set_zip, [
            (swimmer1, [(rep1, intervals[0])]),
            (swimmer2, [(rep1, intervals[1])]),
        ])
Ejemplo n.º 5
0
 def setUp(self):
     user = test.create_user('user', 'password')
     team = test.create_team(user=user)
     week = test.create_week()
     practice = test.create_practice(team, week)
     self.test_set = test.create_set(practice=practice)
Ejemplo n.º 6
0
 def setUp(self):
     user = test.create_user('user', 'password')
     self.team = test.create_team(user=user)
     week = test.create_week()
     self.practice = test.create_practice(self.team, week)