Пример #1
0
Файл: jhkg.py Проект: neynt/jhkg
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?'
Пример #2
0
Файл: jhkg.py Проект: neynt/jhkg
def contest_data():
    problem = db.get_problem(request.form["problem"])
    if problem:
        grader_name = problem.grader
        data, seed = getattr(problems, grader_name).generate()
        given_data[g.user] = data
        given_seed[g.user] = seed
        given_time[g.user] = g.now
        return data
    else:
        return "I don't know that problem, dude."
Пример #3
0
Файл: jhkg.py Проект: neynt/jhkg
def contest_data():
    problem = db.get_problem(request.form["problem"])
    if problem:
        grader_name = problem.grader
        data, seed = getattr(problems, grader_name).generate()
        given_data[g.user] = data
        given_seed[g.user] = seed
        given_time[g.user] = g.now
        return data
    else:
        return "I don't know that problem, dude."
Пример #4
0
Файл: jhkg.py Проект: neynt/jhkg
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?"