From c3962a913924d6199f0ba198a96596bdba9dc604 Mon Sep 17 00:00:00 2001 From: Menci Date: Wed, 14 Dec 2016 19:55:24 +0800 Subject: [PATCH] Sort contest ranklist by latest submit time --- models/contest_ranklist.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/models/contest_ranklist.js b/models/contest_ranklist.js index 6cc047f..1587516 100644 --- a/models/contest_ranklist.js +++ b/models/contest_ranklist.js @@ -63,7 +63,23 @@ class ContestRanklist extends Model { players.push(player); } - players.sort((a, b) => b.score - a.score); + let JudgeState = syzoj.model('judge_state'); + + for (let player of players) { + player.latest = 0; + for (let i in 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); + } + } + + players.sort((a, b) => { + if (a.score > b.score) return -1; + if (b.score > a.score) return 1; + if (a.latest < b.latest) return -1; + if (a.latest > b.latest) return 1; + return 0; + }); this.ranklist = { player_num: players.length }; for (let i = 0; i < players.length; i++) this.ranklist[i + 1] = players[i].id;