Skip to content

Commit

Permalink
updated how bonus tasks work
Browse files Browse the repository at this point in the history
  • Loading branch information
Giantpizzahead committed Aug 7, 2020
1 parent 8974843 commit fc602c0
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 77 deletions.
11 changes: 9 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,16 @@ def _get_problem_info(problem_id):
problem_statement = change_md_to_html('{}/{}/statement.md'.format(PROBLEM_INFO_PATH, problem_id),
'<p>No problem statement available.</p>')

# Get bonus (if there is any)
bonus = change_md_to_html('{}/{}/bonus.md'.format(PROBLEM_INFO_PATH, problem_id), 'No bonus available.')

# Get hints (if there are any)
hints = change_md_to_html('{}/{}/hints.md'.format(PROBLEM_INFO_PATH, problem_id), 'No hints available.')

# Return only the info that the client needs to know about the problem
return {'id': pinfo['problem_id'], 'name': pinfo['problem_name'], 'time_limit': pinfo['time_limit'],
'memory_limit': pinfo['memory_limit'], 'max_score': pinfo['max_score'],
'statement': problem_statement, 'hints': hints,
'statement': problem_statement, 'bonus': bonus, 'hints': hints,
'difficulty': pinfo['difficulty'] if 'difficulty' in pinfo else ''}


Expand Down Expand Up @@ -236,6 +239,10 @@ def handle_submission():
code_filename, code_extension = os.path.splitext(sec_filename)
if request.form['type'] == 'java' and code_extension != '.java':
return json_error('Missing .java file extension!')
elif request.form['type'] == 'cpp' and code_extension != '.cpp':
return json_error('Missing .cpp file extension!')
elif request.form['type'] == 'python' and code_extension != '.py':
return json_error('Missing .py file extension!')

# Make a temporary directory / save files there
tempdir = tempfile.mkdtemp(prefix='judge-')
Expand Down Expand Up @@ -276,7 +283,7 @@ def _get_status(job_id):
elif job.is_failed:
return {'status': 'internal_error', 'error': 'JOB_FAILED', 'job_id': job_id}, 200
else:
return job.meta, 202
return job.meta, 202 if job.meta['status'] != 'done' else 200


if __name__ == "__main__":
Expand Down
26 changes: 16 additions & 10 deletions judge_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,12 @@ def run_subtask(isolate_dir, problem_info, problem_folder, subtask_info, compile
max_time = max(run_verdict['time'], max_time)
max_memory = max(run_verdict['memory'], max_memory)

# Update job meta, but don't reveal any bonus verdicts
# Update job meta
if problem_info['scoring_method'] in ['average', 'average_stop']:
job.meta['score'][subtask_i] = score_sum / len(test_inputs) * subtask_info['score']
if run_verdict['verdict'] == 'AC' or 'is_bonus' not in subtask_info or not subtask_info['is_bonus']:
job.meta['subtasks'][subtask_i][test_i][0] = run_verdict['verdict']
job.meta['subtasks'][subtask_i][test_i][1] = run_verdict['time']
job.meta['subtasks'][subtask_i][test_i][2] = run_verdict['memory']
else:
job.meta['subtasks'][subtask_i][test_i][0] = 'SK'
job.meta['subtasks'][subtask_i][test_i][0] = run_verdict['verdict']
job.meta['subtasks'][subtask_i][test_i][1] = run_verdict['time']
job.meta['subtasks'][subtask_i][test_i][2] = run_verdict['memory']
job.save_meta()

# If first wrong answer, track results
Expand Down Expand Up @@ -472,12 +469,15 @@ def judge_submission(tempdir, problem_id, code_filename, code_type, username):
curr_testcase += testcase_count

# Do some final cleanup
final_score = round(final_score, 2)
final_score = round(final_score)
if testcase == -1:
testcase = curr_testcase
if final_score > problem_info['max_score']:
# AC* :O
final_verdict = 'AC*'
job.meta['status'] = 'done'
job.meta['final_score'] = final_score
job.save_meta()

# Add submission result to Redis database
with open(isolate_dir + '/' + code_filename, 'r') as fcode:
Expand All @@ -487,8 +487,14 @@ def judge_submission(tempdir, problem_id, code_filename, code_type, username):
# Send POST request to webhook URL
if WEBHOOK_URL is not None:
try:
requests.post(WEBHOOK_URL, data={'problem_id': problem_info['problem_id'], 'username': username,
'score': final_score, 'job_id': job.get_id()}, timeout=10)
if DEBUG_LOW:
log('Sending POST request to ' + WEBHOOK_URL)
req = requests.post(WEBHOOK_URL, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'},
data={'problem_id': problem_info['problem_id'], 'username': username,
'score': final_score, 'job_id': job.get_id(),
'secret_key': SECRET_KEY}, timeout=10)
if DEBUG_LOW:
log('Response code: ' + str(req))
except Exception as e:
return verdict_error('WEBHOOK_FAIL')

Expand Down
11 changes: 2 additions & 9 deletions misc/redis.conf
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,6 @@ always-show-logo yes
# Will save the DB if both the given number of seconds and the given
# number of write operations against the DB occurred.
#
# In the example below the behaviour will be to save:
# after 600 sec (10 min) if at least 5 key changed
# after 180 sec (3 min) if at least 10 keys changed
# after 60 sec (1 min) if at least 100 keys changed
# after 30 sec if at least 500 keys changed
#
# Note: you can disable saving completely by commenting out all "save" lines.
#
# It is also possible to remove all the previously configured save
Expand All @@ -216,10 +210,9 @@ always-show-logo yes
#
# save ""

save 600 5
save 180 10
save 900 1
save 300 10
save 60 100
save 30 500

# By default Redis will stop accepting writes if RDB snapshots are enabled
# (at least one save point) and the latest background save failed.
Expand Down
80 changes: 40 additions & 40 deletions sample_problem_info/test/solutions/wrong.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
#include <iostream>

int main() {
int N;
std::cin >> N;

int sum = 238947324;
if (N == 2 || N == 9) {
for (int i = 0; i < 10000; i++) {
sum *= (i+1);
sum += (sum % i);
sum -= i*9123479;
}
}

if (N == 4) {
int SIZE = 300000000;
int arr[SIZE];
for (int i = 2; i < SIZE; i++) {
arr[i] = arr[i-1] * arr[i-2] % arr[i-1] + 817;
}
std::cerr << arr[SIZE-1] << std::endl;
}

if (N == 5 || N == 8) {
N--;
}

if (N == 7) {
for (int i = 0; i < 800000000; i++) {
sum *= (i+1);
sum += (sum % (i+1));
sum -= i*9123479;
}
}

std::cerr << sum;
std::cout << N;
return 0;
}
#include <iostream>

int main() {
int N;
std::cin >> N;

int sum = 238947324;
if (N == 2 || N == 9) {
for (int i = 0; i < 10000; i++) {
sum *= (i+1);
sum += (sum % i);
sum -= i*9123479;
}
}

if (N == 4) {
int SIZE = 300000000;
int arr[SIZE];
for (int i = 2; i < SIZE; i++) {
arr[i] = arr[i-1] * arr[i-2] % arr[i-1] + 817;
}
std::cerr << arr[SIZE-1] << std::endl;
}

if (N == 5 || N == 8) {
N++;
}

if (N == 7) {
for (int i = 0; i < 800000000; i++) {
sum *= (i+1);
sum += (sum % (i+1));
sum -= i*9123479;
}
}

std::cerr << sum;
std::cout << N;
return 0;
}
25 changes: 16 additions & 9 deletions static/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function handleRequestError() {
setTimeout(runInterval, numFailed * 2 * QUERY_DELAY);
}

function displayTestResult(verdict, subtask, test, time=0, memory=0) {
function displayTestResult(verdict, subtask, test, isBonus, time=0, memory=0) {
let testResultsBox = document.querySelector("#submission-result-box .test-results-box");
let template = document.querySelector("#test-result");

Expand All @@ -67,18 +67,18 @@ function displayTestResult(verdict, subtask, test, time=0, memory=0) {
if (subtask != 0) testNumber.innerText = subtask + "-" + test;
else testNumber.innerText = test;

if (verdict == "AC" || verdict == "BO") {
if (verdict == "AC") {
tooltip.setAttribute("title", "Correct answer");
testResult.classList.add(verdict == "AC" ? "test-result-pass" : "test-result-bonus");
testResult.classList.add(isBonus ? "test-result-bonus" : "test-result-pass");
testVerdict.innerText = "*";
testMemory.innerText = memory + "mb";
testTime.innerText = time + "ms";
} else if (verdict == "SK") {
tooltip.setAttribute("title", "Test skipped");
testResult.classList.add("test-result-fail");
testResult.classList.add(isBonus ? "test-result-skipped" : "test-result-fail");
testVerdict.innerText = "-";
} else {
testResult.classList.add("test-result-fail");
testResult.classList.add(isBonus ? "test-result-skipped" : "test-result-fail");
if (verdict == "WA") {
tooltip.setAttribute("title", "Wrong answer");
testVerdict.innerText = "x";
Expand Down Expand Up @@ -135,14 +135,21 @@ function updateResults(resp) {
for (let i = 0; i < resp["subtasks"].length; i++) {
let subtask = resp["subtasks"][i];
let subtaskNum = i+1;
let subtaskIsBonus = resp["is_bonus"][i] == 1;
let atLeast1AC = false;
for (let j = 0; j < subtask.length; j++) {
let test = subtask[j]
if (test[0] == "AC") {
atLeast1AC = true;
break;
}
}
for (let j = 0; j < subtask.length; j++) {
let test = subtask[j];
if (test[0] != "--") {
testsCompleted++;
if (resp["is_bonus"][i] == 1 && test[0] == "AC") {
displayTestResult("BO", printSubtasks ? i+1 : 0, printSubtasks ? j+1 : testsTotal+j+1, test[1], test[2].toFixed(1));
} else if (resp["is_bonus"][i] == 0) {
displayTestResult(test[0], printSubtasks ? i+1 : 0, printSubtasks ? j+1 : testsTotal+j+1, test[1], test[2].toFixed(1));
if (!subtaskIsBonus || atLeast1AC) {
displayTestResult(test[0], printSubtasks ? i+1 : 0, printSubtasks ? j+1 : testsTotal+j+1, subtaskIsBonus, test[1], test[2].toFixed(1));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ h2 {
padding: 10px;
margin: 20px;
font-weight: bold;
overflow-wrap: anywhere;
}

.submission-result-compile-error {
Expand Down
12 changes: 12 additions & 0 deletions static/submit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
function toggleBonus() {
let bonusButton = document.getElementById("bonus-button");
let bonusContainer = document.getElementById("bonus-container");
if (bonusContainer.style.display === "none") {
bonusButton.innerText = "Hide Bonus";
bonusContainer.style.display = "block";
} else {
bonusButton.innerText = "Show Bonus";
bonusContainer.style.display = "none";
}
}

function toggleHints() {
let hintButton = document.getElementById("hint-button");
let hintContainer = document.getElementById("hint-container");
Expand Down
4 changes: 2 additions & 2 deletions templates/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!--Simple form to test the submission process-->
<div id="result-panel"></div>
<h1>Test Submission Form</h1>
<form id="test-form" autocomplete="on">
<form id="submit-form" autocomplete="on">
<label for="problem_id">Problem ID:</label>
<input id="problem_id" name="problem_id" type="text">
<br> <br>
Expand All @@ -34,7 +34,7 @@ <h1>Test Submission Form</h1>

<div id="response-text"></div>

<script src="static/index.js"></script>
<script src="static/submit.js"></script>

<template id="submit-status-display">
<div id="submission-result-box">
Expand Down
8 changes: 8 additions & 0 deletions templates/view_problem.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ <h4>Max score: {{ problem.max_score }} points</h4>
<hr>
{{ problem.statement | safe }}
<br>
{% if problem.bonus != "No bonus available." %}
<button id="bonus-button" onclick="toggleBonus();">Show Bonus</button>
<div id="bonus-container" style="display: none; margin-bottom: 0;">
{{ problem.bonus | safe }}
</div>
<br>
{% endif %}
<br>
{% if problem.hints != "No hints available." %}
<button id="hint-button" onclick="toggleHints();">Show Hints</button>
<div id="hint-container" style="display: none; margin-bottom: 0;">
Expand Down
2 changes: 1 addition & 1 deletion tests/test_judge_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_wrong_cpp(tempdir):
copyfile('./sample_problem_info/test/solutions/wrong.cpp', tempdir + '/wrong.cpp')
job = q.enqueue_call(func=judge_submission, args=(tempdir, 'test', 'wrong.cpp', 'cpp', 'username'))

correct_verdicts = ['AC', 'RE', 'AC', 'MLE', 'WA', 'AC', 'TLE', 'SK', 'SK', 'AC']
correct_verdicts = ['AC', 'RE', 'AC', 'MLE', 'WA', 'AC', 'TLE', 'WA', 'RE', 'AC']
judge_verdicts = []
for i in range(7):
judge_verdicts.append(job.result['subtasks'][0][i][0])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_judge_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_wrong_java(tempdir):
copyfile('./sample_problem_info/test/solutions/wrong.java', tempdir + '/wrong.java')
job = q.enqueue_call(func=judge_submission, args=(tempdir, 'test', 'wrong.java', 'java', 'username'))

correct_verdicts = ['AC', 'MLE', 'WA', 'AC', 'RE', 'TLE', 'AC', 'SK', 'AC', 'SK']
correct_verdicts = ['AC', 'MLE', 'WA', 'AC', 'RE', 'TLE', 'AC', 'MLE', 'AC', 'WA']
judge_verdicts = []
for i in range(7):
judge_verdicts.append(job.result['subtasks'][0][i][0])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_judge_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_stop_on_fail_average(tempdir):
copyfile('./sample_problem_info/test2/solutions/wrong.py', tempdir + '/wrong.py')
job = q.enqueue_call(func=judge_submission, args=(tempdir, 'test2', 'wrong.py', 'python', 'username'))

correct_verdicts = ['AC', 'WA', 'SK', 'AC', 'WA', 'SK', 'AC', 'SK', 'SK']
correct_verdicts = ['AC', 'WA', 'SK', 'AC', 'WA', 'SK', 'AC', 'WA', 'SK']
judge_verdicts = []
for i in range(3):
judge_verdicts.append(job.result['subtasks'][0][i][0])
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_carriage_return(tempdir):
copyfile('./sample_problem_info/test/solutions/carriage_return.py', tempdir + '/carriage_return.py')
job = q.enqueue_call(func=judge_submission, args=(tempdir, 'test', 'carriage_return.py', 'python', 'username'))

correct_verdicts = ['AC', 'AC', 'WA', 'WA', 'AC', 'AC', 'WA', 'SK', 'SK', 'SK']
correct_verdicts = ['AC', 'AC', 'WA', 'WA', 'AC', 'AC', 'WA', 'WA', 'WA', 'WA']
judge_verdicts = []
for i in range(7):
judge_verdicts.append(job.result['subtasks'][0][i][0])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_judge_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_wrong_python(tempdir):
copyfile('./sample_problem_info/test/solutions/wrong.py', tempdir + '/wrong.py')
job = q.enqueue_call(func=judge_submission, args=(tempdir, 'test', 'wrong.py', 'python', 'username'))

correct_verdicts = ['AC', 'TLE', 'AC', 'MLE', 'AC', 'WA', 'RE', 'SK', 'SK', 'AC']
correct_verdicts = ['AC', 'TLE', 'AC', 'MLE', 'AC', 'WA', 'RE', 'WA', 'MLE', 'AC']
judge_verdicts = []
for i in range(7):
judge_verdicts.append(job.result['subtasks'][0][i][0])
Expand Down

0 comments on commit fc602c0

Please sign in to comment.