def testFloorPointsInRound(self): """ Tests calculating the floor points leaders in a round. """ profile = self.users[0].get_profile() profile.add_points(10, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile.save() self.assertEqual(Floor.floor_points_leaders(round_name=self.current_round)[0], profile.floor, "The user's floor is not leading in the prize.") # Test that a user in a different floor but same dorm changes the leader for the original user. profile2 = self.users[2].get_profile() profile2.add_points(profile.points + 1, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile2.save() self.assertEqual(Floor.floor_points_leaders(round_name=self.current_round)[0], profile2.floor, "The user's floor should have changed.") # Test that adding points outside of the round does not affect the leaders. profile.add_points(10, datetime.datetime.today() - datetime.timedelta(days=2), "test") profile.save() self.assertEqual(Floor.floor_points_leaders(round_name=self.current_round)[0], profile2.floor, "The leader of the floor should not change.") # Test that a tie is handled properly. profile.add_points(1, datetime.datetime.today(), "test") profile.save() self.assertEqual(Floor.floor_points_leaders(round_name=self.current_round)[0], profile.floor, "The leader of the floor should have changed back.")
def points_scoreboard(request): profiles = Profile.objects.filter( points__gt=0, ).order_by("-points", "-last_awarded_submission").values("name", "points", 'user__username') canopy_members = Profile.objects.filter( canopy_member=True, ).order_by("-canopy_karma").values("name", "canopy_karma") floor_standings = Floor.floor_points_leaders(num_results=20) # Find referrals. referrals = Profile.objects.filter( referring_user__isnull=False, ).values('referring_user__profile__name', 'referring_user__username').annotate( referrals=Count('referring_user') ) round_individuals = {} round_floors = {} for round_name in settings.COMPETITION_ROUNDS: round_individuals[round_name] = ScoreboardEntry.objects.filter( points__gt=0, round_name=round_name, ).order_by("-points", "-last_awarded_submission").values("profile__name", "points", 'profile__user__username') round_floors[round_name] = Floor.floor_points_leaders( num_results=20, round_name=round_name ) # Calculate active participation. floor_participation = Floor.objects.filter(profile__points__gte=50).annotate( user_count=Count('profile'), ).order_by('-user_count').select_related('dorm') for floor in floor_participation: floor.active_participation = (floor.user_count * 100) / floor.profile_set.count() return render_to_response("status/points.html", { "profiles": profiles, "canopy_members": canopy_members, "round_individuals": round_individuals, "floor_standings": floor_standings, "round_floors": round_floors, "floor_participation": floor_participation, "referrals": referrals, }, context_instance=RequestContext(request))
def testFloorPointsInRound(self): """ Tests calculating the floor points leaders in a round. """ profile = self.users[0].get_profile() profile.add_points( 10, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile.save() self.assertEqual( Floor.floor_points_leaders(round_name=self.current_round)[0], profile.floor, "The user's floor is not leading in the prize.") # Test that a user in a different floor but same dorm changes the leader for the original user. profile2 = self.users[2].get_profile() profile2.add_points( profile.points + 1, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile2.save() self.assertEqual( Floor.floor_points_leaders(round_name=self.current_round)[0], profile2.floor, "The user's floor should have changed.") # Test that adding points outside of the round does not affect the leaders. profile.add_points( 10, datetime.datetime.today() - datetime.timedelta(days=2), "test") profile.save() self.assertEqual( Floor.floor_points_leaders(round_name=self.current_round)[0], profile2.floor, "The leader of the floor should not change.") # Test that a tie is handled properly. profile.add_points(1, datetime.datetime.today(), "test") profile.save() self.assertEqual( Floor.floor_points_leaders(round_name=self.current_round)[0], profile.floor, "The leader of the floor should have changed back.")
def _points_leader(self, floor=None): round_name = None if self.round_name == "Overall" else self.round_name if self.award_to == "individual_overall": return Profile.points_leaders(num_results=1, round_name=round_name)[0] elif self.award_to == "floor_dorm": return floor.dorm.floor_points_leaders(num_results=1, round_name=round_name)[0] elif self.award_to == "floor_overall": return Floor.floor_points_leaders(num_results=1, round_name=round_name)[0] elif self.award_to == "individual_floor": return floor.points_leaders(num_results=1, round_name=round_name)[0] raise Exception("Not implemented yet.")
def _points_leader(self, floor=None): round_name = None if self.round_name == "Overall" else self.round_name if self.award_to == "individual_overall": return Profile.points_leaders(num_results=1, round_name=round_name)[0] elif self.award_to == "floor_dorm": return floor.dorm.floor_points_leaders(num_results=1, round_name=round_name)[0] elif self.award_to == "floor_overall": return Floor.floor_points_leaders(num_results=1, round_name=round_name)[0] elif self.award_to == "individual_floor": if floor: return floor.points_leaders(num_results=1, round_name=round_name)[0] return None raise Exception("'%s' is not implemented yet." % self.award_to)