Browse Source

Use NaN to represent failure.

master
t123yh 7 years ago
parent
commit
41b4f88779
  1. 2
      src/daemon/judge/process.ts
  2. 23
      src/judgeResult.ts

2
src/daemon/judge/process.ts

@ -89,7 +89,7 @@ export async function processJudgement(
}
if (currentResult.cases.some(c => c.status === TaskStatus.Failed)) {
// If any testcase has failed, the score is invaild.
currentResult.score = -1;
currentResult.score = NaN;
} else {
currentResult.score = calculateSubtaskScore(currentTask.type, currentResult.cases.map(c => c.result ? c.result.scoringRate : 0)) * currentTask.score;
}

23
src/judgeResult.ts

@ -1,4 +1,5 @@
import _ = require('lodash');
import winston = require('winston');
export interface JudgeResultSubmit {
taskId: number;
@ -37,6 +38,7 @@ export function firstNonAC(t: TaskResult[]): TaskResult {
}
export function convertResult(id: number, source: JudgeResult): JudgeResultSubmit {
winston.debug(`Converting result for ${id}`, source);
let time = -1,
memory = -1,
score = 0,
@ -45,26 +47,33 @@ export function convertResult(id: number, source: JudgeResult): JudgeResultSubmi
if (source.compileStatus === TaskStatus.Failed) {
statusString = compileError;
score = 0;
} else if (source.error != null) {
done = false;
score = -1;
score = NaN;
if (source.error === ErrorType.TestDataError) {
statusString = testdataError;
} else {
statusString = systemError;
}
} else if (source.subtasks != null) {
if (source.subtasks.some(s => s.score === -1)) {
score = -1;
if (source.subtasks.some(s => s.score === NaN)) {
score = NaN;
statusString = systemError;
} 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));
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,
time: time,
memory: memory,
@ -73,4 +82,6 @@ export function convertResult(id: number, source: JudgeResult): JudgeResultSubmi
statusString: statusString,
result: JSON.stringify(source)
};
winston.debug(`Result for ${id}`, result);
return result;
}
Loading…
Cancel
Save