From 86c70eb8bd9ffaeb3ece85af146a27fbf74a9184 Mon Sep 17 00:00:00 2001 From: "sxw@401" Date: Sun, 13 Sep 2015 21:31:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9rank=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F=20hh:mm:ss,=E4=BF=AE?= =?UTF-8?q?=E6=94=B9rank=E9=A1=B5=E9=9D=A2=E6=97=B6=E9=97=B4=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=20hh:mm:ss,ContestSubmission=E4=B8=AD=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E4=BB=A5=E7=A7=92=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contest/models.py | 2 +- contest/views.py | 19 ++++++++++++++++--- mq/scripts/info.py | 6 +++--- template/src/oj/contest/contest_rank.html | 6 ++---- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/contest/models.py b/contest/models.py index 8b8a260..d880f06 100644 --- a/contest/models.py +++ b/contest/models.py @@ -90,7 +90,7 @@ class ContestSubmission(models.Model): total_submission_number = models.IntegerField(default=1) # 这道题是 AC 还是没过 ac = models.BooleanField() - # ac 用时 + # ac 用时以秒计 ac_time = models.IntegerField(default=0) # 总的时间,用于acm 类型的,也需要保存罚时 total_time = models.IntegerField(default=0) diff --git a/contest/views.py b/contest/views.py index a5a45c4..867b999 100644 --- a/contest/views.py +++ b/contest/views.py @@ -392,6 +392,19 @@ def _cmp(x, y): return -1 +def get_the_time_format(seconds): + result = str(seconds % 60) + if seconds % 60 < 10: + result = "0" + result + result = str((seconds % 3600) / 60) + ":" + result + if (seconds % 3600) / 60 < 10: + result = "0" + result + result = str(seconds / 3600) + ":" + result + if seconds / 3600 < 10: + result = "0" + result + return result + + @check_user_contest_permission def contest_rank_page(request, contest_id): contest = Contest.objects.get(id=contest_id) @@ -410,17 +423,17 @@ def contest_rank_page(request, contest_id): try: status = submissions.get(problem=problem) result[i]["problems"].append({ - "first_achieved":status.first_achieved, + "first_achieved": status.first_achieved, "ac": status.ac, "failed_number": status.total_submission_number, - "ac_time": status.ac_time}) + "ac_time": get_the_time_format(status.ac_time)}) if status.ac: result[i]["problems"][-1]["failed_number"] -= 1 except ContestSubmission.DoesNotExist: result[i]["problems"].append({}) result[i]["total_ac"] = submissions.filter(ac=True).count() result[i]["username"] = User.objects.get(id=result[i]["user_id"]).username - result[i]["total_time"] = submissions.filter(ac=True).aggregate(total_time=Sum("total_time"))["total_time"] + result[i]["total_time"] = get_the_time_format(submissions.filter(ac=True).aggregate(total_time=Sum("total_time"))["total_time"]) result = sorted(result, cmp=_cmp, reverse=True) r.set("contest_rank_" + contest_id, json.dumps(list(result))) else: diff --git a/mq/scripts/info.py b/mq/scripts/info.py index 5e3691e..c3a2a36 100644 --- a/mq/scripts/info.py +++ b/mq/scripts/info.py @@ -71,7 +71,7 @@ class MessageQueue(object): contest_problem.total_accepted_number += 1 else: # 如果这个提交是错误的,就罚时20分钟 - contest_submission.total_time += 20 + contest_submission.total_time += 1200 contest_submission.total_submission_number += 1 contest_submission.save() contest_problem.save() @@ -79,13 +79,13 @@ class MessageQueue(object): # 第一次提交 is_ac = submission.result == result["accepted"] if is_ac: - total_time = int((submission.create_time - contest.start_time).total_seconds() / 60) + total_time = int((submission.create_time - contest.start_time).total_seconds()) # 增加题目总的ac数计数器 contest_problem.total_accepted_number += 1 contest_problem.save() else: # 没过罚时20分钟 - total_time = 20 + total_time = 1200 ContestSubmission.objects.create(user_id=submission.user_id, contest=contest, problem=contest_problem, ac=is_ac, total_time=total_time) diff --git a/template/src/oj/contest/contest_rank.html b/template/src/oj/contest/contest_rank.html index 62faf0b..11bc8d8 100644 --- a/template/src/oj/contest/contest_rank.html +++ b/template/src/oj/contest/contest_rank.html @@ -47,12 +47,10 @@ {{ forloop.counter }} {{ item.username }} {{ item.total_ac }} / {{ item.total_submit }} - {% if item.total_time %}{{ item.total_time }} min{% else %}--{% endif %} + {% if item.total_time %}{{ item.total_time }}{% else %}--{% endif %} {% for problem in item.problems %} - {% if problem.ac %} - {{ problem.ac_time }}min - {% endif %} + {% if problem.ac %}{{ problem.ac_time }}{% endif %} {% if problem.failed_number %} (-{{ problem.failed_number }}) {% endif %}