Beispiel #1
0
def by_result_for_contest(pg):
    results = UserResultForContest.objects.select_related('user') \
            .filter(contest=pg.contest, score__isnull=False) \
            .order_by('-score')
    order = []
    prev_score = None
    place = None
    for i, result in enumerate(results, 1):
        if result.score != prev_score:
            place = i
            prev_score = result.score
        order.append((place, result.user))
    assign_from_order(pg, order)
Beispiel #2
0
def by_result_for_contest(pg):
    results = UserResultForContest.objects.select_related('user') \
            .filter(contest=pg.contest, score__isnull=False) \
            .order_by('-score')
    order = []
    prev_score = None
    place = None
    for i, result in enumerate(results, 1):
        if result.score != prev_score:
            place = i
            prev_score = result.score
        order.append((place, result.user))
    assign_from_order(pg, order)
Beispiel #3
0
def _with_conflict(pg):
    users = User.objects.all().order_by('id')[:2]
    assign_from_order(pg, [(1, user) for user in users])
Beispiel #4
0
    def test_assign_from_order(self):
        contest = Contest.objects.get()
        pg = _create_PG(contest=contest, name='PG', key='by_id')

        assign_from_order(pg, [])
        assign_from_order(pg, enumerate(User.objects.all()))
        self.assertFalse(PrizeForUser.objects.exists())

        _create_PR(contest=contest,
                   prize_giving=pg,
                   name='Prize',
                   quantity=2,
                   order=10)

        order = [(nr // 2, u) for nr, u in enumerate(User.objects.all())]
        assign_from_order(pg, order)
        self.assertEqual(2, PrizeForUser.objects.count())

        PrizeForUser.objects.all().delete()

        order = [(1, u) for u in User.objects.all()]
        with self.assertRaises(FairAssignmentNotFound):
            assign_from_order(pg, order)

        _create_PR(contest=contest,
                   prize_giving=pg,
                   name='Prize2',
                   quantity=100,
                   order=11)

        with self.assertRaises(FairAssignmentNotFound):
            assign_from_order(pg, order)

        assign_from_order(pg, enumerate(User.objects.all()[:3]))
        self.assertEqual(3, PrizeForUser.objects.count())
Beispiel #5
0
def _prizes_by_user_id(pg):
    users = User.objects.all().order_by('id')
    assign_from_order(pg, enumerate(users))
Beispiel #6
0
def _with_conflict(pg):
    users = User.objects.all().order_by('id')[:2]
    assign_from_order(pg, [(1, user) for user in users])
Beispiel #7
0
    def test_assign_from_order(self):
        contest = Contest.objects.get()
        pg = _create_PG(contest=contest, name='PG', key='by_id')

        assign_from_order(pg, [])
        assign_from_order(pg, enumerate(User.objects.all()))
        self.assertFalse(PrizeForUser.objects.exists())

        _create_PR(contest=contest, prize_giving=pg, name='Prize',
                   quantity=2, order=10)

        order = [(nr // 2, u) for nr, u in enumerate(User.objects.all())]
        assign_from_order(pg, order)
        self.assertEqual(2, PrizeForUser.objects.count())

        PrizeForUser.objects.all().delete()

        order = [(1, u) for u in User.objects.all()]
        with self.assertRaises(FairAssignmentNotFound):
            assign_from_order(pg, order)

        _create_PR(contest=contest, prize_giving=pg, name='Prize2',
                   quantity=100, order=11)

        with self.assertRaises(FairAssignmentNotFound):
            assign_from_order(pg, order)

        assign_from_order(pg, enumerate(User.objects.all()[:3]))
        self.assertEqual(3, PrizeForUser.objects.count())
Beispiel #8
0
def _prizes_by_user_id(pg):
    users = User.objects.all().order_by('id')
    assign_from_order(pg, enumerate(users))