Beispiel #1
0
    def test_get_record(self):
        """
        Returns the fastest time for men and women in the given event.
        """
        team = test.create_team(self.user)
        swimmer1 = test.create_swimmer(team)
        swimmer2 = test.create_swimmer(team, first='Jane', last='Doe', gender='F')
        event1 = test.create_event(swimmer1, '50 free', timedelta(seconds=22.32))
        event2 = test.create_event(swimmer1, '50 free', timedelta(seconds=22.96))
        event3 = test.create_event(swimmer2, '50 free', timedelta(seconds=23.51))
        event1.set_gender()
        event1.team = team
        event1.save()
        event2.set_gender()
        event2.team = team
        event2.save()
        event3.set_gender()
        event3.team = team
        event3.save()

        records1 = team.get_record(('50 free', '50 Freestyle'))
        records2 = team.get_record(('100 free', '100 Freestyle'))

        self.assertEqual(records1, ('50 Freestyle', event1, event3))
        self.assertEqual(records2, ('100 Freestyle', None, None))
Beispiel #2
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))
Beispiel #3
0
 def test_best_time(self):
     """
     Returns the best time in the given event.
     """
     team = test.create_team(user=self.user)
     swimmer = test.create_swimmer(team=team)
     test.create_event(swimmer=swimmer)
     test.create_event(swimmer=swimmer, time=timedelta(seconds=22.96))
     self.assertEqual(swimmer.get_best_time(event='50 free').time, timedelta(seconds=22.32))
     self.assertNotEqual(swimmer.get_best_time(event='50 free').time, timedelta(seconds=22.96))
Beispiel #4
0
    def test_get_base(self):
        """
        Returns the base for the given swimmer depending on the pace specified.
        """
        team = test.create_team(self.user)
        swimmer = test.create_swimmer(team)
        base_free = test.create_event(swimmer, 'base free', timedelta(seconds=25))
        race_free = test.create_event(swimmer, '100 free', timedelta(seconds=49.86))

        base_train = swimmer.get_base('train', 'free')
        base_race = swimmer.get_base('race', 'free')
        none_race = swimmer.get_base('race', 'back')
        self.assertEqual(base_train, timedelta(seconds=25))
        self.assertEqual(base_race, timedelta(seconds=24.93))
        self.assertEqual(none_race, None)
Beispiel #5
0
    def test_set_name(self):
        """
        Set event name from swimmer name.
        """
        team = test.create_team(self.user)
        swimmer = test.create_swimmer(team)
        event = test.create_event(swimmer=swimmer)

        event.set_name()
        self.assertEqual(event.name, 'Henry Gridley')
Beispiel #6
0
    def test_set_gender(self):
        """
        Set event gender from swimmer gender.
        """
        team = test.create_team(self.user)
        swimmer = test.create_swimmer(team)
        event = test.create_event(swimmer=swimmer)

        event.set_gender()
        self.assertEqual(event.gender, 'M')
Beispiel #7
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])]),
        ])
Beispiel #8
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]),
        ])