Browse Source

bugfix: 修复比赛加分异常的情况。

master
zjz1993 5 years ago
parent
commit
3b05110171
  1. 25
      libs/judger.js
  2. 1
      libs/submissions_process.js
  3. 2
      modules/practice.js
  4. 1
      views/submission.ejs
  5. 1
      views/submission_contest.ejs
  6. 45
      views/submission_practice.ejs
  7. 1
      views/submissions.ejs
  8. 23
      views/submissions_item.ejs

25
libs/judger.js

@ -27,8 +27,8 @@ let judgeQueue;
async function connect() { async function connect() {
const JudgeState = syzoj.model('judge_state'); const JudgeState = syzoj.model('judge_state');
const blockableRedisClient = syzoj.redis.duplicate(); const blockableRedisClient = syzoj.redis.duplicate();
judgeQueue = { judgeQueue = {
redisZADD: util.promisify(syzoj.redis.zadd).bind(syzoj.redis), redisZADD: util.promisify(syzoj.redis.zadd).bind(syzoj.redis),
redisBZPOPMAX: util.promisify(blockableRedisClient.bzpopmax).bind(blockableRedisClient), redisBZPOPMAX: util.promisify(blockableRedisClient.bzpopmax).bind(blockableRedisClient),
@ -174,7 +174,7 @@ async function connect() {
if (!judge_state) return; if (!judge_state) return;
const problemId = judge_state.problem_id; const problemId = judge_state.problem_id;
let problemQuery = await Problem.createQueryBuilder(); let problemQuery = await Problem.createQueryBuilder();
const problemInfo = await problemQuery.where("id = :id", { id: problemId }).getOne(); const problemInfo = await problemQuery.where("id = :id", {id: problemId}).getOne();
const problem_time_limit = problemInfo.time_limit; const problem_time_limit = problemInfo.time_limit;
const subtasksArray = convertedResult.result.judge ? convertedResult.result.judge.subtasks : []; const subtasksArray = convertedResult.result.judge ? convertedResult.result.judge.subtasks : [];
const timeArray = subtasksArray.map((subtasksItem) => { const timeArray = subtasksArray.map((subtasksItem) => {
@ -182,9 +182,10 @@ async function connect() {
return subtasksItemCases.result.time return subtasksItemCases.result.time
}) })
}); });
function flat(array, result=[]){
for (let i=0;i<array.length;i++){ function flat(array, result = []) {
if (Array.isArray(array[i])){ for (let i = 0; i < array.length; i++) {
if (Array.isArray(array[i])) {
flat(array[i], result); flat(array[i], result);
} else { } else {
result.push(array[i]); result.push(array[i]);
@ -192,23 +193,27 @@ async function connect() {
} }
return result; return result;
} }
const flatTimeArray = flat(timeArray); const flatTimeArray = flat(timeArray);
const maxItemTime = Math.max.apply(this, flatTimeArray); const maxItemTime = Math.max.apply(this, flatTimeArray);
let baseScore = 0; let baseScore = 0;
if (judge_state.type === 0) { if (judge_state.type === 0 || judge_state.type === 1) {
baseScore = 100; baseScore = 100;
} }
if (judge_state.type === 2) { if (judge_state.type === 2) {
baseScore = syzoj.config.practice_rating baseScore = syzoj.config.practice_rating
} }
if (convertedResult.statusString === 'Accepted' && maxItemTime < problem_time_limit * 0.9) { if (convertedResult.statusString === 'Accepted' && maxItemTime < problem_time_limit * 0.9)
{
const beyondTime = problem_time_limit - maxItemTime; const beyondTime = problem_time_limit - maxItemTime;
const extraScore = (beyondTime / problem_time_limit).toString().slice(0,3)*baseScore; const extraScore = (beyondTime / problem_time_limit).toString().slice(0, 3) * baseScore;
if (judge_state.type === 2) { if (judge_state.type === 2) {
judge_state.score = convertedResult.score + extraScore + syzoj.config.practice_rating; judge_state.score = convertedResult.score + extraScore + syzoj.config.practice_rating;
} }
judge_state.score = convertedResult.score + extraScore; judge_state.score = convertedResult.score + extraScore;
} else { }
else
{
judge_state.score = convertedResult.score; judge_state.score = convertedResult.score;
} }
judge_state.pending = false; judge_state.pending = false;

1
libs/submissions_process.js

@ -5,6 +5,7 @@ const getSubmissionInfo = (s, displayConfig) => {
return { return {
submissionId: s.id, submissionId: s.id,
taskId: s.task_id, taskId: s.task_id,
type: s.type,
user: s.is_anonymous ? null: s.user.username, user: s.is_anonymous ? null: s.user.username,
userId: s.is_anonymous ? null : s.user_id, userId: s.is_anonymous ? null : s.user_id,
problemName: s.problem.title, problemName: s.problem.title,

2
modules/practice.js

@ -214,8 +214,8 @@ app.get('/api/pass/:cid/:pid/:sid',async (req, res) => {
const originRating = syzoj.config.default.user.rating; const originRating = syzoj.config.default.user.rating;
const newRating = originRating + newScore; const newRating = originRating + newScore;
await userQuery.update(User).set({rating: newRating}).where('id=:u_id',{u_id}).execute(); await userQuery.update(User).set({rating: newRating}).where('id=:u_id',{u_id}).execute();
res.send({newRating: newRating});
} }
res.send();
} catch(e) { } catch(e) {
res.send({ error_code: e.errno, error_msg: '练习失败,请稍后重试' }); res.send({ error_code: e.errno, error_msg: '练习失败,请稍后重试' });
} }

1
views/submission.ejs

@ -36,6 +36,7 @@
<tr> <tr>
<th>已分享</th> <th>已分享</th>
<th>编号</th> <th>编号</th>
<th>提交类型</th>
<th>题目</th> <th>题目</th>
<th>状态</th> <th>状态</th>
<th v-if="displayConfig.showScore">分数</th> <th v-if="displayConfig.showScore">分数</th>

1
views/submission_contest.ejs

@ -37,6 +37,7 @@
<tr> <tr>
<th>已分享</th> <th>已分享</th>
<th>编号</th> <th>编号</th>
<th>提交类型</th>
<th>题目</th> <th>题目</th>
<th>状态</th> <th>状态</th>
<th v-if="displayConfig.showScore">分数</th> <th v-if="displayConfig.showScore">分数</th>

45
views/submission_practice.ejs

@ -37,8 +37,9 @@
<table class="ui very basic center aligned table" id="status_table"> <table class="ui very basic center aligned table" id="status_table">
<thead> <thead>
<tr> <tr>
<th>是否分享</th> <th>分享</th>
<th>编号</th> <th>编号</th>
<th>提交类型</th>
<th>题目</th> <th>题目</th>
<th>状态</th> <th>状态</th>
<th v-if="displayConfig.showScore">分数</th> <th v-if="displayConfig.showScore">分数</th>
@ -383,32 +384,32 @@ if (token != null) {
// } // }
// data.running=false; // data.running=false;
if (data && data.ok) { if (data && data.ok) {
if (data.roughResult.result === 'Accepted') {
$.ajax({
url: `/api/pass/${cid}/${pid}/${sid}`,
type: 'GET',
success: function (data) {
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('练习功能发生故障');
}
});
} else {
$.ajax({
url: `/api/nopass/${cid}/${pid}/${sid}`,
type: 'GET',
success: function (data) {
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('练习功能发生故障');
}
});
}
if (data.finished) { if (data.finished) {
vueApp.roughData.result = data.roughResult; vueApp.roughData.result = data.roughResult;
// if (!data.result) location.reload(true); // if (!data.result) location.reload(true);
vueApp.detailResult = data.result; vueApp.detailResult = data.result;
vueApp.roughData.running = false; vueApp.roughData.running = false;
// if (data.roughResult.result === 'Accepted') {
// $.ajax({
// url: `/api/pass/${cid}/${pid}/${sid}`,
// type: 'GET',
// success: function (data) {
// },
// error: function (XMLHttpRequest, textStatus, errorThrown) {
// alert('练习功能发生故障');
// }
// });
// } else {
// $.ajax({
// url: `/api/nopass/${cid}/${pid}/${sid}`,
// type: 'GET',
// success: function (data) {
// },
// error: function (XMLHttpRequest, textStatus, errorThrown) {
// alert('练习功能发生故障');
// }
// });
// }
socket.close(); socket.close();
} else { } else {
if (data.running) { if (data.running) {

1
views/submissions.ejs

@ -108,6 +108,7 @@
<tr> <tr>
<th>已分享</th> <th>已分享</th>
<th>编号</th> <th>编号</th>
<th>提交类型</th>
<th>题目</th> <th>题目</th>
<th>状态</th> <th>状态</th>
<th v-if="displayConfig.showScore">分数</th> <th v-if="displayConfig.showScore">分数</th>

23
views/submissions_item.ejs

@ -22,6 +22,16 @@
template: '#submissionItemTemplate', template: '#submissionItemTemplate',
props: ['data', 'config', 'showRejudge', 'showShare', 'progress', 'compiling', 'rough'], props: ['data', 'config', 'showRejudge', 'showShare', 'progress', 'compiling', 'rough'],
computed: { computed: {
type() {
let type = "";
switch(this.data.info.type) {
case 0: type = "普通提交";break;
case 1: type = "比赛提交";break;
case 2: type = "练习提交";break;
default:type="普通提交";
}
return type;
},
statusString() { statusString() {
const data = this.data; const data = this.data;
@ -73,10 +83,15 @@
<tr> <tr>
<td><i class="icon" :class="data.info.is_share ? 'smile outline success': 'meh outline'" style="font-size: 1.5em"></i></td> <td><i class="icon" :class="data.info.is_share ? 'smile outline success': 'meh outline'" style="font-size: 1.5em"></i></td>
<td><a :href="submissionLink"><b>#{{ data.info.submissionId }}</b></a></td> <td><a :href="submissionLink"><b>#{{ data.info.submissionId }}</b></a></td>
<td ref="problemLabel"><a ref="problemLabelTextFit" <td>{{type}}</td>
style="width: 230px; height: 22px; display: block; margin: 0 auto; line-height: 22px;" <td ref="problemLabel">
:href="problemLink"><b>#{{ config.inContest ? alpha(data.info.problemId) : <a ref="problemLabelTextFit"
data.info.problemId }}.</b> {{ data.info.problemName }}</a></td> style="width: 230px; height: 22px; display: block; margin: 0 auto; line-height: 22px;"
:href="problemLink"
>
<b>#{{ config.inContest ? alpha(data.info.problemId) : data.info.problemId }}.</b>
{{ data.info.problemName }}</a>
</td>
<% if (active === 'submissions') { %> <% if (active === 'submissions') { %>
<td><a :href="submissionLink"><b> <td><a :href="submissionLink"><b>
<status-label :status="statusString" :progress="progress"></status-label> <status-label :status="statusString" :progress="progress"></status-label>

Loading…
Cancel
Save