From 44e3bc2b4386ef7e4998708d35477f21b7577804 Mon Sep 17 00:00:00 2001 From: Pisces000221 <1786762946@qq.com> Date: Thu, 28 Dec 2017 23:40:53 +0800 Subject: [PATCH] Hot fix for Hello 2018! Quick and dirty, will refactor later > < --- models/contest_ranklist.js | 10 ++++++++++ modules/contest.js | 21 ++++++++++++++++++--- views/contest_edit.ejs | 4 ++++ views/contest_ranklist.ejs | 4 ++-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/models/contest_ranklist.js b/models/contest_ranklist.js index d8ea6b6..2689238 100644 --- a/models/contest_ranklist.js +++ b/models/contest_ranklist.js @@ -28,6 +28,7 @@ let ContestPlayer = syzoj.model('contest_player'); let model = db.define('contest_ranklist', { id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, + ranking_params: { type: Sequelize.TEXT, json: true }, ranklist: { type: Sequelize.TEXT, json: true } }, { timestamps: false, @@ -38,6 +39,7 @@ let Model = require('./common'); class ContestRanklist extends Model { static async create(val) { return ContestRanklist.fromRecord(ContestRanklist.model.build(Object.assign({ + ranking_params: '{}', ranklist: '{}' }, val))); } @@ -69,8 +71,16 @@ class ContestRanklist extends Model { for (let player of players) { player.latest = 0; for (let i in player.score_details) { + player.score = 0; + let judge_state = await JudgeState.fromID(player.score_details[i].judge_id); player.latest = Math.max(player.latest, judge_state.submit_time); + + if (player.score_details[i].score != null) { + let multiplier = this.ranking_params[i] || 1.0; + player.score_details[i].weighted_score = Math.round(player.score_details[i].score * multiplier); + player.score += player.score_details[i].weighted_score; + } } } diff --git a/modules/contest.js b/modules/contest.js index 1be0702..a6bc59e 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -61,6 +61,8 @@ app.get('/contest/:id/edit', async (req, res) => { if (!contest) { contest = await Contest.create(); contest.id = 0; + } else { + await contest.loadRelationships(); } let problems = [], admins = []; @@ -86,20 +88,26 @@ app.post('/contest/:id/edit', async (req, res) => { let contest_id = parseInt(req.params.id); let contest = await Contest.fromID(contest_id); + let ranklist = null; if (!contest) { contest = await Contest.create(); contest.holder_id = res.locals.user.id; - let ranklist = await ContestRanklist.create(); - await ranklist.save(); - contest.ranklist_id = ranklist.id; + ranklist = await ContestRanklist.create(); // Only new contest can be set type if (!['noi', 'ioi', 'acm'].includes(req.body.type)) throw new ErrorMessage('无效的赛制。'); contest.type = req.body.type; + } else { + await contest.loadRelationships(); + ranklist = contest.ranklist; } + ranklist.ranking_params = JSON.parse(req.body.ranking_params); + await ranklist.save(); + contest.ranklist_id = ranklist.id; + if (!req.body.title.trim()) throw new ErrorMessage('比赛名不能为空。'); contest.title = req.body.title; contest.subtitle = req.body.subtitle; @@ -247,6 +255,13 @@ app.get('/contest/:id/ranklist', async (req, res) => { let player = await ContestPlayer.fromID(player_id); for (let i in player.score_details) { player.score_details[i].judge_state = await JudgeState.fromID(player.score_details[i].judge_id); + + /*** XXX: Clumsy duplication, see ContestRanklist::updatePlayer() ***/ + if (contest.type === 'noi' || contest.type === 'ioi') { + let multiplier = contest.ranklist.ranking_params[i] || 1.0; + player.score_details[i].weighted_score = player.score_details[i].score == null ? null : Math.round(player.score_details[i].score * multiplier); + player.score += player.score_details[i].weighted_score; + } } let user = await User.fromID(player.user_id); diff --git a/views/contest_edit.ejs b/views/contest_edit.ejs index e4fe124..86e8d06 100644 --- a/views/contest_edit.ejs +++ b/views/contest_edit.ejs @@ -47,6 +47,10 @@ +
+ + +
diff --git a/views/contest_ranklist.ejs b/views/contest_ranklist.ejs index a0841b7..40458dc 100644 --- a/views/contest_ranklist.ejs +++ b/views/contest_ranklist.ejs @@ -122,9 +122,9 @@ <% } else if (contest.type === 'noi' || contest.type === 'ioi') { %> - <% if (item.player.score_details[problem.id].score != null) { %> + <% if (item.player.score_details[problem.id].weighted_score != null) { %> - <%= Math.round(item.player.score_details[problem.id].score) %> + <%= Math.round(item.player.score_details[problem.id].weighted_score) %> <% } else { %>