Browse Source

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

pull/34/head
zjz1993 5 years ago
parent
commit
3b05110171
  1. 23
      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

23
libs/judger.js

@ -28,7 +28,7 @@ let judgeQueue;
async function connect() {
const JudgeState = syzoj.model('judge_state');
const blockableRedisClient = syzoj.redis.duplicate();
const blockableRedisClient = syzoj.redis.duplicate();
judgeQueue = {
redisZADD: util.promisify(syzoj.redis.zadd).bind(syzoj.redis),
redisBZPOPMAX: util.promisify(blockableRedisClient.bzpopmax).bind(blockableRedisClient),
@ -174,7 +174,7 @@ async function connect() {
if (!judge_state) return;
const problemId = judge_state.problem_id;
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 subtasksArray = convertedResult.result.judge ? convertedResult.result.judge.subtasks : [];
const timeArray = subtasksArray.map((subtasksItem) => {
@ -182,9 +182,10 @@ async function connect() {
return subtasksItemCases.result.time
})
});
function flat(array, result=[]){
for (let i=0;i<array.length;i++){
if (Array.isArray(array[i])){
function flat(array, result = []) {
for (let i = 0; i < array.length; i++) {
if (Array.isArray(array[i])) {
flat(array[i], result);
} else {
result.push(array[i]);
@ -192,23 +193,27 @@ async function connect() {
}
return result;
}
const flatTimeArray = flat(timeArray);
const maxItemTime = Math.max.apply(this, flatTimeArray);
let baseScore = 0;
if (judge_state.type === 0) {
if (judge_state.type === 0 || judge_state.type === 1) {
baseScore = 100;
}
if (judge_state.type === 2) {
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 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) {
judge_state.score = convertedResult.score + extraScore + syzoj.config.practice_rating;
}
judge_state.score = convertedResult.score + extraScore;
} else {
}
else
{
judge_state.score = convertedResult.score;
}
judge_state.pending = false;

1
libs/submissions_process.js

@ -5,6 +5,7 @@ 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,

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 newRating = originRating + newScore;
await userQuery.update(User).set({rating: newRating}).where('id=:u_id',{u_id}).execute();
res.send({newRating: newRating});
}
res.send();
} catch(e) {
res.send({ error_code: e.errno, error_msg: '练习失败,请稍后重试' });
}

1
views/submission.ejs

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

1
views/submission_contest.ejs

@ -37,6 +37,7 @@
<tr>
<th>已分享</th>
<th>编号</th>
<th>提交类型</th>
<th>题目</th>
<th>状态</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">
<thead>
<tr>
<th>是否分享</th>
<th>分享</th>
<th>编号</th>
<th>提交类型</th>
<th>题目</th>
<th>状态</th>
<th v-if="displayConfig.showScore">分数</th>
@ -383,32 +384,32 @@ if (token != null) {
// }
// data.running=false;
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) {
vueApp.roughData.result = data.roughResult;
// if (!data.result) location.reload(true);
vueApp.detailResult = data.result;
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();
} else {
if (data.running) {

1
views/submissions.ejs

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

23
views/submissions_item.ejs

@ -22,6 +22,16 @@
template: '#submissionItemTemplate',
props: ['data', 'config', 'showRejudge', 'showShare', 'progress', 'compiling', 'rough'],
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() {
const data = this.data;
@ -73,10 +83,15 @@
<tr>
<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 ref="problemLabel"><a ref="problemLabelTextFit"
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>
<td>{{type}}</td>
<td ref="problemLabel">
<a ref="problemLabelTextFit"
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') { %>
<td><a :href="submissionLink"><b>
<status-label :status="statusString" :progress="progress"></status-label>

Loading…
Cancel
Save