Challenge Judgement

This commit is contained in:
2023-12-13 23:56:01 +08:00
parent 961508449f
commit 76a95b28c2
6 changed files with 146 additions and 26 deletions

View File

@@ -0,0 +1,10 @@
import { runProgramChallenge } from "./programming.ts";
export async function runChallenge(challenge: any, problem: any, cases: any) {
switch (problem.type) {
case "programming":
return await runProgramChallenge(challenge, problem, cases)
default:
throw new Error("Unsupported problem type.")
}
}

View File

@@ -0,0 +1,40 @@
export async function runProgramChallenge(challenge: any, problem: any, cases: any[]) {
const languages: { [id: string]: number } = {
"cpp": 54
};
const code = challenge.answers?.code;
const language = challenge.answers?.language;
if (!code || !language || !cases || Object.keys(languages).indexOf(language) < 0) {
return {
status: "skipped",
submissions: null
};
}
const idx = languages[language];
const submissions = cases.map((item: any) => {
return {
"language_id": idx,
"source_code": challenge.answers?.code,
"expected_output": item?.stdout,
"stdin": code
};
});
const resp = await fetch(
Deno.env.get("JUDGE0_ENDPOINT") + "/submissions/batch",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ submissions })
}
);
const result = await resp.json();
return {
status: "judging",
submissions: result
};
}