Browse Source

Add support for answer-submission problems.

pull/6/head
t123yh 7 years ago
parent
commit
0ed001620c
  1. 7
      libs/judger.js
  2. 2
      models/judge_state.js
  3. 4
      modules/problem.js
  4. 2
      modules/submission.js

7
libs/judger.js

@ -3,10 +3,12 @@ const enums = require('./enums'),
url = require('url'); url = require('url');
module.exports.judge = async function (judge_state, priority) { module.exports.judge = async function (judge_state, priority) {
let type, param; let type, param, extraFile = null;
switch (judge_state.problem.type) { switch (judge_state.problem.type) {
case 'submit-answer': case 'submit-answer':
type = enums.ProblemType.AnswerSubmission; type = enums.ProblemType.AnswerSubmission;
param = null;
extraFile = 'static/uploads/answer/' + judge_state.code;
break; break;
case 'interaction': case 'interaction':
type = enums.ProblemType.Interaction; type = enums.ProblemType.Interaction;
@ -25,11 +27,14 @@ module.exports.judge = async function (judge_state, priority) {
} }
const req = { const req = {
content: {
taskId: judge_state.id, taskId: judge_state.id,
testData: judge_state.problem.id.toString(), testData: judge_state.problem.id.toString(),
type: type, type: type,
priority: priority, priority: priority,
param: param param: param
},
extraFileLocation: extraFile
}; };
await rp(url.resolve(syzoj.config.judge_server_addr, "/daemon/task"), { await rp(url.resolve(syzoj.config.judge_server_addr, "/daemon/task"), {

2
models/judge_state.js

@ -82,7 +82,7 @@ class JudgeState extends Model {
static async create(val) { static async create(val) {
return JudgeState.fromRecord(JudgeState.model.build(Object.assign({ return JudgeState.fromRecord(JudgeState.model.build(Object.assign({
code: '', code: '',
language: '', language: null,
user_id: 0, user_id: 0,
problem_id: 0, problem_id: 0,
submit_time: parseInt((new Date()).getTime() / 1000), submit_time: parseInt((new Date()).getTime() / 1000),

4
modules/problem.js

@ -595,7 +595,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
judge_state = await JudgeState.create({ judge_state = await JudgeState.create({
code: file.md5, code: file.md5,
max_memory: size, max_memory: size,
language: '', language: null,
user_id: res.locals.user.id, user_id: res.locals.user.id,
problem_id: req.params.id problem_id: req.params.id
}); });
@ -640,6 +640,8 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
try { try {
await Judger.judge(judge_state, contest_id ? 3 : 2); await Judger.judge(judge_state, contest_id ? 3 : 2);
} catch (err) { } catch (err) {
judge_state.status = "System Error";
await judge_state.save();
throw new ErrorMessage(`无法开始评测:${err.toString()}`); throw new ErrorMessage(`无法开始评测:${err.toString()}`);
} }

2
modules/submission.js

@ -32,7 +32,7 @@ const getSubmissionInfo = (s) => ({
userId: s.user_id, userId: s.user_id,
problemName: s.problem.title, problemName: s.problem.title,
problemId: s.problem.id, problemId: s.problem.id,
language: s.language != null ? syzoj.config.languages[s.language].show : null, language: (s.language != null && s.language !== '') ? syzoj.config.languages[s.language].show : null,
codeSize: s.allowedSeeCode ? syzoj.utils.formatSize(s.code.length) : null, codeSize: s.allowedSeeCode ? syzoj.utils.formatSize(s.code.length) : null,
submitTime: syzoj.utils.formatDate(s.submit_time), submitTime: syzoj.utils.formatDate(s.submit_time),
}); });

Loading…
Cancel
Save