Commit 2eb7aeed authored by Yechang's avatar Yechang
Browse files

feat(judge): supporting java

parent 4d2ebedd
Loading
Loading
Loading
Loading
Loading
+30 −5
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import { db } from '.';
import _ from 'lodash';
import { z } from 'zod';
import { redis } from '../redis';
import { judgementArgsSchema } from '../oj/args';

type CreateSubmissionSchema = {
	problemId: number;
@@ -31,16 +32,40 @@ export const createSubmission = async ({
		where: { id: volumeId }
	})
	if (!_.isNil(file)) {
		const language = file.filename.endsWith("cpp") ? "cpp" : "java"
		const judgementArgs = judgementArgsSchema.parse(submission.problem.judgementArgs)

		let { memoryLimit, timeLimit } = judgementArgs
		const spec = judgementArgs[language]
		if (!_.isNil(spec)) {
			memoryLimit = spec.memoryLimit || memoryLimit
			timeLimit = spec.timeLimit || timeLimit
		}
		let args: { memoryLimit: number, timeLimit: number, compileAndRunOptions?: {} } = {
			memoryLimit, timeLimit
		}

		if (language === 'cpp') {
			if (spec && "compileAndRunOptions" in spec) {
				args.compileAndRunOptions = spec.compileAndRunOptions
			} else {
				args.compileAndRunOptions = {
					std: "c++11",
					O: "2",
					m: "64",
				}
			}
		}
		const task = await db.task.create({
			data: {
				submissionId: submission.id,
				fileKey: volumeId,
				language: file.filename.endsWith("cpp") ? "cpp" : "java",
				language,
				testdataKey: submission.problem.testdata || "",
				args: z.object({
					memoryLimit: z.number(),
					timeLimit: z.number()
				}).parse(submission.problem.judgementArgs)
				args: {
					subtasks: judgementArgs.subtasks,
					...args
				}
			}
		})
		const hash = nanoid()
+34 −0
Original line number Diff line number Diff line
import z from "zod"

export const judgementArgsSchema = z.object({
    memoryLimit: z.number(),
    timeLimit: z.number(),
    subtasks: z.array(
        z.object({
            testcases: z.array(z.object({
                inputFile: z.string(),
                outputFile: z.string(),
            })),
            scoringType: z.union([
                z.literal("Sum"),
                z.literal("GroupMin"),
                z.literal("GroupMul")
            ]),
            points: z.number()
        })
    ),
    java: z.object({
        memoryLimit: z.number(),
        timeLimit: z.number(),
    }).partial().optional(),
    cpp: z.object({
        memoryLimit: z.number(),
        timeLimit: z.number(),
        compileAndRunOptions: z
            .object({
                std: z.string(),
                O: z.string(),
                m: z.string(),
            })
    }).partial().optional()
})
 No newline at end of file