Beispiel #1
0
def contest_submission():
    problem_name = request.form["problem"]
    submission = request.form["submission"]
    problem = db.get_problem(problem_name)
    if problem:
        problem_name = problem.grader
        gr_func = getattr(problems, problem_name).verify
        base_score = gr_func(given_data[g.user], given_seed[g.user],
                             submission)
        if base_score:
            # They were right!
            # Add bonus points for time
            contest = db.get_contest(problem.contest)
            if g.now < contest.start_time + contest.duration:
                # Contest is still ongoing; give them points!
                time_elapsed = g.now - contest.start_time
                time_bonus = round(100 - 100 *
                                   (time_elapsed.total_seconds() /
                                    contest.duration.total_seconds()))
                db.set_score(g.user, problem.uid, base_score + time_bonus)
                return 'Well done. You got %d points and a time bonus of %d!' % (
                    base_score, time_bonus)
            else:
                return 'Well done. This contest is over, but you would have gotten %d points!' % base_score
        else:
            return 'Incorrect. Keep trying!'
    else:
        return 'What exactly are you trying to do?'
Beispiel #2
0
def show_contest(contest_name):
    contest = db.get_contest(contest_name)
    if contest:
        problems = db.get_contest_problems(contest_name)
        if g.user:
            user_solved = {p.name: db.get_score(g.user, p.name) for p in problems}
        else:
            user_solved = {}
        end_time = contest.start_time + contest.duration
        return my_render_template(
            "contest.html",
            contest=contest,
            problems=[(i + 1, p) for i, p in enumerate(problems)],
            user_solved=user_solved,
            end_time=end_time,
        )
    else:
        return page_not_found()
Beispiel #3
0
def show_contest(contest_name):
    contest = db.get_contest(contest_name)
    if contest:
        problems = db.get_contest_problems(contest_name)
        if g.user:
            user_solved = {
                p.name: db.get_score(g.user, p.name)
                for p in problems
            }
        else:
            user_solved = {}
        end_time = contest.start_time + contest.duration
        return my_render_template('contest.html',
                                  contest=contest,
                                  problems=[(i + 1, p)
                                            for i, p in enumerate(problems)],
                                  user_solved=user_solved,
                                  end_time=end_time)
    else:
        return page_not_found()
Beispiel #4
0
def contest_submission():
    problem_name = request.form["problem"]
    submission = request.form["submission"]
    problem = db.get_problem(problem_name)
    if problem:
        problem_name = problem.grader
        gr_func = getattr(problems, problem_name).verify
        base_score = gr_func(given_data[g.user], given_seed[g.user], submission)
        if base_score:
            # They were right!
            # Add bonus points for time
            contest = db.get_contest(problem.contest)
            if g.now < contest.start_time + contest.duration:
                # Contest is still ongoing; give them points!
                time_elapsed = g.now - contest.start_time
                time_bonus = round(100 - 100 * (time_elapsed.total_seconds() / contest.duration.total_seconds()))
                db.set_score(g.user, problem.uid, base_score + time_bonus)
                return "Well done. You got %d points and a time bonus of %d!" % (base_score, time_bonus)
            else:
                return "Well done. This contest is over, but you would have gotten %d points!" % base_score
        else:
            return "Incorrect. Keep trying!"
    else:
        return "What exactly are you trying to do?"