增加比赛相关的功能
This commit is contained in:
31
contest/migrations/0005_contestsubmission.py
Normal file
31
contest/migrations/0005_contestsubmission.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('contest', '0004_remove_contestproblem_difficulty'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ContestSubmission',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('total_submission_number', models.IntegerField(default=1)),
|
||||
('ac', models.BooleanField()),
|
||||
('total_time', models.IntegerField(default=0)),
|
||||
('contest', models.ForeignKey(to='contest.Contest')),
|
||||
('problem', models.ForeignKey(to='contest.ContestProblem')),
|
||||
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'contest_submission',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -285,7 +285,8 @@ def contest_problems_list_page(request, contest_id):
|
||||
# 右侧的公告列表
|
||||
announcements = Announcement.objects.filter(is_global=True, visible=True).order_by("-create_time")
|
||||
return render(request, "oj/contest/contest_problems_list.html", {"contest_problems": contest_problems,
|
||||
"announcements": announcements})
|
||||
"announcements": announcements,
|
||||
"contest": {"id": contest_id}})
|
||||
|
||||
|
||||
def contest_list_page(request, page=1):
|
||||
|
||||
@@ -52,15 +52,16 @@ class MessageQueue(object):
|
||||
try:
|
||||
contest_submission = ContestSubmission.objects.get(user_id=submission.user_id, contest=contest,
|
||||
problem_id=contest_problem.id)
|
||||
# 如果这道题已经有提交记录了,总的提交次数计数器加1
|
||||
contest_submission.total_submission_number += 1
|
||||
|
||||
if submission.result == result["accepted"]:
|
||||
|
||||
# 避免这道题已经 ac 了,但是又重新提交了一遍
|
||||
if not contest_submission.result:
|
||||
if not contest_submission.ac:
|
||||
# 这种情况是这个题目前处于错误状态,就使用已经存储了的罚时加上这道题的实际用时
|
||||
contest_submission.total_time += int((submission.create_time - contest.start_time).seconds / 60)
|
||||
logger.debug(contest.start_time)
|
||||
logger.debug(submission.create_time)
|
||||
logger.debug((submission.create_time - contest.start_time).total_seconds())
|
||||
contest_submission.total_time += int((submission.create_time - contest.start_time).total_seconds() / 60)
|
||||
# 标记为已经通过
|
||||
contest_submission.ac = True
|
||||
# contest problem ac 计数器加1
|
||||
@@ -88,13 +89,5 @@ class MessageQueue(object):
|
||||
ac=is_ac, total_time=total_time)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
except ContestSubmission.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
logger.debug("Start message queue")
|
||||
MessageQueue().listen_task()
|
||||
|
||||
@@ -88,8 +88,28 @@ require(["jquery", "codeMirror", "csrfToken", "bsAlert"], function ($, codeMirro
|
||||
}
|
||||
|
||||
$("#submit-code-button").click(function () {
|
||||
var problemId = window.location.pathname.split("/")[2];
|
||||
|
||||
var code = codeEditor.getValue();
|
||||
if (location.href.indexOf("contest") > -1) {
|
||||
var problemId = location.pathname.split("/")[4];
|
||||
var contestId = location.pathname.split("/")[2];
|
||||
var url = "/api/contest/submission/";
|
||||
var data = {
|
||||
problem_id: problemId,
|
||||
language: language,
|
||||
code: code,
|
||||
contest_id: contestId
|
||||
};
|
||||
}
|
||||
else {
|
||||
var problemId = window.location.pathname.split("/")[2];
|
||||
var url = "/api/submission/";
|
||||
var data = {
|
||||
problem_id: problemId,
|
||||
language: language,
|
||||
code: code
|
||||
};
|
||||
}
|
||||
|
||||
showLoading();
|
||||
|
||||
@@ -101,15 +121,12 @@ require(["jquery", "codeMirror", "csrfToken", "bsAlert"], function ($, codeMirro
|
||||
|
||||
$("#result").html("");
|
||||
|
||||
|
||||
$.ajax({
|
||||
beforeSend: csrfTokenHeader,
|
||||
url: "/api/submission/",
|
||||
url: url,
|
||||
method: "post",
|
||||
data: JSON.stringify({
|
||||
problem_id: problemId,
|
||||
language: language,
|
||||
code: codeEditor.getValue()
|
||||
}),
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
@@ -118,7 +135,7 @@ require(["jquery", "codeMirror", "csrfToken", "bsAlert"], function ($, codeMirro
|
||||
setTimeout(getResult, 2000);
|
||||
}
|
||||
else {
|
||||
bs_alert(data.data);
|
||||
bsAlert(data.data);
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user