judge: fix testcase id generation

This commit is contained in:
undefined committed 2022-07-11 15:25:02 +08:00
1 parent 3edc425a52
commit c4897b0aba
9 files changed
+33 -38

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "@hydrooj/hydrojudge", "name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js", "bin": "bin/hydrojudge.js",
"version": "2.21.1", "version": "2.22.0",
"main": "package.json", "main": "package.json",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",
+3 -6
View File
@@ -133,14 +133,11 @@ class JudgeTask {
await judge[type].judge(this, startPromise); await judge[type].judge(this, startPromise);
} }
next(data: Partial<JudgeResultBody>, id?: number) { next(data: Partial<JudgeResultBody>) {
log.debug('Next: %d %o', id, data); log.debug('Next: %d %o', data);
data.key = 'next'; data.key = 'next';
data.rid = new ObjectID(this.rid); data.rid = new ObjectID(this.rid);
if (data.case) { if (data.case) data.case.message ||= '';
data.case.id ||= id;
data.case.message ||= '';
}
this.ws.send(JSON.stringify(data)); this.ws.send(JSON.stringify(data));
} }
+4 -2
View File
@@ -27,6 +27,7 @@ function judgeCase(c: NormalizedCase, sid: string) {
) { ) {
ctx.next({ ctx.next({
case: { case: {
id: c.id,
status: STATUS.STATUS_CANCELED, status: STATUS.STATUS_CANCELED,
subtaskId: ctxSubtask.subtask.id, subtaskId: ctxSubtask.subtask.id,
score: 0, score: 0,
@@ -35,7 +36,7 @@ function judgeCase(c: NormalizedCase, sid: string) {
message: '', message: '',
}, },
addProgress: 100 / ctx.config.count, addProgress: 100 / ctx.config.count,
}, c.id); });
return; return;
} }
const { filename } = ctx.config; const { filename } = ctx.config;
@@ -99,6 +100,7 @@ function judgeCase(c: NormalizedCase, sid: string) {
ctx.total_memory_usage_kb = Math.max(ctx.total_memory_usage_kb, memory_usage_kb); ctx.total_memory_usage_kb = Math.max(ctx.total_memory_usage_kb, memory_usage_kb);
ctx.next({ ctx.next({
case: { case: {
id: c.id,
subtaskId: ctxSubtask.subtask.id, subtaskId: ctxSubtask.subtask.id,
status, status,
score, score,
@@ -107,7 +109,7 @@ function judgeCase(c: NormalizedCase, sid: string) {
message, message,
}, },
addProgress: 100 / ctx.config.count, addProgress: 100 / ctx.config.count,
}, c.id); });
if ([STATUS.STATUS_WRONG_ANSWER, STATUS.STATUS_RUNTIME_ERROR].includes(status)) { if ([STATUS.STATUS_WRONG_ANSWER, STATUS.STATUS_RUNTIME_ERROR].includes(status)) {
const langConfig = ctx.getLang(ctx.lang); const langConfig = ctx.getLang(ctx.lang);
if (langConfig.analysis && !ctx.analysis) { if (langConfig.analysis && !ctx.analysis) {
+3 -2
View File
@@ -63,6 +63,7 @@ function judgeCase(c: NormalizedCase) {
ctx.next({ ctx.next({
status: STATUS.STATUS_JUDGING, status: STATUS.STATUS_JUDGING,
case: { case: {
id: c.id,
subtaskId: ctxSubtask.subtask.id, subtaskId: ctxSubtask.subtask.id,
status, status,
score, score,
@@ -70,8 +71,8 @@ function judgeCase(c: NormalizedCase) {
memory: memory_usage_kb, memory: memory_usage_kb,
message, message,
}, },
progress: Math.floor((c.id * 100) / ctx.config.count), addProgress: 100 / ctx.config.count,
}, c.id); });
}; };
} }
+5 -5
View File
@@ -50,7 +50,7 @@ export async function judge({
score, score,
message: 'Correct', message: 'Correct',
}, },
}, +caseId); });
} else { } else {
totalStatus = STATUS.STATUS_WRONG_ANSWER; totalStatus = STATUS.STATUS_WRONG_ANSWER;
next({ next({
@@ -61,7 +61,7 @@ export async function judge({
score: 0, score: 0,
message: 'Incorrect', message: 'Incorrect',
}, },
}, +caseId); });
} }
} else { } else {
const stdAns = new Set(ansInfo[0] || []); const stdAns = new Set(ansInfo[0] || []);
@@ -79,7 +79,7 @@ export async function judge({
score, score,
message: 'Correct', message: 'Correct',
}, },
}, +caseId); });
} else if (partialCorrect) { } else if (partialCorrect) {
totalScore += Math.floor(score / 2); totalScore += Math.floor(score / 2);
totalStatus = STATUS.STATUS_WRONG_ANSWER; totalStatus = STATUS.STATUS_WRONG_ANSWER;
@@ -91,7 +91,7 @@ export async function judge({
score: Math.floor(score / 2), score: Math.floor(score / 2),
message: 'Partially Correct', message: 'Partially Correct',
}, },
}, +caseId); });
} else { } else {
totalStatus = STATUS.STATUS_WRONG_ANSWER; totalStatus = STATUS.STATUS_WRONG_ANSWER;
next({ next({
@@ -102,7 +102,7 @@ export async function judge({
score: 0, score: 0,
message: 'Incorrect', message: 'Incorrect',
}, },
}, +caseId); });
} }
} }
} }
@@ -83,6 +83,7 @@ function judgeCase(c: NormalizedCase, sid: string) {
if (ctxSubtask.status > STATUS.STATUS_ACCEPTED) ctx.failed[sid] = true; if (ctxSubtask.status > STATUS.STATUS_ACCEPTED) ctx.failed[sid] = true;
ctx.next({ ctx.next({
case: { case: {
id: c.id,
status, status,
score: 0, score: 0,
time: 0, time: 0,
@@ -90,7 +91,7 @@ function judgeCase(c: NormalizedCase, sid: string) {
message, message,
}, },
addProgress: 100 / ctx.config.count, addProgress: 100 / ctx.config.count,
}, c.id); });
}; };
} }
+3 -3
View File
@@ -86,10 +86,10 @@ async function postInit() {
} }
function getNext(that) { function getNext(that) {
return (data: Partial<JudgeResultBody>, id = 0) => { return (data: Partial<JudgeResultBody>) => {
logger.debug('Next: %d %o', id, data); logger.debug('Next: %d %o', data);
data.rid = new ObjectID(that.rid); data.rid = new ObjectID(that.rid);
if (data.case) data.case.id ||= id; if (data.case) data.case.message ||= '';
_judge.next(data); _judge.next(data);
}; };
} }
+11 -17
View File
@@ -279,10 +279,7 @@ export function normalizeSubtasks(
Math.max(100 - Math.sum(subtasks.map((i) => i.score || 0)), 0), Math.max(100 - Math.sum(subtasks.map((i) => i.score || 0)), 0),
subtasks.filter((i) => !i.score).length, subtasks.filter((i) => !i.score).length,
); );
let id = 0; return subtasks.map((s, id) => {
let count = 0;
return subtasks.map((s) => {
id++;
s.cases.sort((a, b) => (a.id - b.id)); s.cases.sort((a, b) => (a.id - b.id));
const score = s.score || subtaskScore.next().value as number; const score = s.score || subtaskScore.next().value as number;
const caseScore = getScore( const caseScore = getScore(
@@ -290,25 +287,22 @@ export function normalizeSubtasks(
s.cases.filter((i) => !i.score).length, s.cases.filter((i) => !i.score).length,
); );
return { return {
id, id: id + 1,
type: 'min', type: 'min',
if: [], if: [],
...s, ...s,
score, score,
time: parseTimeMS(s.time || time, !ignoreParseError), time: parseTimeMS(s.time || time, !ignoreParseError),
memory: parseMemoryMB(s.memory || memory, !ignoreParseError), memory: parseMemoryMB(s.memory || memory, !ignoreParseError),
cases: s.cases.map((c) => { cases: s.cases.map((c, index) => ({
count++; id: index + 1,
return { ...c,
id: count, score: c.score || (s.type === 'sum' ? caseScore.next().value as number : score),
...c, time: parseTimeMS(c.time || s.time || time, !ignoreParseError),
score: c.score || (s.type === 'sum' ? caseScore.next().value as number : score), memory: parseMemoryMB(c.memory || s.memory || memory, !ignoreParseError),
time: parseTimeMS(c.time || s.time || time, !ignoreParseError), input: c.input ? checkFile(c.input, 'Cannot find input file {0}.') : '/dev/null',
memory: parseMemoryMB(c.memory || s.memory || memory, !ignoreParseError), output: c.output ? checkFile(c.output, 'Cannot find output file {0}.') : '/dev/null',
input: c.input ? checkFile(c.input, 'Cannot find input file {0}.') : '/dev/null', })) as NormalizedCase[],
output: c.output ? checkFile(c.output, 'Cannot find output file {0}.') : '/dev/null',
};
}) as NormalizedCase[],
}; };
}); });
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/utils", "name": "@hydrooj/utils",
"version": "1.3.1", "version": "1.3.2",
"description": "hydrooj utils", "description": "hydrooj utils",
"main": "package.json", "main": "package.json",
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",