Browse Source

Finish.

pull/6/head
t123yh 7 years ago
parent
commit
72747e50e1
  1. 2
      libs/judger.js
  2. 2
      libs/submissions_process.js
  3. 18
      models/judge_state.js
  4. 12
      modules/api_v2.js
  5. 4
      modules/contest.js
  6. 3
      modules/problem.js
  7. 4
      modules/submission.js
  8. 13
      package-lock.json
  9. 1
      package.json
  10. 12
      views/submission.ejs
  11. 2
      views/submissions.ejs
  12. 4
      views/submissions_item.ejs

2
libs/judger.js

@ -31,7 +31,7 @@ module.exports.judge = async function (judge_state, problem, priority) {
const req = {
content: {
taskId: judge_state.id,
taskId: judge_state.task_id,
testData: problem.id.toString(),
type: type,
priority: priority,

2
libs/submissions_process.js

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

18
models/judge_state.js

@ -20,6 +20,7 @@
'use strict';
let Sequelize = require('sequelize');
const randomstring = require('randomstring');
let db = syzoj.db;
let User = syzoj.model('user');
@ -36,8 +37,10 @@ let model = db.define('judge_state', {
language: { type: Sequelize.STRING(20) },
status: { type: Sequelize.STRING(50) },
task_id: { type: Sequelize.STRING(50) },
score: { type: Sequelize.INTEGER },
total_time: { type: Sequelize.INTEGER },
code_length: { type: Sequelize.INTEGER },
pending: { type: Sequelize.BOOLEAN },
max_memory: { type: Sequelize.INTEGER },
@ -82,6 +85,7 @@ class JudgeState extends Model {
static async create(val) {
return JudgeState.fromRecord(JudgeState.model.build(Object.assign({
code: '',
code_length: 0,
language: null,
user_id: 0,
problem_id: 0,
@ -96,7 +100,8 @@ class JudgeState extends Model {
total_time: null,
max_memory: null,
status: 'Waiting',
result: null
result: null,
task_id: randomstring.generate(10)
}, val)));
}
@ -156,14 +161,15 @@ class JudgeState extends Model {
let oldStatus = this.status;
this.status = 'Waiting';
this.score = 0;
this.score = null;
if (this.language) {
// language is empty if it's a submit-answer problem
this.total_time = 0;
this.max_memory = 0;
this.total_time = null;
this.max_memory = null;
}
this.pending = true;
this.result = {};
this.task_id = randomstring.generate(10);
await this.save();
/*
@ -192,7 +198,11 @@ class JudgeState extends Model {
await contest.newSubmission(this);
}
try {
await Judger.judge(this, this.problem, 1);
} catch (err) {
throw new ErrorMessage("无法开始评测。");
}
});
}

12
modules/api_v2.js

@ -87,7 +87,11 @@ app.apiRouter.post('/api/v2/judge/compiled', async (req, res) => {
let data = req.body;
let JudgeState = syzoj.model('judge_state');
let judge_state = await JudgeState.fromID(req.body.taskId);
let judge_state = await JudgeState.findOne({ where: { task_id: req.body.taskId } });
if (!judge_state) {
res.send({ return: 1 }); // The task might have been rejudging.
return;
}
judge_state.compilation = req.body.result;
await judge_state.save();
@ -104,7 +108,11 @@ app.apiRouter.post('/api/v2/judge/finished', async (req, res) => {
let data = req.body;
let JudgeState = syzoj.model('judge_state');
let judge_state = await JudgeState.fromID(req.body.taskId);
let judge_state = await JudgeState.findOne({ where: { task_id: req.body.taskId } });
if (!judge_state) {
res.send({ return: 1 }); // The task might have been rejudging.
return;
}
// await judge_state.updateResult(JSON.parse(req.body));
judge_state.score = data.score;
judge_state.pending = false;

4
modules/contest.js

@ -349,7 +349,7 @@ app.get('/contest/:id/submissions', async (req, res) => {
items: judge_state.map(x => ({
info: getSubmissionInfo(x, displayConfig),
token: (getRoughResult(x, displayConfig) == null) ? jwt.sign({
taskId: x.id,
taskId: x.task_id,
type: pushType,
displayConfig: displayConfig
}, syzoj.config.judge_token) : null,
@ -404,7 +404,7 @@ app.get('/contest/submission/:id', async (req, res) => {
code: (displayConfig.showCode && judge.problem.type !== 'submit-answer') ? judge.code.toString("utf8") : '',
detailResult: processOverallResult(judge.result, displayConfig),
socketToken: (displayConfig.showDetailResult && judge.pending) ? jwt.sign({
taskId: judge.id,
taskId: judge.task_id,
displayConfig: displayConfig,
type: 'detail'
}, syzoj.config.judge_token) : null,

3
modules/problem.js

@ -594,7 +594,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
if (!file.md5) throw new ErrorMessage('上传答案文件失败。');
judge_state = await JudgeState.create({
code: file.md5,
max_memory: size,
code_length: size,
language: null,
user_id: res.locals.user.id,
problem_id: req.params.id
@ -612,6 +612,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
judge_state = await JudgeState.create({
code: code,
code_length: code.length,
language: req.body.language,
user_id: res.locals.user.id,
problem_id: req.params.id

4
modules/submission.js

@ -110,7 +110,7 @@ app.get('/submissions', async (req, res) => {
items: judge_state.map(x => ({
info: getSubmissionInfo(x, displayConfig),
token: (getRoughResult(x, displayConfig) == null) ? jwt.sign({
taskId: x.id,
taskId: x.task_id,
type: 'rough',
displayConfig: displayConfig
}, syzoj.config.judge_token) : null,
@ -161,7 +161,7 @@ app.get('/submission/:id', async (req, res) => {
code: (judge.problem.type !== 'submit-answer') ? judge.code.toString("utf8") : '',
detailResult: processOverallResult(judge.result, displayConfig),
socketToken: judge.pending ? jwt.sign({
taskId: judge.id,
taskId: judge.task_id,
type: 'detail',
displayConfig: displayConfig
}, syzoj.config.judge_token) : null,

13
package-lock.json generated

@ -105,6 +105,11 @@
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
},
"array-uniq": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.2.tgz",
"integrity": "sha1-X8w3OSB3VyPP1k1lxkvvU7+eum0="
},
"asn1": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz",
@ -2196,6 +2201,14 @@
"resolved": "https://registry.npmjs.org/random-js/-/random-js-1.0.8.tgz",
"integrity": "sha1-lo/WiabyXWwKrHZig94vaIycGQo="
},
"randomstring": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/randomstring/-/randomstring-1.1.5.tgz",
"integrity": "sha1-bfBij3XL1ZMpMNn+OrTpVqGFGMM=",
"requires": {
"array-uniq": "1.0.2"
}
},
"range-parser": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",

1
package.json

@ -46,6 +46,7 @@
"mysql": "^2.11.1",
"node-7z": "^0.4.0",
"pygmentize-bundled-cached": "^1.1.0",
"randomstring": "^1.1.5",
"request": "^2.74.0",
"request-promise": "^4.1.1",
"sendmail": "^1.1.1",

12
views/submission.ejs

@ -20,7 +20,7 @@
</tr>
</thead>
<tbody>
<tr is="submission-item" v-bind:data="roughData" :config="displayConfig" :showRejudge="showRejudge"></tr>
<tr is="submission-item" v-bind:data="roughData" :config="displayConfig" :show-rejudge="showRejudge"></tr>
</tbody>
</table>
@ -39,7 +39,7 @@
<div class="four wide column">
<status-label :status="getSubtaskResult(subtask)"></status-label>
</div>
<div class="three wide column">得分
<div class="three wide column" v-if="subtask.score != null">得分
<span style="font-weight: normal; ">{{ Math.trunc(subtask.score) }}</span>
</div>
</div>
@ -221,13 +221,13 @@ if (token != null) {
socket.on('connect', () => {
socket.on('start', () => {
vueApp.roughData.running = true;
console.log("Judge start!");
vueApp.detailResult = {};
});
socket.on('update', (p) => {
console.log("Delta: " + JSON.stringify(p));
if (p.from === currentVersion) {
currentVersion = p.to;
console.log("Before patching: " + JSON.stringify(vueApp));
jsondiffpatch.patch(vueApp.detailResult, p.delta);
} else { // Some packets are dropped. Let's reset.
socket.close();
@ -235,13 +235,14 @@ if (token != null) {
}
});
socket.on('finish', (p) => {
console.log("Finish: " + JSON.stringify(p));
console.log("Judge finished");
vueApp.roughData.running = false;
vueApp.roughData.result = p.roughResult;
vueApp.detailResult = p.result;
socket.close();
});
socket.emit('join', token, (data) => {
console.log("join! " + JSON.stringify(data));
if (data && data.ok) {
if (data.finished) {
vueApp.roughData.result = data.roughResult;
@ -252,7 +253,8 @@ if (token != null) {
} else {
if (data.running) {
vueApp.roughData.running = true;
vueApp.detailResult = data.current;
vueApp.detailResult = data.current.content;
currentVersion = data.current.version;
}
}
} else {

2
views/submissions.ejs

@ -95,7 +95,7 @@
</tr>
</thead>
<tbody>
<tr v-for="item in items" :config="displayConfig" :showRejudge="false" :data="item" is='submission-item'>
<tr v-for="item in items" :config="displayConfig" :show-rejudge="false" :data="item" is='submission-item'>
</tr>
</tbody>
</table>

4
views/submissions_item.ejs

@ -67,8 +67,8 @@ Vue.component('submission-item', {
<td>{{ data.info.submitTime }}</td>
<td v-if="showRejudge">
<form class="have-csrf" :action="submissionLink + '/rejudge'" method="POST">
<input type="hideen" name="_csrf" value="<%= req.csrfToken() %>" />
<input type="submit" value="rejudge"><i class="repeat icon"></i></input>
<input type="hidden" name="_csrf" value="<%= req.csrfToken() %>" />
<button type="submit" style="color: #000; padding: 0; border: none; background: none;" value="rejudge"><i class="repeat icon"></i></button>
</form>
</td>
</tr>

Loading…
Cancel
Save