core: add contest score ratio (#765)

Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
undefinedandpanda authored and GitHub committed 2024-04-01 19:25:18 +08:00
1 parent 9013c4eaa6
commit e25db178fd
11 files changed
+121 -23

No files matched your search

+11
View File
@@ -253,6 +253,7 @@ export class ContestProblemListHandler extends ContestDetailBaseHandler {
pdict, psdict: {}, udict, rdict: {}, tdoc: this.tdoc, tsdoc: this.tsdoc, tcdocs,
};
this.response.template = 'contest_problemlist.html';
this.response.body.showScore = Object.values(this.tdoc.score || {}).some((i) => i && i !== 100);
if (!this.tsdoc) return;
if (this.tsdoc.attend && !this.tsdoc.startAt && contest.isOngoing(this.tdoc)) {
await contest.setStatus(domainId, tid, this.user._id, { startAt: new Date() });
@@ -651,6 +652,16 @@ export class ContestManagementHandler extends ContestManagementBaseHandler {
]);
this.back();
}
@param('pid', Types.PositiveInt)
@param('score', Types.PositiveInt)
async postSetScore(domainId: string, pid: number, score: number) {
if (!this.tdoc.pids.includes(pid)) throw new ValidationError('pid');
this.tdoc.score ||= {};
this.tdoc.score[pid] = score;
await contest.edit(domainId, this.tdoc.docId, { score: this.tdoc.score });
this.back();
}
}
export class ContestFileDownloadHandler extends ContestDetailBaseHandler {
+3 -2
View File
@@ -358,9 +358,9 @@ export interface JudgeRequest extends Omit<RecordDoc, '_id' | 'testCases'> {
export interface ScoreboardNode {
type: 'string' | 'rank' | 'user' | 'email' | 'record' | 'records' | 'problem' | 'solved' | 'time' | 'total_score';
value: string;
value: string; // 显示分数
raw?: any;
score?: number;
score?: number; // 原始分数(100,不含赛制加成)
style?: string;
hover?: string;
}
@@ -396,6 +396,7 @@ export interface Tdoc extends Document {
unlocked?: boolean;
autoHide?: boolean;
balloon?: Record<number, string>;
score?: Record<number, number>;
/**
* In hours
+25 -12
View File
@@ -291,7 +291,9 @@ const oi = buildContestRule({
display[j.pid] = j;
}
}
for (const i in display) score += display[i].score || 0;
for (const i in display) {
score += ((tdoc.score?.[i] || 100) * (display[i].score || 0)) / 100;
}
return { score, detail, display };
},
showScoreboard: (tdoc, now) => now > tdoc.endAt,
@@ -332,6 +334,10 @@ const oi = buildContestRule({
{ type: 'rank', value: rank.toString() },
{ type: 'user', value: udoc.uname, raw: tsdoc.uid },
];
const displayScore = (pid: number, score?: number) => {
if (typeof score !== 'number') return '-';
return score * ((tdoc.score?.[pid] || 100) / 100);
};
if (config.isExport) {
row.push({ type: 'email', value: udoc.mail });
row.push({ type: 'string', value: udoc.school || '' });
@@ -357,17 +363,20 @@ const oi = buildContestRule({
type: 'records',
value: '',
raw: [{
value: tsddict[pid]?.score ?? '-',
value: displayScore(pid, tsddict[pid]?.score),
raw: tsddict[pid]?.rid || null,
score: tsddict[pid]?.score,
}, {
value: meta?.psdict?.[index]?.score ?? '-',
value: displayScore(pid, meta?.psdict?.[index]?.score),
raw: meta?.psdict?.[index]?.rid ?? null,
score: meta?.psdict?.[index]?.score,
}],
} : {
type: 'record',
value: `${tsddict[pid]?.score ?? '-'}${tsddict[pid]?.npending
value: `${displayScore(pid, tsddict[pid]?.score)}${tsddict[pid]?.npending
? `<span style="color:orange">+${tsddict[pid]?.npending}</span>` : ''}`,
raw: tsddict[pid]?.rid || null,
score: tsddict[pid]?.score,
};
if (tsddict[pid]?.status === STATUS.STATUS_ACCEPTED && tsddict[pid]?.rid.getTimestamp().getTime() === meta?.first?.[pid]) {
node.style = 'background-color: rgb(217, 240, 199);';
@@ -461,7 +470,7 @@ const strictioi = buildContestRule({
j.status = Math.max(...Object.values(subtasks[j.pid]).map((i) => i.status));
if (!detail[j.pid] || detail[j.pid].score < j.score) detail[j.pid] = { ...j, subtasks: subtasks[j.pid] };
}
for (const i in detail) score += detail[i].score;
for (const i in detail) score += ((tdoc.score?.[i] || 100) * (detail[i].score || 0)) / 100;
return { score, detail };
},
async scoreboardRow(config, _, tdoc, pdict, udoc, rank, tsdoc, meta) {
@@ -485,9 +494,10 @@ const strictioi = buildContestRule({
for (const pid of tdoc.pids) {
row.push({
type: 'record',
value: tsddict[pid]?.score || '',
value: ((tsddict[pid]?.score || 0) * ((tdoc.score?.[pid] || 100) / 100)).toString() || '',
hover: Object.values(tsddict[pid]?.subtasks || {}).map((i: SubtaskResult) => `${STATUS_SHORT_TEXTS[i.status]} ${i.score}`).join(','),
raw: tsddict[pid]?.rid,
score: tsddict[pid]?.score,
style: tsddict[pid]?.status === STATUS.STATUS_ACCEPTED && tsddict[pid]?.rid.getTimestamp().getTime() === meta?.first?.[pid]
? 'background-color: rgb(217, 240, 199);'
: undefined,
@@ -523,8 +533,9 @@ const ledo = buildContestRule({
let originalScore = 0;
for (const pid of tdoc.pids) {
if (!detail[pid]) continue;
score += detail[pid].penaltyScore;
originalScore += detail[pid].score;
const rate = (tdoc.score?.[pid] || 100) / 100;
score += detail[pid].penaltyScore * rate;
originalScore += detail[pid].score * rate;
}
return {
score, originalScore, detail,
@@ -555,9 +566,10 @@ const ledo = buildContestRule({
for (const pid of tdoc.pids) {
row.push({
type: 'record',
value: tsddict[pid]?.penaltyScore?.toString() || '',
value: ((tsddict[pid]?.penaltyScore || 0) * ((tdoc.score?.[pid] || 100) / 100)).toString(),
hover: tsddict[pid]?.ntry ? `-${tsddict[pid].ntry} (${Math.round(Math.max(0.7, 0.95 ** tsddict[pid].ntry) * 100)}%)` : '',
raw: tsddict[pid]?.rid,
score: tsddict[pid]?.score,
style: tsddict[pid]?.status === STATUS.STATUS_ACCEPTED && tsddict[pid]?.rid.getTimestamp().getTime() === meta?.first?.[pid]
? 'background-color: rgb(217, 240, 199);'
: undefined,
@@ -587,17 +599,18 @@ const homework = buildContestRule({
}
function penaltyScore(jdoc) {
const rate = (tdoc.score?.[jdoc.pid] || 100) / 100;
const exceedSeconds = Math.floor(
(jdoc.rid.getTimestamp().getTime() - tdoc.penaltySince.getTime()) / 1000,
);
if (exceedSeconds < 0) return jdoc.score;
if (exceedSeconds < 0) return rate * jdoc.score;
let coefficient = 1;
const keys = Object.keys(tdoc.penaltyRules).map(parseFloat).sort((a, b) => a - b);
for (const i of keys) {
if (i * 3600 <= exceedSeconds) coefficient = tdoc.penaltyRules[i];
else break;
}
return jdoc.score * coefficient;
return rate * jdoc.score * coefficient;
}
const detail = [];
for (const j in effective) {
@@ -691,7 +704,7 @@ const homework = buildContestRule({
} else {
row.push({
type: 'record',
score: tsddict[pid]?.penaltyScore || 0,
score: tsddict[pid]?.score,
value: colScore === colOriginalScore
? '{0}\n{1}'.format(colScore, colTimeStr)
: '{0} / {1}\n{2}'.format(colScore, colOriginalScore, colTimeStr),