From 6b641d613b47407e483a6bd40ff24572276178d5 Mon Sep 17 00:00:00 2001 From: Menci Date: Tue, 13 Jun 2017 12:04:54 +0800 Subject: [PATCH] Change problem id in contests to letters, add problem statistics in contest --- models/contest_ranklist.js | 1 - modules/contest.js | 33 +++++++++++++++++++++++++++++++-- views/contest.ejs | 16 +++++++++++++++- views/contest_submissions.ejs | 13 +++++++++++-- views/problem.ejs | 4 ++-- views/submission_content.ejs | 2 +- views/submissions_item.ejs | 2 +- views/util.ejs | 10 +++++++--- 8 files changed, 68 insertions(+), 13 deletions(-) diff --git a/models/contest_ranklist.js b/models/contest_ranklist.js index 7140066..d8ea6b6 100644 --- a/models/contest_ranklist.js +++ b/models/contest_ranklist.js @@ -69,7 +69,6 @@ class ContestRanklist extends Model { for (let player of players) { player.latest = 0; for (let i in player.score_details) { - console.log(player.score_details); let judge_state = await JudgeState.fromID(player.score_details[i].judge_id); player.latest = Math.max(player.latest, judge_state.submit_time); } diff --git a/modules/contest.js b/modules/contest.js index 2284da0..eb74991 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -131,7 +131,7 @@ app.get('/contest/:id', async (req, res) => { }); } - problems = problems.map(x => ({ problem: x, status: null, judge_id: null })); + problems = problems.map(x => ({ problem: x, status: null, judge_id: null, statistics: null })); if (player) { for (let problem of problems) { if (contest.type === 'noi') { @@ -168,9 +168,38 @@ app.get('/contest/:id', async (req, res) => { } } + let hasStatistics = false; + if (contest.type === 'ioi' || contest.type === 'acm' || (contest.type === 'noi' && (contest.ended || (res.locals.user && res.locals.user.is_admin)))) { + hasStatistics = true; + + await contest.loadRelationships(); + let players = await contest.ranklist.getPlayers(); + for (let problem of problems) { + problem.statistics = { attempt: 0, accepted: 0 }; + + if (contest.type === 'ioi' || contest.type === 'noi') { + problem.statistics.partially = 0; + } + + for (let player of players) { + if (player.score_details[problem.problem.id]) { + problem.statistics.attempt++; + if ((contest.type === 'acm' && player.score_details[problem.problem.id].accepted) || ((contest.type === 'noi' || contest.type === 'ioi') && player.score_details[problem.problem.id].score === 100)) { + problem.statistics.accepted++; + } + + if ((contest.type === 'noi' || contest.type === 'ioi') && player.score_details[problem.problem.id].score > 0) { + problem.statistics.partially++; + } + } + } + } + } + res.render('contest', { contest: contest, - problems: problems + problems: problems, + hasStatistics: hasStatistics }); } catch (e) { syzoj.log(e); diff --git a/views/contest.ejs b/views/contest.ejs index 04efaa7..aa6dfe1 100644 --- a/views/contest.ejs +++ b/views/contest.ejs @@ -49,7 +49,10 @@ 状态 - 题目 + 题目 + <% if (hasStatistics) { %> + 统计 + <% } %> @@ -89,6 +92,17 @@ <% } %> <%= syzoj.utils.removeTitleTag(problem.problem.title) %> + <% if (hasStatistics) { %> + + <%= problem.statistics.accepted %> + / + <%= problem.statistics.partially %> + <% if (contest.type === 'noi' || contest.type === 'ioi') { %> + / + <% } %> + <%= problem.statistics.attempt %> + + <% } %> <% } %> diff --git a/views/contest_submissions.ejs b/views/contest_submissions.ejs index 2826f54..8f6f166 100644 --- a/views/contest_submissions.ejs +++ b/views/contest_submissions.ejs @@ -2,10 +2,11 @@ <% include header %>
-
+
-
+
+
<% if ((typeof contest === 'undefined' || !contest) || contest.ended || contest.type !== 'noi' || (user && user.is_admin)) { %> @@ -94,5 +95,13 @@ $(function () { $('#select_language').dropdown(); $('#select_status').dropdown(); }); + +function checkSubmit() { + var x = $('#problem_id').val(), ch = x.charCodeAt(0); + if (x.length === 1 && x >= 'A' && x <= 'Z') $('#problem_id_hidden').val(ch - 'A'.charCodeAt(0) + 1); + else if (x.length === 1 && x >= 'a' && x <= 'a') $('#problem_id_hidden').val(ch - 'a'.charCodeAt(0) + 1); + else $('#problem_id_hidden').val(x); + return true; +} <% include footer %> diff --git a/views/problem.ejs b/views/problem.ejs index 6541c1b..8d83ee1 100644 --- a/views/problem.ejs +++ b/views/problem.ejs @@ -1,7 +1,7 @@ <% if (typeof contest === 'undefined') contest = null; if (contest) { - this.title = syzoj.utils.removeTitleTag(problem.title) + ' - ' + contest.title + ' - 比赛'; + this.title = this.alpha(pid) + '. ' + syzoj.utils.removeTitleTag(problem.title) + ' - ' + contest.title + ' - 比赛'; } else { this.title = problem.title + ' - 题目'; } @@ -22,7 +22,7 @@ if (contest) {

<% if (contest) { %> - #<%= pid %>. <%= syzoj.utils.removeTitleTag(problem.title) %> + <%= this.alpha(pid) %>. <%= syzoj.utils.removeTitleTag(problem.title) %> <% } else { %> #<%= problem.id %>. <%= problem.title %><% if (problem.allowedEdit && !problem.is_public) { %>未公开<% } %> <% } %> diff --git a/views/submission_content.ejs b/views/submission_content.ejs index f59b009..694b831 100644 --- a/views/submission_content.ejs +++ b/views/submission_content.ejs @@ -48,7 +48,7 @@ else problemUrl = syzoj.utils.makeUrl(['problem', judge.problem_id]); #<%= judge.id %> - #<%= judge.problem_id %>. <%= judge.problem.title %> + <%= (typeof contest !== 'undefined' && contest) ? this.alpha(judge.problem_id) : ('#' + judge.problem_id) %>. <%= judge.problem.title %> <% if (judge.allowedSeeResult) { %> diff --git a/views/submissions_item.ejs b/views/submissions_item.ejs index a08eba5..30d0d8d 100644 --- a/views/submissions_item.ejs +++ b/views/submissions_item.ejs @@ -5,7 +5,7 @@ if (typeof contest !== 'undefined' && contest) problemUrl = syzoj.utils.makeUrl( else problemUrl = syzoj.utils.makeUrl(['problem', judge.problem_id]); %> #<%= judge.id %> -#<%= judge.problem_id %>. <%= judge.problem.title %> +<%= (typeof contest !== 'undefined' && contest) ? this.alpha(judge.problem_id) : ('#' + judge.problem_id) %>. <%= judge.problem.title %>