Browse Source

Some minor tweaks

pull/6/head
hewenyang 7 years ago
parent
commit
f1d29a04e6
  1. 6
      app.js
  2. 36
      libs/judgeResult.js
  3. 3
      libs/judger.js
  4. 8
      modules/socketio.js

6
app.js

@ -39,13 +39,12 @@ global.syzoj = {
console.log(obj); console.log(obj);
}, },
async run() { async run() {
let winstonLib = require('./libs/winston');
winstonLib.configureWinston(true);
let Express = require('express'); let Express = require('express');
global.app = Express(); global.app = Express();
syzoj.production = app.get('env') === 'production'; syzoj.production = app.get('env') === 'production';
let winstonLib = require('./libs/winston');
winstonLib.configureWinston(!syzoj.production);
app.server = require('http').createServer(app); app.server = require('http').createServer(app);
app.server.listen(parseInt(syzoj.config.port), syzoj.config.hostname, () => { app.server.listen(parseInt(syzoj.config.port), syzoj.config.hostname, () => {
@ -86,6 +85,7 @@ global.syzoj = {
app.use(csurf({ cookie: true })); app.use(csurf({ cookie: true }));
await this.connectDatabase(); await this.connectDatabase();
await this.lib('judger').connect();
this.loadModules(); this.loadModules();
}, },
async connectDatabase() { async connectDatabase() {

36
libs/judgeResult.js

@ -2,37 +2,37 @@
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash"); const _ = require("lodash");
const winston = require("winston"); const winston = require("winston");
const interfaces_1 = require("./judger_interfaces"); const interfaces = require("./judger_interfaces");
const compileError = "Compile Error", systemError = "System Error", testdataError = "No Testdata"; const compileError = "Compile Error", systemError = "System Error", testdataError = "No Testdata";
exports.statusToString = {}; exports.statusToString = {};
exports.statusToString[interfaces_1.TestcaseResultType.Accepted] = "Accepted"; exports.statusToString[interfaces.TestcaseResultType.Accepted] = "Accepted";
exports.statusToString[interfaces_1.TestcaseResultType.WrongAnswer] = "Wrong Answer"; exports.statusToString[interfaces.TestcaseResultType.WrongAnswer] = "Wrong Answer";
exports.statusToString[interfaces_1.TestcaseResultType.PartiallyCorrect] = "Partially Correct"; exports.statusToString[interfaces.TestcaseResultType.PartiallyCorrect] = "Partially Correct";
exports.statusToString[interfaces_1.TestcaseResultType.MemoryLimitExceeded] = "Memory Limit Exceeded"; exports.statusToString[interfaces.TestcaseResultType.MemoryLimitExceeded] = "Memory Limit Exceeded";
exports.statusToString[interfaces_1.TestcaseResultType.TimeLimitExceeded] = "Time Limit Exceeded"; exports.statusToString[interfaces.TestcaseResultType.TimeLimitExceeded] = "Time Limit Exceeded";
exports.statusToString[interfaces_1.TestcaseResultType.OutputLimitExceeded] = "Output Limit Exceeded"; exports.statusToString[interfaces.TestcaseResultType.OutputLimitExceeded] = "Output Limit Exceeded";
exports.statusToString[interfaces_1.TestcaseResultType.RuntimeError] = "Runtime Error"; exports.statusToString[interfaces.TestcaseResultType.RuntimeError] = "Runtime Error";
exports.statusToString[interfaces_1.TestcaseResultType.FileError] = "File Error"; exports.statusToString[interfaces.TestcaseResultType.FileError] = "File Error";
exports.statusToString[interfaces_1.TestcaseResultType.JudgementFailed] = "Judgement Failed"; exports.statusToString[interfaces.TestcaseResultType.JudgementFailed] = "Judgement Failed";
exports.statusToString[interfaces_1.TestcaseResultType.InvalidInteraction] = "Invalid Interaction"; exports.statusToString[interfaces.TestcaseResultType.InvalidInteraction] = "Invalid Interaction";
function firstNonAC(t) { function firstNonAC(t) {
if (t.every(v => v === interfaces_1.TestcaseResultType.Accepted)) { if (t.every(v => v === interfaces.TestcaseResultType.Accepted)) {
return interfaces_1.TestcaseResultType.Accepted; return interfaces.TestcaseResultType.Accepted;
} }
else { else {
return t.find(r => r !== interfaces_1.TestcaseResultType.Accepted); return t.find(r => r !== interfaces.TestcaseResultType.Accepted);
} }
} }
exports.firstNonAC = firstNonAC; exports.firstNonAC = firstNonAC;
function convertResult(taskId, source) { function convertResult(taskId, source) {
winston.debug(`Converting result for ${taskId}`, source); winston.debug(`Converting result for ${taskId}`, source);
let time = null, memory = null, score = null, done = true, statusString = null; let time = null, memory = null, score = null, done = true, statusString = null;
if (source.compile && source.compile.status === interfaces_1.TaskStatus.Failed) { if (source.compile && source.compile.status === interfaces.TaskStatus.Failed) {
statusString = compileError; statusString = compileError;
} }
else if (source.error != null) { else if (source.error != null) {
done = false; done = false;
if (source.error === interfaces_1.ErrorType.TestDataError) { if (source.error === interfaces.ErrorType.TestDataError) {
statusString = testdataError; statusString = testdataError;
} }
else { else {
@ -49,7 +49,7 @@ function convertResult(taskId, source) {
}; };
time = forEveryTestcase(c => c.time, _.sum); time = forEveryTestcase(c => c.time, _.sum);
memory = forEveryTestcase(c => c.memory, _.max); memory = forEveryTestcase(c => c.memory, _.max);
if (source.judge.subtasks.some(s => s.cases.some(c => c.status === interfaces_1.TaskStatus.Failed))) { if (source.judge.subtasks.some(s => s.cases.some(c => c.status === interfaces.TaskStatus.Failed))) {
winston.debug(`Some subtasks failed, returning system error`); winston.debug(`Some subtasks failed, returning system error`);
statusString = systemError; statusString = systemError;
} }
@ -67,7 +67,7 @@ function convertResult(taskId, source) {
time: time, time: time,
memory: memory, memory: memory,
score: score, score: score,
statusNumber: done ? interfaces_1.TaskStatus.Done : interfaces_1.TaskStatus.Failed, statusNumber: done ? interfaces.TaskStatus.Done : interfaces.TaskStatus.Failed,
statusString: statusString, statusString: statusString,
result: source result: source
}; };

3
libs/judger.js

@ -96,6 +96,7 @@ async function connect () {
process.exit(1); process.exit(1);
}); });
} }
module.exports.connect = connect;
module.exports.judge = async function (judge_state, problem, priority) { module.exports.judge = async function (judge_state, problem, priority) {
let type, param, extraData = null; let type, param, extraData = null;
@ -138,5 +139,3 @@ module.exports.judge = async function (judge_state, problem, priority) {
amqpSendChannel.sendToQueue('judge', msgPack.encode({ content: content, extraData: extraData }), { priority: priority }); amqpSendChannel.sendToQueue('judge', msgPack.encode({ content: content, extraData: extraData }), { priority: priority });
} }
connect();

8
modules/socketio.js

@ -4,8 +4,8 @@ const socketio = require("socket.io");
const diff = require("jsondiffpatch"); const diff = require("jsondiffpatch");
const jwt = require("jsonwebtoken"); const jwt = require("jsonwebtoken");
const winston = require("winston"); const winston = require("winston");
const judgeResult_1 = require("../libs/judgeResult"); const judgeResult = require("../libs/judgeResult");
const interfaces_1 = require("../libs/judger_interfaces"); const interfaces = require("../libs/judger_interfaces");
let ioInstance; let ioInstance;
let detailProgressNamespace; let detailProgressNamespace;
let roughProgressNamespace; let roughProgressNamespace;
@ -223,7 +223,7 @@ function createTask(taskId) {
exports.createTask = createTask; exports.createTask = createTask;
function updateCompileStatus(taskId, result) { function updateCompileStatus(taskId, result) {
winston.debug(`Updating compilation status for #${taskId}`); winston.debug(`Updating compilation status for #${taskId}`);
compiledList[taskId] = { result: result.status === interfaces_1.TaskStatus.Done ? 'Submitted' : 'Compile Error' }; compiledList[taskId] = { result: result.status === interfaces.TaskStatus.Done ? 'Submitted' : 'Compile Error' };
compileProgressNamespace.to(taskId.toString()).emit('finish', { compileProgressNamespace.to(taskId.toString()).emit('finish', {
taskId: taskId, taskId: taskId,
result: compiledList[taskId] result: compiledList[taskId]
@ -261,7 +261,7 @@ function updateResult(taskId, data) {
}); });
} }
} }
const finalResult = judgeResult_1.convertResult(taskId, data); const finalResult = judgeResult.convertResult(taskId, data);
const roughResult = { const roughResult = {
result: finalResult.statusString, result: finalResult.statusString,
time: finalResult.time, time: finalResult.time,

Loading…
Cancel
Save