Esempio n. 1
0
def autoreward_lesson(lesson):
    if not lesson.contest_id:
        return
    upsolving = is_upsolving(lesson.contest_id)
    rules = [Rule(upsolving, rule) for rule in lesson.autorewards.split("\n")]
    runs = run_contests_cmd(lesson.contest_id, "dump-filtered-runs",
                            "status==OK", "0", "-1").split('\n')
    for s in runs:
        if not s:
            continue
        info = s.split(';')
        user_id, prob = int(info[10]), info[18]
        if not Autoreward.objects.filter(
                user__id=user_id, prob=prob, lesson=lesson).exists():
            score = 0
            for rule in rules:
                if rule.appliable(prob):
                    score += rule.score
                    if not rule.add:
                        break
            r = Autoreward()
            r.user = EjudgeAuthBackend().get_user(user_id)
            r.prob = prob
            r.lesson = lesson
            r.save()
            if score > 0:
                r.user.bonuses += score
                r.user.save()
                lesson.bank.bonuses -= score
                tr = Transaction()
                tr.sender = lesson.bank
                tr.receiver = r.user
                tr.amount = score
                tr.save()
    lesson.bank.save()
Esempio n. 2
0
def add_bonuses(modeladmin, request, queryset):
    bonuses = int(request.POST['bonuses'])
    for user in queryset:
        user.bonuses += bonuses
        user.save()
        tr = Transaction()
        tr.receiver = user
        tr.amount = bonuses
        tr.save()
Esempio n. 3
0
def make_declined(modeladmin, request, queryset):
    for purchase in queryset.all():
        purchase.user.bonuses += purchase.prize.cost
        purchase.user.save()
        purchase.prize.stock += 1
        purchase.prize.save()
        purchase.status = Purchase.DECLINED
        purchase.save()
        tr = Transaction()
        tr.receiver = purchase.user
        tr.amount = purchase.prize.cost
        tr.save()
Esempio n. 4
0
def close_casino(finalize=True):
    for group in Group.objects.all():
        if group.casino_contest:
            if finalize:
                finalize_casino(group)
            with open(os.path.join(MEDIA_ROOT, 'casino_%d.html' % group.id),
                      "w") as f:
                f.write(render_casino(group))
    for session in CasinoSession.objects.all():
        if session.won:
            tr = Transaction()
            tr.receiver = session.user
            tr.amount = session.won
            tr.save()
            session.user.bonuses += session.won
            session.user.save()
    for group in Group.objects.all():
        if group.casino_contest:
            reset_contest(casino_contest)
    CasinoSession.objects.all().delete()