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.

366 lines
14 KiB

<% this.title = '提交记录 #' + info.submissionId %>
7 years ago
<% include util %>
8 years ago
<% include header %>
<script src="https://cdnjs.loli.net/ajax/libs/textfit/2.3.1/textFit.min.js"></script>
7 years ago
<style>
.single-subtask {
box-shadow: none !important;
}
.single-subtask > .title {
display: none;
}
.single-subtask > .content {
padding: 0 !important;
}
.accordion > .content > .accordion {
margin-top: 0;
margin-bottom: 0;
}
.accordion > .content > .accordion > .content {
margin-top: 0;
margin-bottom: 14px;
}
.accordion > .content > .accordion > .content > :last-child {
margin-bottom: -10px !important;
}
</style>
7 years ago
<span id="submission_content">
<div class="padding" id="vueAppFuckSafari">
7 years ago
<table class="ui very basic center aligned table" id="status_table">
<thead>
<tr>
<th>编号</th>
<th>题目</th>
<th>状态</th>
<th v-if="displayConfig.showScore">分数</th>
<th v-if="displayConfig.showUsage">总时间</th>
<th v-if="displayConfig.showUsage">内存</th>
<th v-if="displayConfig.showCode">代码 / 答案文件</th>
<th>提交者</th>
<th>提交时间</th>
<th v-if="showRejudge">重新评测</th>
7 years ago
</tr>
</thead>
<tbody>
<tr is="submission-item" v-bind:data="roughData" :config="displayConfig" :show-rejudge="showRejudge" :progress="getProgress()"></tr>
7 years ago
</tbody>
</table>
6 years ago
<code-box :escape="false" v-bind:content="code">
<% if (formattedCode !== null) { %>
<a onclick="toggleFormattedCode()" class="ui button" style="position: absolute; top: 0px; right: -4px; border-top-left-radius: 0; border-bottom-right-radius: 0; ">
<template v-if="currentFormatted">
显示原始代码
</template>
<template v-if="!currentFormatted">
格式化代码
</template>
</a>
<% } %>
</code-box>
7 years ago
<code-box v-if="detailResult && detailResult.compile" :escape="false" title="编译信息" v-bind:content="detailResult.compile.message"></code-box>
<code-box v-if="detailResult" title="系统信息" :escape="true" v-bind:content="detailResult.systemMessage"></code-box>
7 years ago
<div class="ui styled fluid accordion" :class="singleSubtask ? 'single-subtask' : '' "v-if="detailResult && detailResult.judge && detailResult.judge.subtasks">
7 years ago
<template v-for="subtask, $index in detailResult.judge.subtasks">
<div class="title" :class="singleSubtask ? 'active' : ''">
<div class="ui grid">
<div class="three wide column">
<i class="dropdown icon"></i>
子任务 #{{ $index + 1 }}
</div>
<div class="four wide column">
<status-label :status="getSubtaskResult(subtask)" :indetail="true" :progress="getProgress($index)"></status-label>
7 years ago
</div>
7 years ago
<div class="three wide column" v-if="subtask.score != null">
得分:<span style="font-weight: normal; ">{{ Math.trunc(subtask.score) }}</span>
7 years ago
</div>
</div>
</div>
<div class="content" :class="singleSubtask ? 'active' : ''">
<div class="accordion">
<template v-for="curCase, $caseIndex in subtask.cases">
<div class="title" :class="checkTestcaseOK(curCase) ? '' : 'unexpandable'">
7 years ago
<div class="ui grid">
<div class="three wide column">
<i class="dropdown icon"></i>
测试点 #{{ $caseIndex + 1 }}
</div>
<div class="four wide column">
<status-label :status="getTestcaseStatus(curCase)" :indetail="true"></status-label>
7 years ago
</div>
<template v-if="checkTestcaseOK(curCase)">
7 years ago
<div class="three wide column">
得分:<span style="font-weight: normal; ">{{ Math.trunc(curCase.result.scoringRate * 100) }}</span>
7 years ago
</div>
7 years ago
<div class="three wide column" v-if="curCase.result.time != null && curCase.result.time !== NaN">
用时:<span style="font-weight: normal; ">{{ curCase.result.time }} ms</span>
7 years ago
</div>
7 years ago
<div class="three wide column" v-if="curCase.result.memory != null && curCase.result.memory !== NaN">
内存:<span style="font-weight: normal; ">{{ curCase.result.memory }} KiB</span>
7 years ago
</div>
</template>
</div>
</div>
<div class="content">
<template v-if="checkTestcaseOK(curCase)">
7 years ago
<code-box v-if="curCase.result.input" :title="'输入文件(<span style=\'font-family: monospace; \'>'+ curCase.result.input.name +'</span>)'" :content="curCase.result.input.content"></code-box>
<code-box v-if="curCase.result.output" :title="'答案文件(<span style=\'font-family: monospace; \'>'+ curCase.result.output.name +'</span>)'" :content="curCase.result.output.content"></code-box>
7 years ago
<code-box title="用户输出" :content="curCase.result.userOutput"></code-box>
<code-box title="标准错误流" :content="curCase.result.userError"></code-box>
<code-box title="Special Judge 信息" :content="curCase.result.spjMessage"></code-box>
<code-box title="系统信息" :content="curCase.result.systemMessage"></code-box>
</template>
<code-box title="错误信息" :content="curCase.errorMessage"></code-box>
</div>
</template>
</div>
</div>
</template>
</div>
</div>
<script src="https://cdnjs.loli.net/ajax/libs/vue/2.5.17/vue.min.js"></script>
<script src="https://cdnjs.loli.net/ajax/libs/socket.io/2.1.1/socket.io.js"></script>
<script src="https://cdnjs.loli.net/ajax/libs/jsondiffpatch/0.2.5/jsondiffpatch.min.js"></script>
7 years ago
<% include submissions_item %>
<script type="text/x-template" id="codeBoxTemplate">
7 years ago
<div style="margin-top: 0px; margin-bottom: 14px; " v-if="content != null && content !== ''">
<p v-if="title" class="transition visible">
<strong v-html="title"></strong>
</p>
7 years ago
<div class="ui existing segment">
6 years ago
<slot></slot>
7 years ago
<pre v-if="escape" style="margin-top: 0; margin-bottom: 0; "><code>{{ content }}</code></pre>
<pre v-if="!escape" style="margin-top: 0; margin-bottom: 0; "><code v-html="content"></code></pre>
</div>
</div>
</script>
<script>
Vue.component("code-box", {
template: "#codeBoxTemplate",
6 years ago
props: ['title', 'content', 'escape']
7 years ago
});
const socketUrl = "/detail";
7 years ago
const displayConfig = <%- JSON.stringify(displayConfig) %>;
const token = <%- JSON.stringify(socketToken) %>;
const 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);
const statusToString = {};
statusToString[TestcaseResultType.Accepted] = "Accepted";
statusToString[TestcaseResultType.WrongAnswer] = "Wrong Answer";
statusToString[TestcaseResultType.PartiallyCorrect] = "Partially Correct";
statusToString[TestcaseResultType.MemoryLimitExceeded] = "Memory Limit Exceeded";
statusToString[TestcaseResultType.TimeLimitExceeded] = "Time Limit Exceeded";
statusToString[TestcaseResultType.OutputLimitExceeded] = "Output Limit Exceeded";
statusToString[TestcaseResultType.RuntimeError] = "Runtime Error";
statusToString[TestcaseResultType.FileError] = "File Error";
statusToString[TestcaseResultType.JudgementFailed] = "Judgement Failed";
statusToString[TestcaseResultType.InvalidInteraction] = "Invalid Interaction";
const 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);
6 years ago
const unformattedCode = <%- JSON.stringify(code) %>;
const formattedCode = <%- JSON.stringify(formattedCode) %>;
function toggleFormattedCode() {
if (vueApp.currentFormatted) {
vueApp.currentFormatted = false;
vueApp.code = unformattedCode;
} else {
vueApp.currentFormatted = true;
vueApp.code = formattedCode;
}
}
7 years ago
const vueApp = new Vue({
el: '#vueAppFuckSafari',
7 years ago
data: {
roughData: {
info: <%- JSON.stringify(info) %>,
result: <%- JSON.stringify(roughResult) %>,
running: false,
displayConfig: displayConfig
},
6 years ago
code: <%- JSON.stringify(preferFormattedCode && formattedCode !== null) -%> ? formattedCode : unformattedCode,
currentFormatted: <%- JSON.stringify(preferFormattedCode && formattedCode !== null) -%>,
7 years ago
detailResult: <%- JSON.stringify(detailResult) %>,
displayConfig: displayConfig,
7 years ago
},
computed: {
singleSubtask() {
return this.detailResult.judge.subtasks.length === 1;
},
showRejudge() {
return this.displayConfig.showRejudge && (!this.roughData.running);
7 years ago
}
},
methods: {
getStatusString(statusCode) {
return statusToString[statusCode];
},
firstNonAC(t) {
if (t.every(function(v){ return v === TestcaseResultType.Accepted;})) {
7 years ago
return TestcaseResultType.Accepted;
} else {
return t.find(function(r) { return r !== TestcaseResultType.Accepted;});
7 years ago
}
},
getSubtaskResult(t) {
if (t.cases.some(function(c){ return c.status === TaskStatus.Running;})) {
7 years ago
return "Running";
} else if (t.cases.some(function(c) { return c.status === TaskStatus.Waiting;})) {
7 years ago
return "Waiting";
} else if (t.cases.every(function(c){ return c.status === TaskStatus.Done || c.status === TaskStatus.Skipped;})) {
return this.getStatusString(this.firstNonAC(t.cases.filter(function(c) { return c.result; })
.map(function(c) { return c.result.type;})));
7 years ago
} else {
return "System Error";
}
},
getTestcaseStatus(c) {
if (c.status === TaskStatus.Done) {
return this.getStatusString(c.result.type);
} else if (c.status === TaskStatus.Waiting) {
return "Waiting";
} else if (c.status === TaskStatus.Running) {
return "Running";
} else if (c.status === TaskStatus.Skipped) {
return "Skipped";
} else {
return "System Error";
}
},
checkTestcaseOK(c) {
return c.status === TaskStatus.Done;
},
getProgress(i) {
if (!this.detailResult || !this.detailResult.judge || !this.detailResult.judge.subtasks) return {
finished: 0,
total: 0
};
let isPending = status => [TaskStatus.Waiting, TaskStatus.Running].includes(status);
let subtaskProgress = [], allFinished = 0, allTotal = 0;
for (let i in this.detailResult.judge.subtasks) {
let subtaskFinished = 0, subtaskTotal = 0;
for (let j in this.detailResult.judge.subtasks[i].cases) {
subtaskTotal++, allTotal++;
if (!isPending(this.detailResult.judge.subtasks[i].cases[j].status)) subtaskFinished++, allFinished++;
}
subtaskProgress.push({
finished: subtaskFinished,
total: subtaskTotal
});
}
let allProgress = {
finished: allFinished,
total: allTotal
};
return typeof i === 'undefined' ? allProgress : subtaskProgress[i];
7 years ago
}
},
mounted() {
$(document).ready(function(){ $('.ui.accordion').accordion({ selector: { trigger: '.title:not(.unexpandable)' } })});
7 years ago
},
updated() {
$('.ui.accordion').accordion("refresh");
}
});
if (token != null) {
const loadSocketIO = function () {
let currentVersion = 0;
const socket = io(socketUrl);
socket.on('connect', function () {
socket.on('start', function () {
7 years ago
vueApp.roughData.running = true;
7 years ago
console.log("Judge start!");
7 years ago
vueApp.detailResult = {};
});
socket.on('update', function (p) {
7 years ago
console.log("Delta: " + JSON.stringify(p));
if (p.from === currentVersion) {
currentVersion = p.to;
jsondiffpatch.patch(vueApp.detailResult, p.delta);
} else { // Some packets are dropped. Let's reset.
socket.close();
setTimeout(loadSocketIO, 0);
}
});
socket.on('finish', function (p) {
7 years ago
console.log("Judge finished");
7 years ago
vueApp.roughData.running = false;
vueApp.roughData.result = p.roughResult;
vueApp.detailResult = p.result;
socket.close();
});
socket.emit('join', token, function (data) {
7 years ago
console.log("join! " + JSON.stringify(data));
7 years ago
if (data && data.ok) {
if (data.finished) {
vueApp.roughData.result = data.roughResult;
vueApp.detailResult = data.result || {
systemMessage: "系统出错,请刷新后重试。"
};
socket.close();
} else {
if (data.running) {
vueApp.roughData.running = true;
7 years ago
vueApp.detailResult = data.current.content;
currentVersion = data.current.version;
7 years ago
}
}
} else {
alert("ERROR: " + JSON.stringify(data));
}
});
});
};
loadSocketIO();
}
</script>
<script>
document.addEventListener('keydown', function (event) {
if ((event.ctrlKey || event.metaKey) && event.key === 'a') {
var sel = window.getSelection();
var rg = document.createRange()
rg.selectNodeContents(document.querySelector('code'));
sel.removeAllRanges();
sel.addRange(rg);
event.preventDefault();
}
});
</script>
7 years ago
</span>
7 years ago
<% include footer %>