Example #1
0
def approve_set_result(request, set_result_id):
    sr = SetResult.objects.filter(pk=set_result_id).first()
    if not sr:
        return HttpResponseBadRequest('Match with id {} does not exist'.format(set_result_id))

    user_id = request.user.pk
    if sr.player1.pk != user_id and sr.player2.pk != user_id:
        return HttpResponseBadRequest('You are not the participant of the match {}'.format(set_result_id))

    if sr.is_approved:
        return HttpResponseBadRequest('Match already approved')

    with transaction.atomic():
        if sr.player1.pk == user_id:
            sr.player1_approved = True
        elif sr.player2.pk == user_id:
            sr.player2_approved = True

        sr.save()

        if sr.is_approved:
            rating_changes = calculate_rating_changes(sr)
            update_rating(rating_changes)

    if sr.group:
        return HttpResponseRedirect(reverse('app-tournament', args=[sr.group.tournament.pk]))
    else:
        return HttpResponseRedirect(reverse('rating-list'))
Example #2
0
def approve_set_result(request, set_result_id):
    sr = SetResult.objects.filter(pk=set_result_id).first()
    if not sr:
        return HttpResponseBadRequest(
            'Match with id {} does not exist'.format(set_result_id))

    user_id = request.user.pk
    if sr.player1.pk != user_id and sr.player2.pk != user_id:
        return HttpResponseBadRequest(
            'You are not the participant of the match {}'.format(
                set_result_id))

    if sr.is_approved:
        return HttpResponseBadRequest('Match already approved')

    with transaction.atomic():
        if sr.player1.pk == user_id:
            sr.player1_approved = True
        elif sr.player2.pk == user_id:
            sr.player2_approved = True

        sr.save()

        if sr.is_approved:
            rating_changes = calculate_rating_changes(sr)
            update_rating(rating_changes)

    if sr.group:
        return HttpResponseRedirect(
            reverse('app-tournament', args=[sr.group.tournament.pk]))
    else:
        return HttpResponseRedirect(reverse('rating-list'))
Example #3
0
    def recalculate(self):
        q = SetResult.objects.select_related("player1", "player2").order_by("created_at")

        for match in q.all():
            if not match.is_approved:
                continue

            rating_change = calculate_rating_changes(match)
            logger.info(
                "Change after match on {when} between {winner} and {looser}. "
                "{winner} gets {delta} and now {winner_rating}. {looser} looses {delta} and now {looser_rating}".format(
                    winner=rating_change.winner.username,
                    looser=rating_change.looser.username,
                    when=rating_change.when_changed,
                    delta=rating_change.delta,
                    winner_rating=rating_change.new_winner_rating.rating,
                    looser_rating=rating_change.new_looser_rating.rating,
                )
            )
            update_rating(rating_change)
Example #4
0
    def recalculate(self):
        q = SetResult.objects.select_related('player1',
                                             'player2').order_by('created_at')

        for match in q.all():
            if not match.is_approved:
                continue

            rating_change = calculate_rating_changes(match)
            logger.info(
                'Change after match on {when} between {winner} and {looser}. '
                '{winner} gets {delta} and now {winner_rating}. {looser} looses {delta} and now {looser_rating}'
                .format(
                    winner=rating_change.winner.username,
                    looser=rating_change.looser.username,
                    when=rating_change.when_changed,
                    delta=rating_change.delta,
                    winner_rating=rating_change.new_winner_rating.rating,
                    looser_rating=rating_change.new_looser_rating.rating,
                ))
            update_rating(rating_change)