Skip to content

Commit

Permalink
(wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
shine00chang committed Dec 2, 2024
1 parent 3b7dab8 commit bb1d62d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
23 changes: 11 additions & 12 deletions packages/judge-daemon/src/services/grading.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}));

Expand All @@ -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: {
Expand All @@ -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);
Expand Down
35 changes: 21 additions & 14 deletions packages/result-handler/src/services/result.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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 = {
Expand All @@ -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 }, {
Expand All @@ -72,9 +73,14 @@ export async function handleCompileResult (compileResult: CompilingResult, submi

export async function completeGrading (submissionId: string, log?: string): Promise<void> {
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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
})

Expand Down
12 changes: 5 additions & 7 deletions packages/types/src/types/problem.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof NewProblemSchema>
Expand All @@ -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()
Expand Down
4 changes: 0 additions & 4 deletions packages/types/src/types/submission.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}))
})])
Expand All @@ -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
}))
})])
Expand Down
4 changes: 2 additions & 2 deletions packages/upload-server/src/services/polygon.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit bb1d62d

Please sign in to comment.