Esempio n. 1
0
  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(Profile.points_leaders()[0], 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(Profile.points_leaders()[0], 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(Profile.points_leaders()[0], profile2, 
        "User 2 should still be the leading profile.")
Esempio n. 2
0
    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(Profile.points_leaders()[0], 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(Profile.points_leaders()[0], 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(Profile.points_leaders()[0], profile2,
                         "User 2 should still be the leading profile.")
Esempio n. 3
0
    def testLeadersInRound(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))
        profile.save()

        self.assertEqual(
            Profile.points_leaders(round_name=self.current_round)[0], 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())
        profile2.save()

        self.assertEqual(
            Profile.points_leaders(round_name=self.current_round)[0], 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))
        profile3.save()

        self.assertEqual(
            Profile.points_leaders(round_name=self.current_round)[0],
            profile2,
            "User 2 should still be the leading profile.",
        )

        # Have the first user earn more points outside of the round.
        profile.add_points(2, datetime.datetime.today() - datetime.timedelta(days=2))
        profile.save()

        self.assertEqual(
            Profile.points_leaders(round_name=self.current_round)[0],
            profile2,
            "User 2 should still be the leading profile.",
        )
Esempio n. 4
0
 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.")
Esempio n. 5
0
    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)
Esempio n. 6
0
 def __generate_prize_forms(self, round_dir, round_name):
   prizes = Prize.objects.filter(
       Q(award_to='individual_floor') | Q(award_to='individual_overall'),
       round_name=round_name,
   )
   
   round_name = round_name if round_name != 'Overall' else None
   # Need to calculate winners for each prize.
   for prize in prizes:
     if prize.award_to == 'individual_floor':
       # Need to calculate floor winners for each floor.
       for floor in Floor.objects.all():
         leader = floor.points_leaders(1, round_name)[0].user
         prize.winner = leader
         contents = render_to_string('view_prizes/form.txt', {
             'raffle': False,
             'prize':  prize,
             'round': round_name,
         })
         
         filename = '%s-%s-%s.txt' % (floor.dorm.name, floor.number, leader.username)
         f = open('%s/%s' % (round_dir, filename), 'w')
         f.write(contents)
         
     else:
       leader = Profile.points_leaders(1, round_name)[0].user
       prize.winner = leader
       contents = render_to_string('view_prizes/form.txt', {
           'raffle': False,
           'prize':  prize,
           'round': round_name,
       })
       
       filename = 'overall-%s.txt' % leader.username
       f = open('%s/%s' % (round_dir, filename), 'w')
       f.write(contents)
       
Esempio n. 7
0
    def __generate_prize_forms(self, round_dir, round_name):
        prizes = Prize.objects.filter(
            Q(award_to='individual_floor') | Q(award_to='individual_overall'),
            round_name=round_name,
        )

        round_name = round_name if round_name != 'Overall' else None
        # Need to calculate winners for each prize.
        for prize in prizes:
            if prize.award_to == 'individual_floor':
                # Need to calculate floor winners for each floor.
                for floor in Floor.objects.all():
                    leader = floor.points_leaders(1, round_name)[0].user
                    prize.winner = leader
                    contents = render_to_string('view_prizes/form.txt', {
                        'raffle': False,
                        'prize': prize,
                        'round': round_name,
                    })

                    filename = '%s-%s-%s.txt' % (floor.dorm.name, floor.number,
                                                 leader.username)
                    f = open('%s/%s' % (round_dir, filename), 'w')
                    f.write(contents)

            else:
                leader = Profile.points_leaders(1, round_name)[0].user
                prize.winner = leader
                contents = render_to_string('view_prizes/form.txt', {
                    'raffle': False,
                    'prize': prize,
                    'round': round_name,
                })

                filename = 'overall-%s.txt' % leader.username
                f = open('%s/%s' % (round_dir, filename), 'w')
                f.write(contents)