From bb1d62dfae42a293c60b5c8cfbb6e8afb712e9b8 Mon Sep 17 00:00:00 2001 From: Shine Chang Date: Mon, 2 Dec 2024 13:09:26 -0800 Subject: [PATCH] (wip) --- .../src/services/grading.services.ts | 23 ++++++------ .../src/services/result.services.ts | 35 +++++++++++-------- packages/types/src/types/problem.types.ts | 12 +++---- packages/types/src/types/submission.types.ts | 4 --- .../src/services/polygon.services.ts | 4 +-- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/packages/judge-daemon/src/services/grading.services.ts b/packages/judge-daemon/src/services/grading.services.ts index d811f5ff..fd5ee6ab 100644 --- a/packages/judge-daemon/src/services/grading.services.ts +++ b/packages/judge-daemon/src/services/grading.services.ts @@ -33,16 +33,15 @@ export async function gradeSubmission ({ task, boxId }: { task: GradingTask, box command = command.replaceAll('{binary_path}', config.binaryFile) console.log('cmd: ', command); - const sandboxResult = await runInSandbox( - { - task: { - command, - constraints: task.constraints, - inputPath: 'in.txt', - outputPath: 'out.txt' - }, - boxId - }) + const sandboxResult = await runInSandbox({ + task: { + command, + constraints: task.constraints, + inputPath: 'in.txt', + outputPath: 'out.txt' + }, + boxId + }) //return new Promise((resolve, reject) => resolve({ message: '', status: GradingStatus.Accepted, memory: 1, time: 1, wallTime: 1})); @@ -52,8 +51,7 @@ export async function gradeSubmission ({ task, boxId }: { task: GradingTask, box const { time, wallTime, memory } = sandboxResult try { const command = `./checker in.txt ans.txt out.txt`; - const result = await runInSandbox( - { + const result = await runInSandbox({ task: { command, constraints: { @@ -70,6 +68,7 @@ export async function gradeSubmission ({ task, boxId }: { task: GradingTask, box throw result const verdict = (await fs.readFile(verdictPath)).toString() + console.log('verdict: ', verdict); const passed = verdict.startsWith('ok'); console.log('checker: ', command); diff --git a/packages/result-handler/src/services/result.services.ts b/packages/result-handler/src/services/result.services.ts index a96c5d7b..2855cf19 100644 --- a/packages/result-handler/src/services/result.services.ts +++ b/packages/result-handler/src/services/result.services.ts @@ -9,6 +9,7 @@ export async function handleCompileResult (compileResult: CompilingResult, submi if (submission.status === SubmissionStatus.Compiling) { if (compileResult.status === CompilingStatus.Succeeded) { const { problemId, domainId, contestId } = submission + let problem: Problem = contestId == null ? await fetchDomainProblem({ problemId, domainId }) : await fetchContestProblem({ problemId, contestId }) @@ -23,7 +24,7 @@ export async function handleCompileResult (compileResult: CompilingResult, submi return } - const submissionTestcases: Array<{ points: number, input: { name: string, versionId: string }, output: { name: string, versionId: string } }> = [] + const submissionTestcases: Array<{ input: { name: string, versionId: string }, output: { name: string, versionId: string } }> = [] problem.testcases.forEach((testcase, index) => { const task: GradingTask = { @@ -49,7 +50,7 @@ export async function handleCompileResult (compileResult: CompilingResult, submi language: submission.language } rabbitMQ.publish(judgerExchange, judgerTasksKey, Buffer.from(JSON.stringify(task))) - submissionTestcases.push({ points: testcase.points, input: testcase.input, output: testcase.output }) + submissionTestcases.push({ input: testcase.input, output: testcase.output }) }) await submissionCollection.updateOne({ id: submissionId }, { @@ -72,9 +73,14 @@ export async function handleCompileResult (compileResult: CompilingResult, submi export async function completeGrading (submissionId: string, log?: string): Promise { const submission = await fetchSubmission({ submissionId }) - - if (submission.status !== SubmissionStatus.Compiling && - submission.status !== SubmissionStatus.Grading) { + const { problemId, domainId, contestId, teamId, status, createdAt } = submission; + const { partials } = contestId == null ? + await fetchDomainProblem({ problemId, domainId }) : + await fetchContestProblem({ problemId, contestId }) + + // Unexpected status + if (status !== SubmissionStatus.Compiling && + status !== SubmissionStatus.Grading) { console.error('completeGrading recieved unexpected status: ', submission.status); return; } @@ -85,17 +91,21 @@ export async function completeGrading (submissionId: string, log?: string): Prom await submissionCollection.updateOne({ id: submissionId }, { $set: { status: SubmissionStatus.Terminated, log } }) return; } - - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands - const score = submission.testcases.reduce((accumulator: number, testcase) => accumulator + (testcase.score ?? 0), 0) + const testcases = submission.testcases; + + // Calculate score + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands + const passes = testcases.reduce((t, testcase) => t + (testcase.result!).status == GradingStatus.Accepted ? 1 : 0, 1); + const score = partials ? + passes / testcases.length * 100 : + (passes == testcases.length ? 100 : 0); + await submissionCollection.updateOne({ id: submissionId }, { $set: { score, status: SubmissionStatus.Graded }, - $unset: { - gradedCases: '' - } + $unset: { gradedCases: '' } }) // Skip score update if testing submission @@ -124,16 +134,13 @@ export async function handleGradingResult (gradingResult: GradingResult, submiss if (submission.testcases[testcaseIndex] == null) { throw new NotFoundError('No testcase found at the given index') } - const score = gradingResult.status === GradingStatus.Accepted ? submission.testcases[testcaseIndex].points : 0 submission.testcases[testcaseIndex].result = gradingResult await submissionCollection.updateOne({ id: submissionId }, { $set: { [`testcases.${testcaseIndex}.result`]: gradingResult, - [`testcases.${testcaseIndex}.score`]: score }, $inc: { gradedCases: 1, - score } }) diff --git a/packages/types/src/types/problem.types.ts b/packages/types/src/types/problem.types.ts index a088f929..dc27b309 100644 --- a/packages/types/src/types/problem.types.ts +++ b/packages/types/src/types/problem.types.ts @@ -9,16 +9,15 @@ export const NewProblemSchema = Type.Object({ inputFormat: Type.String(), outputFormat: Type.String(), constraints: ConstraintsSchema, + partials: Type.Boolean(), samples: Type.Array( Type.Object({ input: Type.String(), output: Type.String() }) ), - testcases: Type.Optional(Type.Array( + testcases: Type.Array( Type.Object({ input: Type.Object({ name: Type.String(), versionId: Type.String() }), output: Type.Object({ name: Type.String(), versionId: Type.String() }), - points: Type.Number() })) - ) }, { additionalProperties: false }) export type NewProblem = Static @@ -30,16 +29,15 @@ export const ProblemSchema = Type.Object({ inputFormat: Type.String(), outputFormat: Type.String(), constraints: ConstraintsSchema, + partials: Type.Boolean(), samples: Type.Array( Type.Object({ input: Type.String(), output: Type.String() }) ), - testcases: Type.Optional(Type.Array( + testcases: Type.Array( Type.Object({ input: Type.Object({ name: Type.String(), versionId: Type.String() }), output: Type.Object({ name: Type.String(), versionId: Type.String() }), - points: Type.Number() - })) - ), + })), checker: Type.Optional(Type.Object({ name: Type.String(), versionId: Type.String() })), id: Type.String(), domainId: Type.String() diff --git a/packages/types/src/types/submission.types.ts b/packages/types/src/types/submission.types.ts index 07c01eb0..36319a08 100644 --- a/packages/types/src/types/submission.types.ts +++ b/packages/types/src/types/submission.types.ts @@ -39,8 +39,6 @@ const GradingSubmissionSchema = Type.Intersect([BaseSubmissionSchema, Type.Objec status: Type.Literal(SubmissionStatus.Grading), gradedCases: Type.Number(), testcases: Type.Array(Type.Object({ - points: Type.Number(), - score: Type.Optional(Type.Number()), result: Type.Optional(GradingResultSchema) })) })]) @@ -59,8 +57,6 @@ const GradedSubmissionSchema = Type.Intersect([BaseSubmissionSchema, Type.Object status: Type.Literal(SubmissionStatus.Graded), score: Type.Number(), testcases: Type.Array(Type.Object({ - points: Type.Number(), - score: Type.Number(), result: GradingResultSchema })) })]) diff --git a/packages/upload-server/src/services/polygon.services.ts b/packages/upload-server/src/services/polygon.services.ts index 1ee077a8..d73d1122 100644 --- a/packages/upload-server/src/services/polygon.services.ts +++ b/packages/upload-server/src/services/polygon.services.ts @@ -58,7 +58,8 @@ export async function uploadPolygon ({ domainId, replaceId, archive }: { domainI inputFormat: statement.input, outputFormat: statement.output, samples: [], - constraints + constraints, + partials: false } // Extract Testcases @@ -80,7 +81,6 @@ export async function uploadPolygon ({ domainId, replaceId, archive }: { domainI problem.testcases.push({ input, output, - points: 100 / test_n }) } console.log('problem: ', problem)