示例#1
0
    def testUserOverallRoundRankWithSubmissionDate(self):
        """Tests that the overall rank calculation for a user in a round is
        correct based on submission date."""
        top_entry = ScoreboardEntry.objects.filter(
            round_name=self.current_round).order_by("-points")[0]
        entry, _ = ScoreboardEntry.objects.get_or_create(
            profile=self.user.get_profile(),
            round_name=self.current_round,
        )
        entry.points = top_entry.points + 1
        entry.last_awarded_submission = datetime.datetime.today(
        ) - datetime.timedelta(days=3)
        entry.save()

        self.assertEqual(
            score_mgr.player_rank(self.user.get_profile(), self.current_round),
            1, "Check user is ranked #1 for the current round.")

        user2 = User(username="******", password="******")
        user2.save()

        profile2 = user2.get_profile()
        entry2, _ = ScoreboardEntry.objects.get_or_create(
            profile=profile2,
            round_name=self.current_round,
        )
        entry2.points = entry.points
        entry2.last_awarded_submission = datetime.datetime.today()
        entry2.save()

        self.assertEqual(
            score_mgr.player_rank(self.user.get_profile(), self.current_round),
            2, "Check user is now second.")
示例#2
0
    def testRoundRankWithoutEntry(self):
        """Tests that the overall rank calculation is correct even if a user
        has not done anything yet."""
        group = Group(name="Test group")
        group.save()
        team = Team(name="A", group=group)
        team.save()

        # Rank will be the number of users who have points plus one.
        overall_rank = 1
        team_rank = 1

        self.assertEqual(
            score_mgr.player_rank(self.user.get_profile(), self.current_round),
            overall_rank, "Check user is last overall for the current round.")
        self.assertEqual(
            score_mgr.player_rank_in_team(self.user.get_profile(),
                                          self.current_round), team_rank,
            "Check user is last in their team for the current "
            "round.")

        user2 = User(username="******", password="******")
        user2.save()

        profile2 = user2.get_profile()
        profile2.add_points(10, datetime.datetime.today(), "test")

        self.assertEqual(
            score_mgr.player_rank(self.user.get_profile(),
                                  self.current_round), overall_rank + 1,
            "Check that the user's overall rank has moved down.")
        self.assertEqual(
            score_mgr.player_rank_in_team(self.user.get_profile(),
                                          self.current_round), team_rank + 1,
            "Check that the user's team rank has moved down.")
示例#3
0
    def testUserOverallRoundRankWithSubmissionDate(self):
        """Tests that the overall rank calculation for a user in a round is
        correct based on submission date."""
        top_entry = ScoreboardEntry.objects.filter(
            round_name=self.current_round).order_by("-points")[0]
        entry, _ = ScoreboardEntry.objects.get_or_create(
            profile=self.user.profile,
            round_name=self.current_round,
            )
        entry.points = top_entry.points + 1
        entry.last_awarded_submission = datetime.datetime.today() - datetime.timedelta(days=3)
        entry.save()

        self.assertEqual(score_mgr.player_rank(self.user.profile,
                                                           self.current_round),
                         1,
                         "Check user is ranked #1 for the current round.")

        user2 = User(username="******", password="******")
        user2.save()

        profile2 = user2.profile
        entry2, _ = ScoreboardEntry.objects.get_or_create(
            profile=profile2,
            round_name=self.current_round,
            )
        entry2.points = entry.points
        entry2.last_awarded_submission = datetime.datetime.today()
        entry2.save()

        self.assertEqual(score_mgr.player_rank(self.user.profile,
                                                           self.current_round),
                         2,
                         "Check user is now second.")
示例#4
0
    def testRoundRankWithoutEntry(self):
        """Tests that the overall rank calculation is correct even if a user
        has not done anything yet."""
        group = Group(name="Test group")
        group.save()
        team = Team(name="A", group=group)
        team.save()

        # Rank will be the number of users who have points plus one.
        overall_rank = 1
        team_rank = 1

        self.assertEqual(score_mgr.player_rank(self.user.profile,
                                                           self.current_round),
                         overall_rank,
                         "Check user is last overall for the current round.")
        self.assertEqual(score_mgr.player_rank_in_team(self.user.profile,
                                                        self.current_round),
                         team_rank,
                         "Check user is last in their team for the current "
                         "round.")

        user2 = User(username="******", password="******")
        user2.save()

        profile2 = user2.profile
        profile2.add_points(10, datetime.datetime.today(), "test")

        self.assertEqual(score_mgr.player_rank(self.user.profile,
                                                           self.current_round),
                         overall_rank + 1,
                         "Check that the user's overall rank has moved down.")
        self.assertEqual(score_mgr.player_rank_in_team(self.user.profile,
                                                        self.current_round),
                         team_rank + 1,
                         "Check that the user's team rank has moved down.")
示例#5
0
 def overall_rank(self):
     """Returns the rank of the user for the round."""
     return score_mgr.player_rank(self)
示例#6
0
 def current_round_overall_rank(self):
     """Returns the overall rank of the user for the current round."""
     current_round = challenge_mgr.get_round_name()
     return score_mgr.player_rank(self, round_name=current_round)
示例#7
0
文件: models.py 项目: csdl/makahiki
 def overall_rank(self):
     """Returns the rank of the user for the round."""
     return score_mgr.player_rank(self)
示例#8
0
文件: models.py 项目: csdl/makahiki
 def current_round_overall_rank(self):
     """Returns the overall rank of the user for the current round."""
     current_round = challenge_mgr.get_round_name()
     return score_mgr.player_rank(self, round_name=current_round)