You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.5 KiB

6 years ago
import * as TypeORM from "typeorm";
import Model from "./common";
8 years ago
6 years ago
declare var syzoj: any;
8 years ago
6 years ago
import ContestPlayer from "./contest_player";
import JudgeState from "./judge_state";
8 years ago
6 years ago
@TypeORM.Entity()
export default class ContestRanklist extends Model {
@TypeORM.PrimaryGeneratedColumn()
id: number;
@TypeORM.Column({ nullable: true, type: "json" })
ranking_params: any;
@TypeORM.Column({ nullable: true, type: "json" })
ranklist: any;
8 years ago
async getPlayers() {
let a = [];
for (let i = 1; i <= this.ranklist.player_num; i++) {
6 years ago
a.push(await ContestPlayer.findById(this.ranklist[i]));
8 years ago
}
return a;
}
async updatePlayer(contest, player) {
8 years ago
let players = await this.getPlayers(), newPlayer = true;
for (let x of players) {
if (x.user_id === player.user_id) {
newPlayer = false;
break;
}
}
if (newPlayer) {
players.push(player);
}
if (contest.type === 'noi' || contest.type === 'ioi') {
for (let player of players) {
player.latest = 0;
player.score = 0;
for (let i in player.score_details) {
6 years ago
let judge_state = await JudgeState.findById(player.score_details[i].judge_id);
if (!judge_state) continue;
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;
}
}
}
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;
});
} else {
for (let player of players) {
player.timeSum = 0;
for (let i in player.score_details) {
if (player.score_details[i].accepted) {
player.timeSum += (player.score_details[i].acceptedTime - contest.start_time) + (player.score_details[i].unacceptedCount * 20 * 60);
}
}
}
players.sort((a, b) => {
if (a.score > b.score) return -1;
if (b.score > a.score) return 1;
if (a.timeSum < b.timeSum) return -1;
if (a.timeSum > b.timeSum) return 1;
return 0;
});
}
8 years ago
this.ranklist = { player_num: players.length };
for (let i = 0; i < players.length; i++) this.ranklist[i + 1] = players[i].id;
}
}