Skip to content

Commit c74c246

Browse files
committed
feat: mysql
1 parent 689616f commit c74c246

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

config.js

+5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ exports = module.exports = {
9595
SOURCE_FILE: 'Main.kt',
9696
CPU_SHARE: "1.2",
9797
MEM_LIMIT: '500m',
98+
},
99+
'mysql': {
100+
SOURCE_FILE: 'script.sql',
101+
CPU_SHARE: "1.2",
102+
MEM_LIMIT: '500m',
98103
}
99104
}
100105
}

src/tasks/scenario.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ export class Scenario {
88
throw new Error("Not Implemented")
99
}
1010
run(currentJobDir: string, job: Job) {
11-
const LANG_CONFIG = config.LANGS[job.lang]
12-
return exec(`docker run \\
11+
const LANG_CONFIG = config.LANGS[job.lang];
12+
const uLimit = job.lang === "mysql" ? "" : "--ulimit nofile=64:64";
13+
return exec(
14+
`docker run \\
1315
--cpus="${LANG_CONFIG.CPU_SHARE}" \\
1416
--memory="${LANG_CONFIG.MEM_LIMIT}" \\
15-
--ulimit nofile=64:64 \\
1617
--rm \\
18+
${uLimit ? `${uLimit}` : ""} \\
1719
-v "${currentJobDir}":/usr/src/runbox \\
1820
-w /usr/src/runbox \\
1921
codingblocks/judge-worker-${job.lang} \\
2022
/bin/judge.sh
21-
`)
23+
`,
24+
);
2225
}
2326
result(currentJobDir: string, job: Job): Promise<Result> {
2427
throw new Error("Not Implemented")

src/tasks/scenarios/submission.ts

+44-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,50 @@ export default class SubmissionScenario extends Scenario {
5858
const runOutputFile = path.join(currentTestcasePath, 'run.stdout')
5959
const expectedOutputFile = path.join(currentTestcasePath, 'stdout')
6060

61-
const diff = exec(`
62-
diff -b -B -a --suppress-common-lines --speed-large-files ${runOutputFile} ${expectedOutputFile}
63-
`)
64-
let score = diff.code === 0 ? 100 : 0
61+
let score = 0;
62+
switch(job.lang) {
63+
case 'mysql': {
64+
console.log('inside job kang mysql')
65+
66+
const fromEntries = (entries) => {
67+
return entries.reduce((acc, [key, value]) => {
68+
acc[key] = value;
69+
return acc;
70+
}, {});
71+
};
72+
73+
const normalizeObject = (obj) =>
74+
fromEntries(Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)));
75+
76+
const compare = (arr1, arr2) => {
77+
if (arr1.length !== arr2.length) return false;
78+
79+
const sortedArr1 = arr1.map(normalizeObject).sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
80+
const sortedArr2 = arr2.map(normalizeObject).sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
81+
82+
return JSON.stringify(sortedArr1) === JSON.stringify(sortedArr2);
83+
};
84+
const runOutput = fs.readFileSync(runOutputFile, {
85+
encoding: 'utf-8'
86+
});
87+
const expectedOutput = fs.readFileSync(expectedOutputFile, {
88+
encoding: 'utf-8'
89+
});
90+
try {
91+
score = compare(JSON.parse(runOutput), JSON.parse(expectedOutput)) ? 100 : 0;
92+
} catch(err) {
93+
// unable to parse json
94+
}
95+
break;
96+
}
97+
default: {
98+
const diff = exec(`
99+
diff -b -B -a --suppress-common-lines --speed-large-files ${runOutputFile} ${expectedOutputFile}
100+
`);
101+
score = diff.code === 0 ? 100 : 0;
102+
break;
103+
}
104+
}
65105

66106
let result = new Array(
67107
+code === 143 && "TLE",

0 commit comments

Comments
 (0)