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. 14
      modules/problem.js

1
config-example.json

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

7
models/judge_state.js

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

14
modules/problem.js

@ -28,6 +28,8 @@ let ProblemTag = syzoj.model('problem_tag');
let ProblemTagMap = syzoj.model('problem_tag_map'); let ProblemTagMap = syzoj.model('problem_tag_map');
let Article = syzoj.model('article'); let Article = syzoj.model('article');
const judger = require('../modules/judge');
app.get('/problems', async (req, res) => { app.get('/problems', async (req, res) => {
try { try {
let where = {}; let where = {};
@ -635,13 +637,11 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
} }
await judge_state.updateRelatedInfo(true); await judge_state.updateRelatedInfo(true);
let waiting_judge = await WaitingJudge.create({ try {
judge_id: judge_state.id, await judger.judge(judge_state, contest_id ? 3 : 2);
priority: 1, } catch (err) {
type: 'submission' throw new ErrorMessage(`无法开始评测:${err.toString()}`);
}); }
await waiting_judge.save();
res.redirect(syzoj.utils.makeUrl(['submission', judge_state.id])); res.redirect(syzoj.utils.makeUrl(['submission', judge_state.id]));
} catch (e) { } catch (e) {

Loading…
Cancel
Save