Browse Source

Hot fix for Hello 2018!

Quick and dirty, will refactor later > <
pull/6/head
Pisces000221 7 years ago
parent
commit
44e3bc2b43
  1. 10
      models/contest_ranklist.js
  2. 21
      modules/contest.js
  3. 4
      views/contest_edit.ejs
  4. 4
      views/contest_ranklist.ejs

10
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;
}
}
}

21
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);

4
views/contest_edit.ejs

@ -47,6 +47,10 @@
</div>
</div>
</div>
<div class="field">
<label>排行参数</label>
<input type="text" name="ranking_params" value="<%= JSON.stringify(contest.ranklist.ranking_params) %>">
</div>
<div class="field">
<label>比赛公告</label>
<textarea class="" rows="5" id="doc-ta-1" name="information" class="font-content"><%= contest.information %></textarea>

4
views/contest_ranklist.ejs

@ -122,9 +122,9 @@
</td>
<% } else if (contest.type === 'noi' || contest.type === 'ioi') { %>
<a href="<%= syzoj.utils.makeUrl(['submission', item.player.score_details[problem.id].judge_id]) %>">
<% if (item.player.score_details[problem.id].score != null) { %>
<% if (item.player.score_details[problem.id].weighted_score != null) { %>
<span class="score score_<%= parseInt((item.player.score_details[problem.id].score / 10) || 0) %>">
<%= Math.round(item.player.score_details[problem.id].score) %>
<%= Math.round(item.player.score_details[problem.id].weighted_score) %>
</span>
<% } else { %>
<span class="status compile_error">

Loading…
Cancel
Save