From 5df7ba41267eca6dc0a7c8bb5e195215a96cb124 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Sun, 23 Aug 2015 19:27:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AF=94=E8=B5=9B=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contest/migrations/0005_contestsubmission.py | 31 ++++++++++++++ contest/views.py | 3 +- mq/scripts/info.py | 17 +++----- static/src/js/app/oj/problem/problem.js | 43 ++++++++++++++------ 4 files changed, 68 insertions(+), 26 deletions(-) create mode 100644 contest/migrations/0005_contestsubmission.py diff --git a/contest/migrations/0005_contestsubmission.py b/contest/migrations/0005_contestsubmission.py new file mode 100644 index 00000000..f1018d89 --- /dev/null +++ b/contest/migrations/0005_contestsubmission.py @@ -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', + }, + ), + ] diff --git a/contest/views.py b/contest/views.py index 924b0eb7..ae288cc3 100644 --- a/contest/views.py +++ b/contest/views.py @@ -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): diff --git a/mq/scripts/info.py b/mq/scripts/info.py index a092b0d2..70843d0b 100644 --- a/mq/scripts/info.py +++ b/mq/scripts/info.py @@ -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() diff --git a/static/src/js/app/oj/problem/problem.js b/static/src/js/app/oj/problem/problem.js index 009929b3..d936e0fd 100644 --- a/static/src/js/app/oj/problem/problem.js +++ b/static/src/js/app/oj/problem/problem.js @@ -56,7 +56,7 @@ require(["jquery", "codeMirror", "csrfToken", "bsAlert"], function ($, codeMirro var counter = 0; function getResult() { - if(counter++ > 10){ + if (counter++ > 10) { hideLoading(); bsAlert("抱歉,服务器可能出现了故障,请稍后到我的提交列表中查看"); counter = 0; @@ -88,12 +88,32 @@ 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(); - if(!code.trim()){ + if (!code.trim()) { bsAlert("请填写代码!"); hideLoading(); return false; @@ -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(); } } @@ -127,11 +144,11 @@ require(["jquery", "codeMirror", "csrfToken", "bsAlert"], function ($, codeMirro }); $.ajax({ - url : "/api/user/", + url: "/api/user/", method: "get", dataType: "json", - success: function(data){ - if(data.code){ + success: function (data) { + if (data.code) { $("#submit-code-button").attr("disabled", "disabled"); $("#result").html(''); }