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');
module.exports.judge = async function (judge_state, priority) {
let type, param;
let type, param, extraFile = null;
switch (judge_state.problem.type) {
case 'submit-answer':
type = enums.ProblemType.AnswerSubmission;
param = null;
extraFile = 'static/uploads/answer/' + judge_state.code;
break;
case 'interaction':
type = enums.ProblemType.Interaction;
@ -25,11 +27,14 @@ module.exports.judge = async function (judge_state, priority) {
}
const req = {
content: {
taskId: judge_state.id,
testData: judge_state.problem.id.toString(),
type: type,
priority: priority,
param: param
},
extraFileLocation: extraFile
};
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) {
return JudgeState.fromRecord(JudgeState.model.build(Object.assign({
code: '',
language: '',
language: null,
user_id: 0,
problem_id: 0,
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({
code: file.md5,
max_memory: size,
language: '',
language: null,
user_id: res.locals.user.id,
problem_id: req.params.id
});
@ -640,6 +640,8 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
try {
await Judger.judge(judge_state, contest_id ? 3 : 2);
} catch (err) {
judge_state.status = "System Error";
await judge_state.save();
throw new ErrorMessage(`无法开始评测:${err.toString()}`);
}

2
modules/submission.js

@ -32,7 +32,7 @@ const getSubmissionInfo = (s) => ({
userId: s.user_id,
problemName: s.problem.title,
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,
submitTime: syzoj.utils.formatDate(s.submit_time),
});

Loading…
Cancel
Save