算法评测平台前端。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.3 KiB

const {getCachedJudgeState} = require('./judger');
const _ = require('lodash');
const getSubmissionInfo = (s, displayConfig) => {
return {
submissionId: s.id,
taskId: s.task_id,
type: s.type,
user: s.is_anonymous ? null: s.user.username,
userId: s.is_anonymous ? null : s.user_id,
problemName: s.problem.title,
problemId: s.problem_id,
language: displayConfig.showCode ? ((s.language != null && s.language !== '') ? syzoj.languages[s.language].show : null) : null,
codeSize: displayConfig.showCode ? s.code_length : null,
submitTime: syzoj.utils.formatDate(s.submit_time),
isPractice: s.is_practice,
c_id: s.c_id,
is_share: s.is_share || false,
is_anonymous: s.is_anonymous
}
};
const getRoughResult = (x, displayConfig, roughOnly) => {
let max = 0;
5 years ago
if (x && x.result && x.result.judge) {
5 years ago
_.forEach(x.result.judge.subtasks, function (item) {
_.forEach(item.cases, function (one) {
max = Math.max(max, one.result.time);
});
});
5 years ago
}
if (displayConfig.showResult) {
if (x.pending) {
let res = getCachedJudgeState(x.task_id) || null;
if (!res) return null;
if (roughOnly) {
return Object.assign({}, res, {
result: 'Judging',
time: 0,
maxItemTime: 0,
memory: 0,
score: 0
});
} else return res;
7 years ago
} else {
return {
result: x.status,
time: displayConfig.showUsage ? x.total_time : null,
5 years ago
maxItemTime: displayConfig.showUsage ? max === 0 ? x.total_time : max : null,
memory: displayConfig.showUsage ? x.max_memory : null,
score: displayConfig.showScore ? x.score : null
};
}
} else {
// 0: Waiting 1: Running
if (x.status === "System Error")
return {result: "System Error"};
if (x.compilation == null || [0, 1].includes(x.compilation.status)) {
return null;
} else {
if (x.compilation.status === 2) { // 2 is TaskStatus.Done
return {result: "Submitted"};
} else {
return {result: "Compile Error"};
}
}
}
}
7 years ago
const processOverallResult = (source, config) => {
if (source == null)
return null;
if (source.error != null) {
7 years ago
return {
error: source.error,
systemMessage: source.systemMessage
7 years ago
};
}
return {
compile: source.compile,
judge: {
subtasks: source.judge ? source.judge.subtasks && source.judge.subtasks.map(st => ({
score: st.score,
cases: st.cases.map(cs => ({
status: cs.status,
errorMessage: cs.errorMessage,
result: cs.result && {
type: cs.result.type,
time: config.showUsage ? cs.result.time : undefined,
memory: config.showUsage ? cs.result.memory : undefined,
scoringRate: cs.result.scoringRate,
systemMessage: cs.result.systemMessage,
input: config.showTestdata ? cs.result.input : undefined,
output: config.showTestdata ? cs.result.output : undefined,
userOutput: config.showTestdata ? cs.result.userOutput : undefined,
userError: config.showTestdata ? cs.result.userError : undefined,
spjMessage: config.showTestdata ? cs.result.spjMessage : undefined,
}
}))
})) : null
}
};
7 years ago
}
module.exports = {getRoughResult, getSubmissionInfo, processOverallResult};