From ac7ec743151f642d25ebef1bdf70d36ec14c65b8 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Tue, 25 Aug 2015 13:34:55 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A2=98=E7=9B=AE?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contest/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contest/views.py b/contest/views.py index 8c2e29f9..92cbd785 100644 --- a/contest/views.py +++ b/contest/views.py @@ -134,9 +134,9 @@ class ContestAdminAPIView(APIView): response_serializer: ContestSerializer """ if request.user.admin_type == SUPER_ADMIN: - contest = Contest.objects.all().order_by("-last_updated_time") + contest = Contest.objects.all().order_by("-create_time") else: - contest = Contest.objects.filter(created_by=request.user).order_by("-last_updated_time") + contest = Contest.objects.filter(created_by=request.user).order_by("-create_time") visible = request.GET.get("visible", None) if visible: contest = contest.filter(visible=(visible == "true")) From 5acd55b702a3a5f7250352d2f48607cbee59caa0 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Tue, 25 Aug 2015 13:35:06 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=AF=94=E8=B5=9B?= =?UTF-8?q?=E9=A2=98=E7=9B=AE=E5=88=97=E8=A1=A8=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/oj/contest/contest_problem.html | 31 ++++++++++-------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/template/oj/contest/contest_problem.html b/template/oj/contest/contest_problem.html index cf2b7db3..f5b3cb1c 100644 --- a/template/oj/contest/contest_problem.html +++ b/template/oj/contest/contest_problem.html @@ -1,11 +1,13 @@ {% extends 'oj_base.html' %} {% block body %} -
+

{{ contest_problem.title }}

@@ -15,29 +17,22 @@

-
- +
+ -

{{ contest_problem.description|safe }}

-
-
- +

{{ contest_problem.description|safe }}

+
+
+ + +

{{ contest_problem.input_description }}

-
- -

{{ contest_problem.description|safe }}

-
-
- - -

{{ contest_problem.input_description }}

-
-

{{ contest_problem.output_description }}k

+

{{ contest_problem.output_description }}

{% for item in samples %}
From 1746fe7184346d3fb3fceed709f4dbc72bc6f9a5 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Tue, 25 Aug 2015 15:45:56 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E6=AF=94=E8=B5=9B=E6=8E=92=E5=90=8D=E7=9A=84=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=92=8C=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contest/views.py | 33 ++++++------------------- mq/scripts/info.py | 3 +++ template/oj/contest/contest_rank.html | 35 ++++++++++++++++++++++++--- utils/templatetags/submission.py | 22 ++++++++++++++++- 4 files changed, 64 insertions(+), 29 deletions(-) diff --git a/contest/views.py b/contest/views.py index 92cbd785..67201933 100644 --- a/contest/views.py +++ b/contest/views.py @@ -300,7 +300,7 @@ def contest_problem_page(request, contest_id, contest_problem_id): contest_problem = ContestProblem.objects.get(id=contest_problem_id, visible=True) except ContestProblem.DoesNotExist: return error_page(request, u"比赛题目不存在") - warning = u"您已经提交过本题的正确答案!" + warning = u"您已经提交过本题的正确答案,重复提交可能造成时间累计。" show_warning = False try: submission = ContestSubmission.objects.get(user=request.user, contest=contest, problem=contest_problem) @@ -394,39 +394,22 @@ def _cmp(x, y): @check_user_contest_permission def contest_rank_page(request, contest_id): + contest = Contest.objects.get(id=contest_id) + contest_problems = ContestProblem.objects.filter(contest=contest).order_by("sort_index") result = ContestSubmission.objects.values("user_id").annotate(total_submit=Count("user_id")) for i in range(0, len(result)): # 这个人所有的提交 submissions = ContestSubmission.objects.filter(user_id=result[i]["user_id"]) + result[i]["submissions"] = {} + for item in submissions: + result[i]["submissions"][item.problem_id] = item result[i]["total_ac"] = submissions.filter(ac=True).count() result[i]["user"] = User.objects.get(id=result[i]["user_id"]) - result[i]["submissions"] = submissions.order_by("problem__sort_index") result[i]["total_time"] = submissions.filter(ac=True).aggregate(total_time=Sum("total_time"))["total_time"] - print result - return render(request, "oj/contest/contest_rank.html") - # - # - # return - # contest = Contest.objects.get(id=contest_id) - # contest_submissions = ContestSubmission.objects.filter(contest=contest) - # result = {} - # # 先把数据按照用户id 为 key 整理一下 - # # {1: {"submissions": [], "total_time": 0, "total_ac": 0}} - # for item in contest_submissions: - # if item.user.id not in contest_submissions: - # result[item.user.id] = {"user": {"id": item.user.id, "username": item.user.username, - # "real_name": item.user.real_name}, - # "submissions": [], "total_time": 0, "total_ac": 0} - # result[item.user.id]["submissions"].append(ContestSubmissionSerializer(item).data) - # if item.ac: - # result[item.user.id]["total_time"] += item.total_time - # result[item.user.id]["total_ac"] += 1 - # l = [] - # for k, v in result.iteritems(): - # l.append(v) - # print sorted(l, cmp=_cmp, reverse=True) + return render(request, "oj/contest/contest_rank.html", + {"contest": contest, "contest_problems": contest_problems, "result": sorted(result, cmp=_cmp, reverse=True)}) diff --git a/mq/scripts/info.py b/mq/scripts/info.py index 661c3ff6..6634b5b3 100644 --- a/mq/scripts/info.py +++ b/mq/scripts/info.py @@ -61,9 +61,12 @@ class MessageQueue(object): logger.debug(contest.start_time) logger.debug(submission.create_time) logger.debug((submission.create_time - contest.start_time).total_seconds()) + logger.debug(int((submission.create_time - contest.start_time).total_seconds() / 60)) contest_submission.total_time += int((submission.create_time - contest.start_time).total_seconds() / 60) # 标记为已经通过 contest_submission.ac = True + # 提交次数加1 + contest_submission.total_submission_number += 1 # contest problem ac 计数器加1 contest_problem.total_accepted_number += 1 else: diff --git a/template/oj/contest/contest_rank.html b/template/oj/contest/contest_rank.html index 89d1e409..823b021b 100644 --- a/template/oj/contest/contest_rank.html +++ b/template/oj/contest/contest_rank.html @@ -1,10 +1,10 @@ {% extends "oj_base.html" %} {% block body %} - {% load contest %} + {% load submission %}
+ + + + + + + + {% for item in contest_problems %} + + {% endfor %} + + + + {% for item in result %} + + + + + + {% for problem in contest_problems %} + + {% endfor %} + + {% endfor %} + +
#用户名AC / 总提交用时 + 罚时{{ item.sort_index }} +
{{ forloop.counter }}{{ item.user.username }}{{ item.total_ac }} / {{ item.total_submit }}{% if item.total_time %}{{ item.total_time }} min{% else %}--{% endif %} + {% submission_problem problem item.submissions %} +
diff --git a/utils/templatetags/submission.py b/utils/templatetags/submission.py index a80c25e6..b1f43d2d 100644 --- a/utils/templatetags/submission.py +++ b/utils/templatetags/submission.py @@ -29,7 +29,27 @@ def translate_result_class(value): return "danger" +def get_contest_submission_problem_detail(contest_problem, my_submission): + if contest_problem.id in my_submission: + submission = my_submission[contest_problem.id] + if submission.ac: + return u"\n 时间: " + str(submission.total_time) + u" min" + return "" + + +def get_submission_problem_result_class(contest_problem, my_submission): + if contest_problem.id in my_submission: + submission = my_submission[contest_problem.id] + if submission.ac: + return "success" + else: + return "danger" + else: + return "" + register = template.Library() register.filter("translate_result", translate_result) register.filter("translate_language", translate_language) -register.filter("translate_result_class", translate_result_class) \ No newline at end of file +register.filter("translate_result_class", translate_result_class) +register.simple_tag(get_contest_submission_problem_detail, name="submission_problem") +register.simple_tag(get_submission_problem_result_class, name="submission_problem_result_class") \ No newline at end of file