resolver: add time display

This commit is contained in:
undefined committed 2024-11-18 10:53:47 +08:00
1 parent f177844336
commit 874411c018
2 files changed
+18 -8

No files matched your search

@@ -33,7 +33,14 @@ interface Props extends DisplaySettings {
data: ResolverInput; data: ResolverInput;
} }
function status(problem) { interface ProblemStatus {
old: number;
frozen: number;
pass: boolean;
time: number;
}
function status(problem: ProblemStatus) {
if (!problem) return 'untouched'; if (!problem) return 'untouched';
if (problem.pass) return 'ac'; if (problem.pass) return 'ac';
if (!problem.old && !problem.frozen) return 'untouched'; if (!problem.old && !problem.frozen) return 'untouched';
@@ -41,9 +48,9 @@ function status(problem) {
return 'failed'; return 'failed';
} }
function submissions(problem) { function submissions(problem: ProblemStatus) {
const st = status(problem); const st = status(problem);
if (st === 'ac') { return `${problem.old}`; } if (st === 'ac') { return `${problem.old} / ${problem.time}`; }
if (st === 'frozen') { return `${problem.old}+${problem.frozen}`; } if (st === 'frozen') { return `${problem.old}+${problem.frozen}`; }
if (st === 'failed') { return problem.old; } if (st === 'failed') { return problem.old; }
return String.fromCharCode('A'.charCodeAt(0) + problem.index); return String.fromCharCode('A'.charCodeAt(0) + problem.index);
@@ -80,6 +87,7 @@ export function start(data: ResolverInput, options: DisplaySettings) {
else { else {
if (submission.verdict === 'AC') { if (submission.verdict === 'AC') {
problem.pass = true; problem.pass = true;
problem.time = Math.floor(submission.time / 60);
team.score += 1; team.score += 1;
team.penalty += submission.time + problem.old * 20 * 60; team.penalty += submission.time + problem.old * 20 * 60;
} }
@@ -129,16 +137,17 @@ export function start(data: ResolverInput, options: DisplaySettings) {
}, },
async revealProblem(teamId: string, problemId: string) { async revealProblem(teamId: string, problemId: string) {
const team = teams.find((i) => i.id === teamId); const team = teams.find((i) => i.id === teamId);
const problem = team?.problems.find((i) => i.id === problemId); const problem: ProblemStatus = team?.problems.find((i) => i.id === problemId);
if (!team || !problem) return; if (!team || !problem) return;
if (allAc.find((s) => s.team === teamId && s.problem === problemId)) { if (allAc.find((s) => s.team === teamId && s.problem === problemId)) {
const sub = allSubmissions.filter((s) => s.team === teamId && s.problem === problemId); const sub = allSubmissions.filter((s) => s.team === teamId && s.problem === problemId);
let penalty = 0; let penalty = 0;
for (const s of sub) { for (const s of sub) {
problem.old++;
if (s.verdict !== 'AC') { if (s.verdict !== 'AC') {
penalty += 20 * 60; penalty += 20 * 60;
problem.old++;
} else { } else {
problem.time = Math.floor(s.time / 60);
penalty += s.time; penalty += s.time;
break; break;
} }
@@ -179,7 +188,7 @@ export function start(data: ResolverInput, options: DisplaySettings) {
const team = clone[orders[i]]; const team = clone[orders[i]];
queueOperations('highlightTeam', team.id, i); queueOperations('highlightTeam', team.id, i);
for (const pinfo of data.problems) { for (const pinfo of data.problems) {
const problem = team.problems.find((idx) => idx.id === pinfo.id); const problem: ProblemStatus = team.problems.find((idx) => idx.id === pinfo.id);
if (!problem || !problem.frozen || problem.pass) continue; if (!problem || !problem.frozen || problem.pass) continue;
queueOperations('highlightProblem', pinfo.id); queueOperations('highlightProblem', pinfo.id);
queueOperations('revealProblem', team.id, pinfo.id); queueOperations('revealProblem', team.id, pinfo.id);
@@ -188,10 +197,11 @@ export function start(data: ResolverInput, options: DisplaySettings) {
const sub = allSubmissions.filter((s) => s.team === team.id && s.problem === problem.id); const sub = allSubmissions.filter((s) => s.team === team.id && s.problem === problem.id);
let penalty = 0; let penalty = 0;
for (const s of sub) { for (const s of sub) {
problem.old++;
if (s.verdict !== 'AC') { if (s.verdict !== 'AC') {
penalty += 20 * 60; penalty += 20 * 60;
problem.old++;
} else { } else {
problem.time = Math.floor(s.time / 60);
penalty += s.time; penalty += s.time;
break; break;
} }
+1 -1
View File
@@ -39,7 +39,7 @@ export function apply(ctx: Context) {
ctx.inject(['scoreboard'], ({ scoreboard }) => { ctx.inject(['scoreboard'], ({ scoreboard }) => {
scoreboard.addView('resolver-tiny', 'Resolver(Tiny)', { tdoc: 'tdoc' }, { scoreboard.addView('resolver-tiny', 'Resolver(Tiny)', { tdoc: 'tdoc' }, {
async display({ tdoc }) { async display({ tdoc }) {
if (!this.user.own(tdoc)) this.checkPerm(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD); if (!this.user.own(tdoc) && ContestModel.isLocked(tdoc)) this.checkPerm(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
const teams = await ContestModel.getMultiStatus(tdoc.domainId, { docId: tdoc.docId }).toArray(); const teams = await ContestModel.getMultiStatus(tdoc.domainId, { docId: tdoc.docId }).toArray();
const udict = await UserModel.getList(tdoc.domainId, teams.map((i) => i.uid)); const udict = await UserModel.getList(tdoc.domainId, teams.map((i) => i.uid));
const teamIds: Record<number, number> = {}; const teamIds: Record<number, number> = {};