Browse Source

Report subtask's progress in time

master
Menci 6 years ago
parent
commit
6b99cded3c
  1. 32
      src/daemon/judge/judger-base.ts

32
src/daemon/judge/judger-base.ts

@ -33,10 +33,27 @@ export abstract class JudgerBase {
async judge(reportProgressResult: (p: JudgeResult) => Promise<void>): Promise<JudgeResult> { async judge(reportProgressResult: (p: JudgeResult) => Promise<void>): Promise<JudgeResult> {
const results: SubtaskResult[] = this.testData.subtasks.map(t => ({ const results: SubtaskResult[] = this.testData.subtasks.map(t => ({
cases: t.cases.map(j => ({ cases: t.cases.map(j => ({
status: TaskStatus.Waiting status: TaskStatus.Waiting,
result: { scoringRate: t.type !== SubtaskScoringType.Summation ? 1 : 0 } as any
})), })),
status: TaskStatus.Waiting status: TaskStatus.Waiting
})); }));
const updateSubtaskScore = (currentTask, currentResult) => {
if (currentResult.cases.some(c => c.status === TaskStatus.Failed)) {
// If any testcase has failed, the score is invaild.
currentResult.score = NaN;
} else {
currentResult.score = calculateSubtaskScore(currentTask.type, currentResult.cases.map(c => c.result ? c.result.scoringRate : 0)) * currentTask.score;
}
}
for (let subtaskIndex = 0; subtaskIndex < this.testData.subtasks.length; subtaskIndex++) {
const currentResult = results[subtaskIndex];
const currentTask = this.testData.subtasks[subtaskIndex];
updateSubtaskScore(currentTask, currentResult);
}
const reportProgress = function () { const reportProgress = function () {
reportProgressResult({ subtasks: results }); reportProgressResult({ subtasks: results });
} }
@ -47,6 +64,8 @@ export abstract class JudgerBase {
const currentResult = results[subtaskIndex]; const currentResult = results[subtaskIndex];
const currentTask = this.testData.subtasks[subtaskIndex]; const currentTask = this.testData.subtasks[subtaskIndex];
const updateCurrentSubtaskScore = () => updateSubtaskScore(currentTask, currentResult);
judgeTasks.push((async () => { judgeTasks.push((async () => {
// Type minimum is skippable, run one by one // Type minimum is skippable, run one by one
if (currentTask.type !== SubtaskScoringType.Summation) { if (currentTask.type !== SubtaskScoringType.Summation) {
@ -75,6 +94,7 @@ export abstract class JudgerBase {
winston.debug(`Subtask ${subtaskIndex}, case ${index}: zero, skipping the rest.`); winston.debug(`Subtask ${subtaskIndex}, case ${index}: zero, skipping the rest.`);
skipped = true; skipped = true;
} }
updateCurrentSubtaskScore();
await reportProgress(); await reportProgress();
} }
} }
@ -96,17 +116,13 @@ export abstract class JudgerBase {
currentTaskResult.errorMessage = err.toString(); currentTaskResult.errorMessage = err.toString();
winston.warn(`Task runner error: ${err.toString()} (subtask ${subtaskIndex}, case ${index})`); winston.warn(`Task runner error: ${err.toString()} (subtask ${subtaskIndex}, case ${index})`);
} }
updateCurrentSubtaskScore();
await reportProgress(); await reportProgress();
})()); })());
} }
await Promise.all(caseTasks); await Promise.all(caseTasks);
} }
if (currentResult.cases.some(c => c.status === TaskStatus.Failed)) { updateCurrentSubtaskScore();
// If any testcase has failed, the score is invaild.
currentResult.score = NaN;
} else {
currentResult.score = calculateSubtaskScore(currentTask.type, currentResult.cases.map(c => c.result ? c.result.scoringRate : 0)) * currentTask.score;
}
winston.verbose(`Subtask ${subtaskIndex}, finished`); winston.verbose(`Subtask ${subtaskIndex}, finished`);
})()); })());
} }
@ -116,4 +132,4 @@ export abstract class JudgerBase {
protected abstract judgeTestcase(curCase: TestcaseJudge, started: () => Promise<void>): Promise<TestcaseDetails>; protected abstract judgeTestcase(curCase: TestcaseJudge, started: () => Promise<void>): Promise<TestcaseDetails>;
async cleanup() { } async cleanup() { }
} }

Loading…
Cancel
Save