Browse Source

Repalce data.yml with data_rule.txt

pull/6/head
Menci 7 years ago
parent
commit
36bc764632
  1. 1
      package.json
  2. 59
      utility.js
  3. 8
      views/problem_testcases.ejs
  4. 6
      views/submission_content.ejs

1
package.json

@ -37,6 +37,7 @@
"file-size": "^1.0.0",
"fs-extra": "^2.1.2",
"gravatar": "^1.5.2",
"js-yaml": "^3.9.0",
"moemark-renderer": "^1.2.6",
"moment": "^2.15.0",
"multer": "^1.2.0",

59
utility.js

@ -209,7 +209,7 @@ module.exports = {
let list = await (await fs.readdirAsync(dir)).filterAsync(async x => await syzoj.utils.isFile(path.join(dir, x)));
let res = [];
if (!list.includes('data_rule.txt')) {
if (!list.includes('data.yml')) {
res[0] = {};
res[0].cases = [];
for (let file of list) {
@ -247,52 +247,37 @@ module.exports = {
return getLastInteger(a.input) - getLastInteger(b.input);
});
} else {
let lines = (await fs.readFileAsync(path.join(dir, 'data_rule.txt'))).toString().split('\r').join('').split('\n').filter(x => x.length !== 0);
let input, output, answer;
if (submitAnswer) {
if (lines.length < 4) throw '无效的数据配置文件(data_rule.txt)。';
input = lines[lines.length - 3];
output = lines[lines.length - 2];
answer = lines[lines.length - 1];
res.spj = list.some(s => s.startsWith('spj_'));
} else {
if (lines.length < 3) throw '无效的数据配置文件(data_rule.txt)。';
input = lines[lines.length - 2];
output = lines[lines.length - 1];
}
let config = require('js-yaml').load((await fs.readFileAsync(dir + '/data.yml')));
for (let s = 0; s < lines.length - (submitAnswer ? 3 : 2); ++s) {
res[s] = {};
res[s].cases = [];
let numbers = lines[s].split(' ').filter(x => x);
if (numbers[0].includes(':')) {
let tokens = numbers[0].split(':');
res[s].type = tokens[0] || 'sum';
res[s].score = parseFloat(tokens[1]) || (100 / (lines.length - 2));
numbers.shift();
} else {
res[s].type = 'sum';
res[s].score = 100;
let input = config.inputFile, output = config.answerFile, answer = config.userOutput;
res = config.subtasks.map(st => ({
score: st.score,
type: st.type,
cases: st.cases.map(c => {
function getFileName(template, id) {
let s = template.split('#').join(String(id));
if (!list.includes(s)) throw `找不到文件 ${s}`;
return s;
}
for (let i of numbers) {
let testcase = {
input: input.replace('#', i),
output: output.replace('#', i)
};
if (submitAnswer) testcase.answer = answer.replace('#', i);
let o = {};
if (input) o.input = getFileName(input, c);
if (output) o.output = getFileName(output, c);
if (answer) o.answer = getFileName(answer, c);
if (testcase.input !== '-' && !list.includes(testcase.input)) throw `找不到文件 ${testcase.input}`;
if (testcase.output !== '-' && !list.includes(testcase.output)) throw `找不到文件 ${testcase.output}`;
res[s].cases.push(testcase);
}
}
return o;
})
}));
res = res.filter(x => x.cases && x.cases.length !== 0);
res.spj = !!config.specialJudge;
}
res.spj = list.some(s => s.startsWith('spj_'));
return res;
} catch (e) {
console.log(e);

8
views/problem_testcases.ejs

@ -12,6 +12,8 @@ let subtaskType = {
%>
<% if (testcases.spj) { %>
<p>评测方式:Special Judge</p>
<% } else if (problem.type === 'interaction') { %>
<p>评测方式:交互</p>
<% } else { %>
<p>评测方式:文本比较</p>
<% } %>
@ -33,12 +35,12 @@ let subtaskType = {
<tr class="center aligned">
<td style="width: 33%; "><%= testcase.input || '-' %></td>
<td style="width: 33%; "><%= testcase.output || '-' %></td>
<td style="width: 33%; "><%= testcase.answer %></td>
<td style="width: 33%; "><%= testcase.answer || '-' %></td>
</tr>
<% } else { %>
<tr class="center aligned">
<td style="width: 50%; "><%= testcase.input %></td>
<td style="width: 50%; "><%= testcase.output %></td>
<td style="width: 50%; "><%= testcase.input || '-' %></td>
<td style="width: 50%; "><%= testcase.output || '-' %></td>
</tr>
<% } %>
<% } %>

6
views/submission_content.ejs

@ -147,7 +147,7 @@ else problemUrl = syzoj.utils.makeUrl(['problem', judge.problem_id]);
<h3 class="ui header">系统调试信息</h3>
<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; "><code><%= judge.result.message %></code></pre></div>
<% } else if (judge.result.spj_compiler_output) { %>
<h3 class="ui header">Special Judge 编译信息</h3>
<h3 class="ui header"><%= judge.problem.type === 'interaction' ? '交互程序' : 'Special Judge ' %>编译信息</h3>
<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; "><code><%- syzoj.utils.ansiToHTML(judge.result.spj_compiler_output) %></code></pre></div>
<% } else if (judge.allowedSeeCase && judge.result.subtasks && (judge.result.subtasks.length !== 1 || judge.result.subtasks[0].case_num)) { %>
<div class="ui styled fluid accordion" id="subtasks_list">
@ -189,12 +189,14 @@ else problemUrl = syzoj.utils.makeUrl(['problem', judge.problem_id]);
<p>
<strong>输入文件<% if (testcase.input_file_name) { %>(<span style="font-family: monospace; "><%= testcase.input_file_name %></span>)<% } %></strong>
<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; "><code><%= testcase.input %></code></pre></div>
<% if (judge.problem.type !== 'interaction') { %>
<strong>输出文件<% if (testcase.output_file_name) { %>(<span style="font-family: monospace; "><%= testcase.output_file_name %></span>)<% } %></strong>
<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; "><code><%= testcase.answer %></code></pre></div>
<strong>选手输出</strong>
<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; "><code><%= testcase.user_out %></code></pre></div>
<% } %>
<% if (testcase.spj_message) { %>
<strong>Special Judge 信息</strong>
<strong><%= judge.problem.type === 'interaction' ? '交互程序' : 'Special Judge ' %>信息</strong>
<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; "><code><%= testcase.spj_message %></code></pre></div>
<% } %>
<% if (testcase.user_err) { %>

Loading…
Cancel
Save