def testLeadersOverall(self): """ Test that we can retrieve the leaders in a given round. """ # Test one user profile = self.users[0].profile profile.add_points(10, datetime.datetime.today() - datetime.timedelta(minutes=1), "Test") profile.save() self.assertEqual(player_mgr.points_leader(), profile, "Current leader is not the leading user.") # Have another user move ahead in points profile2 = self.users[1].profile profile2.add_points(profile.points() + 1, datetime.datetime.today(), "Test") profile2.save() self.assertEqual(player_mgr.points_leader(), profile2, "User 2 should be the leading profile.") # Have this user get the same amount of points, # but an earlier award date. profile3 = self.users[2].profile profile3.add_points(profile2.points(), datetime.datetime.today() - datetime.timedelta(minutes=1), "Test") profile3.save() self.assertEqual(player_mgr.points_leader(), profile2, "User 2 should still be the leading profile.")
def testLeadersOverall(self): """ Test that we can retrieve the leaders in a given round. """ # Test one user profile = self.users[0].get_profile() profile.add_points( 10, datetime.datetime.today() - datetime.timedelta(minutes=1), "Test") profile.save() self.assertEqual(player_mgr.points_leader(), profile, "Current leader is not the leading user.") # Have another user move ahead in points profile2 = self.users[1].get_profile() profile2.add_points(profile.points() + 1, datetime.datetime.today(), "Test") profile2.save() self.assertEqual(player_mgr.points_leader(), profile2, "User 2 should be the leading profile.") # Have this user get the same amount of points, # but an earlier award date. profile3 = self.users[2].get_profile() profile3.add_points( profile2.points(), datetime.datetime.today() - datetime.timedelta(minutes=1), "Test") profile3.save() self.assertEqual(player_mgr.points_leader(), profile2, "User 2 should still be the leading profile.")
def _points_leader(self, team=None, place=1): """Return the point leader.""" if self.round == None: round_name = "Round 1" else: round_name = self.round.name leader = None if self.award_to == "individual_overall": leader = player_mgr.points_leader(round_name=round_name, place=place) elif self.award_to == "team_group": if team: leaders = team.group.team_points_leaders(num_results=place, round_name=round_name) if len(leaders) >= place: leader = leaders[place - 1] elif self.award_to == "team_overall": leader = team_mgr.team_points_leader(round_name=round_name, place=place) elif self.award_to == "group": leader = team_mgr.group_points_leader(round_name=round_name, place=place) elif self.award_to == "individual_team": if team: leaders = team.points_leaders(num_results=place, round_name=round_name) if len(leaders) >= place: leader = leaders[place - 1] else: raise Exception("'%s' is not implemented yet." % self.award_to) return leader
def testOverallRankForCurrentRound(self): """Test that we can retrieve the rank for the user in the current round.""" test_utils.set_competition_round() user = User(username="******", password="******") user.save() profile = user.profile top_user = player_mgr.points_leader() profile.add_points(top_user.points() + 1, datetime.datetime.today(), "Test") profile.save() self.assertEqual(profile.current_round_overall_rank(), 1, "Check that the user is number 1.") user2 = User(username="******", password="******") user2.save() profile2 = user2.profile profile2.add_points(profile.points() + 1, datetime.datetime.today(), "Test") profile2.save() self.assertEqual(profile.current_round_overall_rank(), 2, "Check that the user is now number 2.")
def testTeamRankWithSubmissionDate(self): """Tests that the team_rank method accurately computes the rank when users have the same number of points,""" user = User(username="******", password="******") user.save() group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() profile = user.profile profile.team = team top_user = player_mgr.points_leader() profile.add_points(top_user.points() + 1, datetime.datetime.today() - datetime.timedelta(minutes=1), "Test") profile.save() self.assertEqual(profile.team_rank(), 1, "Check that the user is number 1.") user2 = User(username="******", password="******") user2.save() profile2 = user2.profile profile2.add_points(profile.points(), datetime.datetime.today(), "Test") profile2.save() profile2.team = team profile2.save() self.assertEqual(profile.team_rank(), 2, "Check that the user is now rank 2.")
def testOverallRankForCurrentRound(self): """Test that we can retrieve the rank for the user in the current round.""" test_utils.set_competition_round() user = User(username="******", password="******") user.save() profile = user.get_profile() top_user = player_mgr.points_leader() profile.add_points(top_user.points() + 1, datetime.datetime.today(), "Test") profile.save() self.assertEqual(profile.current_round_overall_rank(), 1, "Check that the user is number 1.") user2 = User(username="******", password="******") user2.save() profile2 = user2.get_profile() profile2.add_points(profile.points() + 1, datetime.datetime.today(), "Test") profile2.save() self.assertEqual(profile.current_round_overall_rank(), 2, "Check that the user is now number 2.")
def testTeamRankWithSubmissionDate(self): """Tests that the team_rank method accurately computes the rank when users have the same number of points,""" user = User(username="******", password="******") user.save() group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() profile = user.get_profile() profile.team = team top_user = player_mgr.points_leader() profile.add_points( top_user.points() + 1, datetime.datetime.today() - datetime.timedelta(minutes=1), "Test") profile.save() self.assertEqual(profile.team_rank(), 1, "Check that the user is number 1.") user2 = User(username="******", password="******") user2.save() profile2 = user2.get_profile() profile2.add_points(profile.points(), datetime.datetime.today(), "Test") profile2.save() profile2.team = team profile2.save() self.assertEqual(profile.team_rank(), 2, "Check that the user is now rank 2.")
def _points_leader(self, team=None): """Return the point leader.""" if self.round == None: round_name = "Round 1" else: round_name = self.round.name if self.award_to == "individual_overall": return player_mgr.points_leader(round_name=round_name) elif self.award_to == "team_group": if team: leaders = team.group.team_points_leaders(num_results=1, round_name=round_name) if leaders: return leaders[0] return None elif self.award_to == "team_overall": return team_mgr.team_points_leader(round_name=round_name) elif self.award_to == "individual_team": if team: leaders = team.points_leaders(num_results=1, round_name=round_name) if leaders: return leaders[0] return None elif self.award_to == "group_overall": return score_mgr.group_points_leader() raise Exception("'%s' is not implemented yet." % self.award_to)
def _points_leader(self, team=None): """Return the point leader.""" if self.round == None: round_name = "Round 1" else: round_name = self.round.name leader = None if self.award_to == "individual_overall": leader = player_mgr.points_leader(round_name=round_name) elif self.award_to == "team_group": if team: leaders = team.group.team_points_leaders(num_results=1, round_name=round_name) if leaders: leader = leaders[0] elif self.award_to == "team_overall": leader = team_mgr.team_points_leader(round_name=round_name) elif self.award_to == "group": leader = team_mgr.group_points_leader(round_name=round_name) elif self.award_to == "individual_team": if team: leaders = team.points_leaders(num_results=1, round_name=round_name) if leaders: leader = leaders[0] else: raise Exception("'%s' is not implemented yet." % self.award_to) return leader