hewenyang
7 years ago
5 changed files with 199 additions and 55 deletions
@ -0,0 +1,78 @@
|
||||
"use strict"; |
||||
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
const _ = require("lodash"); |
||||
const winston = require("winston"); |
||||
const interfaces_1 = require("./judger_interfaces"); |
||||
const compileError = "Compile Error", systemError = "System Error", testdataError = "No Testdata"; |
||||
exports.statusToString = {}; |
||||
exports.statusToString[interfaces_1.TestcaseResultType.Accepted] = "Accepted"; |
||||
exports.statusToString[interfaces_1.TestcaseResultType.WrongAnswer] = "Wrong Answer"; |
||||
exports.statusToString[interfaces_1.TestcaseResultType.PartiallyCorrect] = "Partially Correct"; |
||||
exports.statusToString[interfaces_1.TestcaseResultType.MemoryLimitExceeded] = "Memory Limit Exceeded"; |
||||
exports.statusToString[interfaces_1.TestcaseResultType.TimeLimitExceeded] = "Time Limit Exceeded"; |
||||
exports.statusToString[interfaces_1.TestcaseResultType.OutputLimitExceeded] = "Output Limit Exceeded"; |
||||
exports.statusToString[interfaces_1.TestcaseResultType.RuntimeError] = "Runtime Error"; |
||||
exports.statusToString[interfaces_1.TestcaseResultType.FileError] = "File Error"; |
||||
exports.statusToString[interfaces_1.TestcaseResultType.JudgementFailed] = "Judgement Failed"; |
||||
exports.statusToString[interfaces_1.TestcaseResultType.InvalidInteraction] = "Invalid Interaction"; |
||||
function firstNonAC(t) { |
||||
if (t.every(v => v === interfaces_1.TestcaseResultType.Accepted)) { |
||||
return interfaces_1.TestcaseResultType.Accepted; |
||||
} |
||||
else { |
||||
return t.find(r => r !== interfaces_1.TestcaseResultType.Accepted); |
||||
} |
||||
} |
||||
exports.firstNonAC = firstNonAC; |
||||
function convertResult(taskId, source) { |
||||
winston.debug(`Converting result for ${taskId}`, source); |
||||
let time = null, memory = null, score = null, done = true, statusString = null; |
||||
if (source.compile && source.compile.status === interfaces_1.TaskStatus.Failed) { |
||||
statusString = compileError; |
||||
} |
||||
else if (source.error != null) { |
||||
done = false; |
||||
if (source.error === interfaces_1.ErrorType.TestDataError) { |
||||
statusString = testdataError; |
||||
} |
||||
else { |
||||
statusString = systemError; |
||||
} |
||||
} |
||||
else if (source.judge != null && source.judge.subtasks != null) { |
||||
const forEveryTestcase = function (map, reduce) { |
||||
const list = source.judge.subtasks.map(s => reduce(s.cases.filter(c => c.result != null).map(c => map(c.result)))); |
||||
if (list.every(x => x == null)) |
||||
return null; |
||||
else |
||||
return reduce(list); |
||||
}; |
||||
time = forEveryTestcase(c => c.time, _.sum); |
||||
memory = forEveryTestcase(c => c.memory, _.max); |
||||
if (source.judge.subtasks.some(s => s.cases.some(c => c.status === interfaces_1.TaskStatus.Failed))) { |
||||
winston.debug(`Some subtasks failed, returning system error`); |
||||
statusString = systemError; |
||||
} |
||||
else { |
||||
score = _.sum(source.judge.subtasks.map(s => s.score)); |
||||
const finalResult = forEveryTestcase(c => c.type, firstNonAC); |
||||
statusString = exports.statusToString[finalResult]; |
||||
} |
||||
} |
||||
else { |
||||
statusString = systemError; |
||||
} |
||||
const result = { |
||||
taskId: taskId, |
||||
time: time, |
||||
memory: memory, |
||||
score: score, |
||||
statusNumber: done ? interfaces_1.TaskStatus.Done : interfaces_1.TaskStatus.Failed, |
||||
statusString: statusString, |
||||
result: source |
||||
}; |
||||
winston.debug(`Result for ${taskId}`, result); |
||||
return result; |
||||
} |
||||
exports.convertResult = convertResult; |
||||
//# sourceMappingURL=judgeResult.js.map
|
@ -0,0 +1,53 @@
|
||||
"use strict"; |
||||
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
var RPCTaskType; |
||||
(function (RPCTaskType) { |
||||
RPCTaskType[RPCTaskType["Compile"] = 1] = "Compile"; |
||||
RPCTaskType[RPCTaskType["RunStandard"] = 2] = "RunStandard"; |
||||
RPCTaskType[RPCTaskType["RunSubmitAnswer"] = 3] = "RunSubmitAnswer"; |
||||
RPCTaskType[RPCTaskType["RunInteraction"] = 4] = "RunInteraction"; |
||||
})(RPCTaskType = exports.RPCTaskType || (exports.RPCTaskType = {})); |
||||
; |
||||
var ErrorType; |
||||
(function (ErrorType) { |
||||
ErrorType[ErrorType["SystemError"] = 0] = "SystemError"; |
||||
ErrorType[ErrorType["TestDataError"] = 1] = "TestDataError"; |
||||
})(ErrorType = exports.ErrorType || (exports.ErrorType = {})); |
||||
var TaskStatus; |
||||
(function (TaskStatus) { |
||||
TaskStatus[TaskStatus["Waiting"] = 0] = "Waiting"; |
||||
TaskStatus[TaskStatus["Running"] = 1] = "Running"; |
||||
TaskStatus[TaskStatus["Done"] = 2] = "Done"; |
||||
TaskStatus[TaskStatus["Failed"] = 3] = "Failed"; |
||||
TaskStatus[TaskStatus["Skipped"] = 4] = "Skipped"; |
||||
})(TaskStatus = exports.TaskStatus || (exports.TaskStatus = {})); |
||||
var TestcaseResultType; |
||||
(function (TestcaseResultType) { |
||||
TestcaseResultType[TestcaseResultType["Accepted"] = 1] = "Accepted"; |
||||
TestcaseResultType[TestcaseResultType["WrongAnswer"] = 2] = "WrongAnswer"; |
||||
TestcaseResultType[TestcaseResultType["PartiallyCorrect"] = 3] = "PartiallyCorrect"; |
||||
TestcaseResultType[TestcaseResultType["MemoryLimitExceeded"] = 4] = "MemoryLimitExceeded"; |
||||
TestcaseResultType[TestcaseResultType["TimeLimitExceeded"] = 5] = "TimeLimitExceeded"; |
||||
TestcaseResultType[TestcaseResultType["OutputLimitExceeded"] = 6] = "OutputLimitExceeded"; |
||||
TestcaseResultType[TestcaseResultType["FileError"] = 7] = "FileError"; |
||||
TestcaseResultType[TestcaseResultType["RuntimeError"] = 8] = "RuntimeError"; |
||||
TestcaseResultType[TestcaseResultType["JudgementFailed"] = 9] = "JudgementFailed"; |
||||
TestcaseResultType[TestcaseResultType["InvalidInteraction"] = 10] = "InvalidInteraction"; |
||||
})(TestcaseResultType = exports.TestcaseResultType || (exports.TestcaseResultType = {})); |
||||
var RPCReplyType; |
||||
(function (RPCReplyType) { |
||||
RPCReplyType[RPCReplyType["Started"] = 1] = "Started"; |
||||
RPCReplyType[RPCReplyType["Finished"] = 2] = "Finished"; |
||||
RPCReplyType[RPCReplyType["Error"] = 3] = "Error"; |
||||
})(RPCReplyType = exports.RPCReplyType || (exports.RPCReplyType = {})); |
||||
var ProgressReportType; |
||||
(function (ProgressReportType) { |
||||
ProgressReportType[ProgressReportType["Started"] = 1] = "Started"; |
||||
ProgressReportType[ProgressReportType["Compiled"] = 2] = "Compiled"; |
||||
ProgressReportType[ProgressReportType["Progress"] = 3] = "Progress"; |
||||
ProgressReportType[ProgressReportType["Finished"] = 4] = "Finished"; |
||||
ProgressReportType[ProgressReportType["Reported"] = 5] = "Reported"; |
||||
})(ProgressReportType = exports.ProgressReportType || (exports.ProgressReportType = {})); |
||||
exports.redisBinarySuffix = '-bin'; |
||||
exports.redisMetadataSuffix = '-meta'; |
||||
//# sourceMappingURL=interfaces.js.map
|
@ -0,0 +1,23 @@
|
||||
const winston = require('winston'); |
||||
const _ = require('lodash'); |
||||
const util = require('util'); |
||||
|
||||
function formatter(args) { |
||||
var msg = args.level + ' - ' + args.message + (_.isEmpty(args.meta) ? '' : (' - ' + util.inspect(args.meta))); |
||||
return msg; |
||||
} |
||||
|
||||
function configureWinston(verbose) { |
||||
winston.configure({ |
||||
transports: [ |
||||
new (winston.transports.Console)({ formatter: formatter }) |
||||
] |
||||
}); |
||||
if (verbose) { |
||||
winston.level = 'debug'; |
||||
} else { |
||||
winston.level = 'info'; |
||||
} |
||||
} |
||||
|
||||
configureWinston(false); |
Loading…
Reference in new issue