From c4897b0abac52b99d1ac73058b101de42a51db80 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 11 Jul 2022 15:25:02 +0800 Subject: [PATCH] judge: fix testcase id generation --- packages/hydrojudge/package.json | 2 +- packages/hydrojudge/src/hosts/hydro.ts | 9 ++---- packages/hydrojudge/src/judge/default.ts | 6 ++-- packages/hydrojudge/src/judge/interactive.ts | 5 ++-- packages/hydrojudge/src/judge/objective.ts | 10 +++---- .../hydrojudge/src/judge/submit_answer.ts | 3 +- packages/hydrojudge/src/service.ts | 6 ++-- packages/utils/lib/common.ts | 28 ++++++++----------- packages/utils/package.json | 2 +- 9 files changed, 33 insertions(+), 38 deletions(-) diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 9dda20988..a8d970570 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.21.1", + "version": "2.22.0", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/hydrojudge/src/hosts/hydro.ts b/packages/hydrojudge/src/hosts/hydro.ts index 6824b5af0..4f549a2c1 100644 --- a/packages/hydrojudge/src/hosts/hydro.ts +++ b/packages/hydrojudge/src/hosts/hydro.ts @@ -133,14 +133,11 @@ class JudgeTask { await judge[type].judge(this, startPromise); } - next(data: Partial, id?: number) { - log.debug('Next: %d %o', id, data); + next(data: Partial) { + log.debug('Next: %d %o', data); data.key = 'next'; data.rid = new ObjectID(this.rid); - if (data.case) { - data.case.id ||= id; - data.case.message ||= ''; - } + if (data.case) data.case.message ||= ''; this.ws.send(JSON.stringify(data)); } diff --git a/packages/hydrojudge/src/judge/default.ts b/packages/hydrojudge/src/judge/default.ts index 847f68636..2a520aef0 100644 --- a/packages/hydrojudge/src/judge/default.ts +++ b/packages/hydrojudge/src/judge/default.ts @@ -27,6 +27,7 @@ function judgeCase(c: NormalizedCase, sid: string) { ) { ctx.next({ case: { + id: c.id, status: STATUS.STATUS_CANCELED, subtaskId: ctxSubtask.subtask.id, score: 0, @@ -35,7 +36,7 @@ function judgeCase(c: NormalizedCase, sid: string) { message: '', }, addProgress: 100 / ctx.config.count, - }, c.id); + }); return; } 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.next({ case: { + id: c.id, subtaskId: ctxSubtask.subtask.id, status, score, @@ -107,7 +109,7 @@ function judgeCase(c: NormalizedCase, sid: string) { message, }, addProgress: 100 / ctx.config.count, - }, c.id); + }); if ([STATUS.STATUS_WRONG_ANSWER, STATUS.STATUS_RUNTIME_ERROR].includes(status)) { const langConfig = ctx.getLang(ctx.lang); if (langConfig.analysis && !ctx.analysis) { diff --git a/packages/hydrojudge/src/judge/interactive.ts b/packages/hydrojudge/src/judge/interactive.ts index 2e556ad07..a05a8141b 100644 --- a/packages/hydrojudge/src/judge/interactive.ts +++ b/packages/hydrojudge/src/judge/interactive.ts @@ -63,6 +63,7 @@ function judgeCase(c: NormalizedCase) { ctx.next({ status: STATUS.STATUS_JUDGING, case: { + id: c.id, subtaskId: ctxSubtask.subtask.id, status, score, @@ -70,8 +71,8 @@ function judgeCase(c: NormalizedCase) { memory: memory_usage_kb, message, }, - progress: Math.floor((c.id * 100) / ctx.config.count), - }, c.id); + addProgress: 100 / ctx.config.count, + }); }; } diff --git a/packages/hydrojudge/src/judge/objective.ts b/packages/hydrojudge/src/judge/objective.ts index 729fb4ea5..8de5eee69 100644 --- a/packages/hydrojudge/src/judge/objective.ts +++ b/packages/hydrojudge/src/judge/objective.ts @@ -50,7 +50,7 @@ export async function judge({ score, message: 'Correct', }, - }, +caseId); + }); } else { totalStatus = STATUS.STATUS_WRONG_ANSWER; next({ @@ -61,7 +61,7 @@ export async function judge({ score: 0, message: 'Incorrect', }, - }, +caseId); + }); } } else { const stdAns = new Set(ansInfo[0] || []); @@ -79,7 +79,7 @@ export async function judge({ score, message: 'Correct', }, - }, +caseId); + }); } else if (partialCorrect) { totalScore += Math.floor(score / 2); totalStatus = STATUS.STATUS_WRONG_ANSWER; @@ -91,7 +91,7 @@ export async function judge({ score: Math.floor(score / 2), message: 'Partially Correct', }, - }, +caseId); + }); } else { totalStatus = STATUS.STATUS_WRONG_ANSWER; next({ @@ -102,7 +102,7 @@ export async function judge({ score: 0, message: 'Incorrect', }, - }, +caseId); + }); } } } diff --git a/packages/hydrojudge/src/judge/submit_answer.ts b/packages/hydrojudge/src/judge/submit_answer.ts index 699f58cdd..a0ca623e9 100644 --- a/packages/hydrojudge/src/judge/submit_answer.ts +++ b/packages/hydrojudge/src/judge/submit_answer.ts @@ -83,6 +83,7 @@ function judgeCase(c: NormalizedCase, sid: string) { if (ctxSubtask.status > STATUS.STATUS_ACCEPTED) ctx.failed[sid] = true; ctx.next({ case: { + id: c.id, status, score: 0, time: 0, @@ -90,7 +91,7 @@ function judgeCase(c: NormalizedCase, sid: string) { message, }, addProgress: 100 / ctx.config.count, - }, c.id); + }); }; } diff --git a/packages/hydrojudge/src/service.ts b/packages/hydrojudge/src/service.ts index a8ac4f3c0..5611bd91d 100644 --- a/packages/hydrojudge/src/service.ts +++ b/packages/hydrojudge/src/service.ts @@ -86,10 +86,10 @@ async function postInit() { } function getNext(that) { - return (data: Partial, id = 0) => { - logger.debug('Next: %d %o', id, data); + return (data: Partial) => { + logger.debug('Next: %d %o', data); data.rid = new ObjectID(that.rid); - if (data.case) data.case.id ||= id; + if (data.case) data.case.message ||= ''; _judge.next(data); }; } diff --git a/packages/utils/lib/common.ts b/packages/utils/lib/common.ts index 2a7d8c597..0e23dcbac 100644 --- a/packages/utils/lib/common.ts +++ b/packages/utils/lib/common.ts @@ -279,10 +279,7 @@ export function normalizeSubtasks( Math.max(100 - Math.sum(subtasks.map((i) => i.score || 0)), 0), subtasks.filter((i) => !i.score).length, ); - let id = 0; - let count = 0; - return subtasks.map((s) => { - id++; + return subtasks.map((s, id) => { s.cases.sort((a, b) => (a.id - b.id)); const score = s.score || subtaskScore.next().value as number; const caseScore = getScore( @@ -290,25 +287,22 @@ export function normalizeSubtasks( s.cases.filter((i) => !i.score).length, ); return { - id, + id: id + 1, type: 'min', if: [], ...s, score, time: parseTimeMS(s.time || time, !ignoreParseError), memory: parseMemoryMB(s.memory || memory, !ignoreParseError), - cases: s.cases.map((c) => { - count++; - return { - id: count, - ...c, - score: c.score || (s.type === 'sum' ? caseScore.next().value as number : score), - time: parseTimeMS(c.time || s.time || time, !ignoreParseError), - memory: parseMemoryMB(c.memory || s.memory || memory, !ignoreParseError), - input: c.input ? checkFile(c.input, 'Cannot find input file {0}.') : '/dev/null', - output: c.output ? checkFile(c.output, 'Cannot find output file {0}.') : '/dev/null', - }; - }) as NormalizedCase[], + cases: s.cases.map((c, index) => ({ + id: index + 1, + ...c, + score: c.score || (s.type === 'sum' ? caseScore.next().value as number : score), + time: parseTimeMS(c.time || s.time || time, !ignoreParseError), + memory: parseMemoryMB(c.memory || s.memory || memory, !ignoreParseError), + input: c.input ? checkFile(c.input, 'Cannot find input file {0}.') : '/dev/null', + output: c.output ? checkFile(c.output, 'Cannot find output file {0}.') : '/dev/null', + })) as NormalizedCase[], }; }); } diff --git a/packages/utils/package.json b/packages/utils/package.json index a2060ee43..4544b8a61 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/utils", - "version": "1.3.1", + "version": "1.3.2", "description": "hydrooj utils", "main": "package.json", "repository": "https://github.com/hydro-dev/Hydro.git",