|
|
@ -1,4 +1,5 @@ |
|
|
|
import _ = require('lodash'); |
|
|
|
import _ = require('lodash'); |
|
|
|
|
|
|
|
import winston = require('winston'); |
|
|
|
|
|
|
|
|
|
|
|
export interface JudgeResultSubmit { |
|
|
|
export interface JudgeResultSubmit { |
|
|
|
taskId: number; |
|
|
|
taskId: number; |
|
|
@ -37,6 +38,7 @@ export function firstNonAC(t: TaskResult[]): TaskResult { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function convertResult(id: number, source: JudgeResult): JudgeResultSubmit { |
|
|
|
export function convertResult(id: number, source: JudgeResult): JudgeResultSubmit { |
|
|
|
|
|
|
|
winston.debug(`Converting result for ${id}`, source); |
|
|
|
let time = -1, |
|
|
|
let time = -1, |
|
|
|
memory = -1, |
|
|
|
memory = -1, |
|
|
|
score = 0, |
|
|
|
score = 0, |
|
|
@ -45,26 +47,33 @@ export function convertResult(id: number, source: JudgeResult): JudgeResultSubmi |
|
|
|
|
|
|
|
|
|
|
|
if (source.compileStatus === TaskStatus.Failed) { |
|
|
|
if (source.compileStatus === TaskStatus.Failed) { |
|
|
|
statusString = compileError; |
|
|
|
statusString = compileError; |
|
|
|
|
|
|
|
score = 0; |
|
|
|
} else if (source.error != null) { |
|
|
|
} else if (source.error != null) { |
|
|
|
done = false; |
|
|
|
done = false; |
|
|
|
score = -1; |
|
|
|
score = NaN; |
|
|
|
if (source.error === ErrorType.TestDataError) { |
|
|
|
if (source.error === ErrorType.TestDataError) { |
|
|
|
statusString = testdataError; |
|
|
|
statusString = testdataError; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
statusString = systemError; |
|
|
|
statusString = systemError; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (source.subtasks != null) { |
|
|
|
} else if (source.subtasks != null) { |
|
|
|
if (source.subtasks.some(s => s.score === -1)) { |
|
|
|
if (source.subtasks.some(s => s.score === NaN)) { |
|
|
|
score = -1; |
|
|
|
score = NaN; |
|
|
|
statusString = systemError; |
|
|
|
statusString = systemError; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const finalResult = firstNonAC(source.subtasks.map(s => firstNonAC(s.cases.filter(c => c.result != null).map(c => c.result.type)))); |
|
|
|
|
|
|
|
statusString = statusToString[finalResult]; |
|
|
|
|
|
|
|
score = _.sum(source.subtasks.map(s => s.score)); |
|
|
|
score = _.sum(source.subtasks.map(s => s.score)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const forEveryTestcase = function <TParam>(map: (v: TestCaseDetails) => TParam, reduce: (v: TParam[]) => TParam): TParam { |
|
|
|
|
|
|
|
return reduce(source.subtasks.map(s => reduce(s.cases.filter(c => c.result != null).map(c => map(c.result))))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
time = forEveryTestcase(c => c.time, _.sum); |
|
|
|
|
|
|
|
memory = forEveryTestcase(c => c.memory, _.max); |
|
|
|
|
|
|
|
const finalResult = forEveryTestcase(c => c.type, firstNonAC); |
|
|
|
|
|
|
|
statusString = statusToString[finalResult]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
const result = { |
|
|
|
taskId: id, |
|
|
|
taskId: id, |
|
|
|
time: time, |
|
|
|
time: time, |
|
|
|
memory: memory, |
|
|
|
memory: memory, |
|
|
@ -73,4 +82,6 @@ export function convertResult(id: number, source: JudgeResult): JudgeResultSubmi |
|
|
|
statusString: statusString, |
|
|
|
statusString: statusString, |
|
|
|
result: JSON.stringify(source) |
|
|
|
result: JSON.stringify(source) |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
winston.debug(`Result for ${id}`, result); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |