Browse Source

Judge v3

pull/6/head
t123yh 7 years ago
parent
commit
a1b5ad0ddd
  1. 1
      config-example.json
  2. 7
      models/judge_state.js
  3. 24
      modules/api_v2.js
  4. 16
      modules/problem.js

1
config-example.json

@ -151,5 +151,6 @@
}
],
"session_secret": "233",
"judge_server_addr": "http://127.0.0.1:5284",
"judge_token": "233"
}

7
models/judge_state.js

@ -20,6 +20,7 @@
'use strict';
let Sequelize = require('sequelize');
const judger = require('../modules/judge');
let db = syzoj.db;
let User = syzoj.model('user');
@ -211,9 +212,10 @@ class JudgeState extends Model {
this.max_memory = 0;
}
this.pending = true;
this.result = { status: "Waiting", total_time: 0, max_memory: 0, score: 0, case_num: 0, compiler_output: "", pending: true };
this.result = { };
await this.save();
/*
let WaitingJudge = syzoj.model('waiting_judge');
let waiting_judge = await WaitingJudge.create({
judge_id: this.id,
@ -222,6 +224,7 @@ class JudgeState extends Model {
});
await waiting_judge.save();
*/
if (oldStatus === 'Accepted') {
await this.user.refreshSubmitInfo();
@ -237,6 +240,8 @@ class JudgeState extends Model {
let contest = await Contest.fromID(this.type_info);
await contest.newSubmission(this);
}
await judger.judge(this, 1);
});
}

24
modules/api_v2.js

@ -178,3 +178,27 @@ app.apiRouter.post('/api/v2/judge/update/:id', async (req, res) => {
res.status(500).send(e);
}
});
app.apiRouter.post('/api/v2/judge/update2', async (req, res) => {
try {
if (req.get('Token') !== syzoj.config.judge_token) return res.status(403).send({ err: 'Incorrect token' });
const data = req.body;
let JudgeState = syzoj.model('judge_state');
let judge_state = await JudgeState.fromID(req.body.taskId);
// await judge_state.updateResult(JSON.parse(req.body));
judge_state.score = data.score;
judge_state.pending = false;
judge_state.status = data.statusString;
this.total_time = data.time;
this.max_memory = data.memory;
this.result = data.result;
await judge_state.save();
await judge_state.updateRelatedInfo();
res.send({ return: 0 });
} catch (e) {
syzoj.log(e);
res.status(500).send(e);
}
});

16
modules/problem.js

@ -28,6 +28,8 @@ let ProblemTag = syzoj.model('problem_tag');
let ProblemTagMap = syzoj.model('problem_tag_map');
let Article = syzoj.model('article');
const judger = require('../modules/judge');
app.get('/problems', async (req, res) => {
try {
let where = {};
@ -194,7 +196,7 @@ app.get('/problem/:id', async (req, res) => {
problem.allowedManage = await problem.isAllowedManageBy(res.locals.user);
if (problem.is_public || problem.allowedEdit) {
await syzoj.utils.markdown(problem, [ 'description', 'input_format', 'output_format', 'example', 'limit_and_hint' ]);
await syzoj.utils.markdown(problem, ['description', 'input_format', 'output_format', 'example', 'limit_and_hint']);
} else {
throw new ErrorMessage('您没有权限进行此操作。');
}
@ -635,13 +637,11 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
}
await judge_state.updateRelatedInfo(true);
let waiting_judge = await WaitingJudge.create({
judge_id: judge_state.id,
priority: 1,
type: 'submission'
});
await waiting_judge.save();
try {
await judger.judge(judge_state, contest_id ? 3 : 2);
} catch (err) {
throw new ErrorMessage(`无法开始评测:${err.toString()}`);
}
res.redirect(syzoj.utils.makeUrl(['submission', judge_state.id]));
} catch (e) {

Loading…
Cancel
Save