Beispiel #1
0
def public_rank_create_frozen(contest, all_submit):
    for user in contest.user.all():
        if not all_submit.filter(user=user):
            continue
        try:
            rank_cache = RankcachePublic.objects.get(contest=contest,
                                                     user=user)
            rank_cache.point = 0
            rank_cache.punish_time = 0
            rank_cache.save()
        except RankcachePublic.DoesNotExist:
            rank_cache = RankcachePublic(contest=contest, user=user)
            rank_cache.save()
        for problem in contest.problem.all():
            submit = all_submit.filter(user=user,
                                       problem=problem).order_by('submit_time')
            if not submit:
                continue
            try:
                score_cache = ScorecachePublic.objects.get(
                    rank_cache=rank_cache, problem=problem)
                score_cache.submission = 0
                score_cache.punish = 0
                score_cache.pending = 0
                score_cache.is_correct = False
                score_cache.correct_submit_time = None
                score_cache.save()
            except ScorecachePublic.DoesNotExist:
                score_cache = ScorecachePublic(rank_cache=rank_cache,
                                               problem=problem)
                score_cache.save()

            for sub in submit:
                score_cache.submission += 1
                if contest.frozen_time <= sub.submit_time and sub.submit_time < contest.unfrozen_time:
                    score_cache.pending += 1
                elif sub.result == "Correct":
                    score_cache.is_correct = True
                    score_cache.correct_submit_time = sub.submit_time
                    rank_cache.point = float(rank_cache.point) + float(
                        problem.point)
                    try:
                        punish_value = Setting.objects.get(
                            name="punish time").value
                        rank_cache.punish_time += punish_value * score_cache.punish + \
                            time_gap(score_cache.correct_submit_time,
                                     contest.start_time)
                    except Setting.DoesNotExist:
                        rank_cache.punish_time += 20 * score_cache.punish
                    rank_cache.save()
                    break
                elif sub.result == "Compiler Error":
                    pass
                else:
                    score_cache.punish += 1
            score_cache.save()
Beispiel #2
0
def rank_update(submit):
    if not submit.user.role.short_name == "contestant":
        return
    if not submit.result:
        return
    if submit.submit_time < submit.contest.start_time:
        return
    if submit.submit_time >= submit.contest.end_time:
        return
    pro = submit.problem
    contest = submit.contest
    this_problem_prevous_correct_submit = Submit.objects.filter(
        contest=contest,
        problem=pro,
        result='Correct',
        submit_time__lte=submit.submit_time,
        user=submit.user).exclude(pk=submit.pk)
    if this_problem_prevous_correct_submit:
        return

    try:
        rank_cache = RankcacheJury.objects.get(user=submit.user,
                                               contest=contest)
    except RankcacheJury.DoesNotExist:
        rank_cache = RankcacheJury(user=submit.user, contest=contest)
        rank_cache.save()

    try:
        rank_cache_public = RankcachePublic.objects.get(user=submit.user,
                                                        contest=contest)
    except RankcachePublic.DoesNotExist:
        rank_cache_public = RankcachePublic(user=submit.user, contest=contest)
        rank_cache_public.save()

    try:
        score_cache = ScorecacheJury.objects.get(rank_cache=rank_cache,
                                                 problem=pro)
    except ScorecacheJury.DoesNotExist:
        score_cache = ScorecacheJury(rank_cache=rank_cache, problem=pro)
        score_cache.save()

    try:
        score_cache_public = ScorecachePublic.objects.get(
            rank_cache=rank_cache_public, problem=pro)
    except ScorecachePublic.DoesNotExist:
        score_cache_public = ScorecachePublic(rank_cache=rank_cache_public,
                                              problem=pro)
        score_cache_public.save()

    if score_cache.is_correct:
        return
    score_cache.submission += 1
    if submit.result == "Correct":
        score_cache.is_correct = True
        score_cache.correct_submit_time = submit.submit_time
    elif submit.result == "Compiler Error":
        pass
    else:
        score_cache.punish += 1
    score_cache.save()

    if submit.result == "Correct":
        punish_value, rating_correct_value, rating_punish_value = setting_values(
        )
        rank_cache.point = (float(rank_cache.point) + float(pro.point))
        rank_cache.punish_time += punish_value * score_cache.punish + \
           time_gap(score_cache.correct_submit_time, contest.start_time)
        rank_cache.save()
        if contest.has_value:  # rating update
            user = submit.user
            user.rating += (rating_correct_value -
                            rating_punish_value * score_cache.punish)
            user.save()

    if contest.frozen_time and contest.unfrozen_time and contest.frozen_time <= submit.submit_time and submit.submit_time < contest.unfrozen_time:
        score_cache_public.submission += 1
        score_cache_public.pending += 1
        score_cache_public.save()
    else:
        rank_cache_public.point = rank_cache.point
        rank_cache_public.punish_time = rank_cache.punish_time
        rank_cache_public.save()

        score_cache_public.submission = score_cache.submission
        score_cache_public.punish = score_cache.punish
        score_cache_public.correct_submit_time = score_cache.correct_submit_time
        score_cache_public.is_correct = score_cache.is_correct
        score_cache_public.save()

    score_cache_public.judging -= 1
    score_cache_public.save()
    score_cache.judging -= 1
    score_cache.save()

    this_contest = submit.contest
    this_contest.last_update = timezone.now()
    this_contest.save()
Beispiel #3
0
def rank_update_unfrozen(contest):
    total_rank_cache = RankcacheJury.objects.filter(contest=contest)
    for jury_rank in total_rank_cache:
        try:
            public_rank_cache = RankcachePublic.objects.get(
                user=jury_rank.user, contest=jury_rank.contest)
        except RankcachePublic.DoesNotExist:
            public_rank_cache = RankcachePublic(user=jury_rank.user,
                                                contest=jury_rank.contest)
            public_rank_cache.save()
        public_rank_cache.point = jury_rank.point
        public_rank_cache.punish_time = jury_rank.punish_time
        public_rank_cache.save()
        total_score_cache = ScorecacheJury.objects.filter(rank_cache=jury_rank)
        for jury_score in total_score_cache:
            try:
                public_score_cache = ScorecachePublic.objects.get(
                    rank_cache=public_rank_cache, problem=jury_score.problem)
            except ScorecachePublic.DoesNotExist:
                public_score_cache = ScorecachePublic(
                    rank_cache=public_rank_cache, problem=jury_score.problem)
                public_score_cache.save()
            public_score_cache.submission = jury_score.submission
            public_score_cache.punish = jury_score.punish
            public_score_cache.correct_submit_time = jury_score.correct_submit_time
            public_score_cache.is_correct = jury_score.is_correct
            public_score_cache.pending = 0
            public_score_cache.save()
Beispiel #4
0
def update_score_and_rank(submit):
    point = submit.problem.point
    contest = submit.contest

    rank_cache_jury = RankcacheJury.objects.get(user=submit.user,
                                                contest=contest)
    rank_cache_public = RankcachePublic.objects.get(user=submit.user,
                                                    contest=contest)
    try:
        score_cache_jury = ScorecacheJury.objects.get(
            rank_cache=rank_cache_jury, problem=submit.problem)
    except ScorecacheJury.DoesNotExist:
        score_cache_jury = ScorecacheJury(rank_cache=rank_cache_jury,
                                          problem=submit.problem)
        score_cache_jury.save()

    try:
        score_cache_public = ScorecachePublic.objects.get(
            rank_cache=rank_cache_public, problem=submit.problem)
    except ScorecachePublic.DoesNotExist:
        score_cache_public = ScorecachePublic(rank_cache=rank_cache_public,
                                              problem=submit.problem)
        score_cache_public.save()

    punish_value, rating_correct_value, rating_punish_value = setting_values()
    if score_cache_jury.is_correct:
        rank_cache_jury.point -= point
        rank_cache_jury.punish_time -= (
            punish_value * score_cache_jury.punish +
            time_gap(score_cache_jury.correct_submit_time, contest.start_time))
        rank_cache_jury.save()
        if contest.has_value:  # rating update
            user = submit.user
            user.rating -= (rating_correct_value -
                            rating_punish_value * score_cache_jury.punish)
            user.save()

    score_cache_jury.is_correct = False
    score_cache_jury.punish = 0
    score_cache_jury.submission = 0
    score_cache_jury.correct_submit_time = None
    score_cache_jury.save()

    if score_cache_public.is_correct:
        rank_cache_public.point -= point
        rank_cache_public.punish_time -= (
            punish_value * score_cache_public.punish + time_gap(
                score_cache_public.correct_submit_time, contest.start_time))
        rank_cache_public.save()

    score_cache_public.is_correct = False
    score_cache_public.punish = 0
    score_cache_public.submission = 0
    score_cache_public.correct_submit_time = None
    score_cache_public.pending = 0
    score_cache_public.save()

    # all_submit = Submit.objects.filter(user=submit.user, problem=submit.problem, contest=contest, submit_time__gte=contest.start_time,
    #                                  submit_time__lte=contest.end_time).exclude(result="Judging").order_by('submit_time')
    all_submit = Submit.objects.filter(
        user=submit.user,
        problem=submit.problem,
        contest=contest,
        submit_time__gte=contest.start_time,
        submit_time__lte=contest.end_time).order_by('submit_time')

    for sub in all_submit:
        score_cache_jury.submission += 1
        if sub.result == "Correct":
            score_cache_jury.correct_submit_time = sub.submit_time
            score_cache_jury.is_correct = True
            rank_cache_jury.point += point
            rank_cache_jury.punish_time += (
                punish_value * score_cache_jury.punish + time_gap(
                    score_cache_jury.correct_submit_time, contest.start_time))
            rank_cache_jury.save()
            break
        elif not sub.result == "Compiler Error":
            score_cache_jury.punish += 1
    score_cache_jury.save()

    for sub in all_submit:
        if contest.frozen_time and contest.unfrozen_time and contest.frozen_time <= sub.submit_time and sub.submit_time < contest.unfrozen_time:
            score_cache_public.submission += 1
            score_cache_public.pending += 1
            score_cache_public.save()
        else:
            rank_cache_public.point = rank_cache_jury.point
            rank_cache_public.punish_time = rank_cache_jury.punish_time
            rank_cache_public.save()

            score_cache_public.submission = score_cache_jury.submission
            score_cache_public.punish = score_cache_jury.punish
            score_cache_public.correct_submit_time = score_cache_jury.correct_submit_time
            score_cache_public.is_correct = score_cache_jury.is_correct
            score_cache_public.save()

    if contest.has_value and score_cache_jury.is_correct:  # rating update
        user = submit.user
        user.rating += (rating_correct_value -
                        rating_punish_value * score_cache_jury.punish)
        user.save()