From 00b1fcacc5b16de8d3462affa4c19ccadc78bfa5 Mon Sep 17 00:00:00 2001 From: zjz1993 <1429595365@qq.com> Date: Mon, 16 Sep 2019 15:32:10 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E8=A7=A3=E5=86=B3=E7=BB=83=E4=B9=A0?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E5=8A=A0=E5=88=86=E7=9A=84bug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/judger.js | 3 +++ models/judge_state.ts | 2 +- modules/practice.js | 12 ++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libs/judger.js b/libs/judger.js index cfe40a0..02f62ed 100644 --- a/libs/judger.js +++ b/libs/judger.js @@ -204,6 +204,9 @@ async function connect() { 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; + if (judge_state.type === 2) { + judge_state.score = convertedResult.score + extraScore + syzoj.config.practice_rating; + } judge_state.score = convertedResult.score + extraScore; } else { judge_state.score = convertedResult.score; diff --git a/models/judge_state.ts b/models/judge_state.ts index 9e647d1..18b0218 100644 --- a/models/judge_state.ts +++ b/models/judge_state.ts @@ -131,7 +131,7 @@ export default class JudgeState extends Model { await this.loadRelationships(); if (user && user.id === this.problem.user_id) return true; - else if (this.type === 0) return this.problem.is_public || (user && (await user.hasPrivilege('manage_problem'))); + else if (this.type === 0 || this.type === 2) return this.problem.is_public || (user && (await user.hasPrivilege('manage_problem'))); else if (this.type === 1) { let contest = await Contest.findById(this.type_info); if (contest.isRunning()) { diff --git a/modules/practice.js b/modules/practice.js index 304faf3..3781c98 100644 --- a/modules/practice.js +++ b/modules/practice.js @@ -200,9 +200,17 @@ app.get('/api/pass/:cid/:pid/:sid',async (req, res) => { }); await utop.save(); } + let newutopQuery = UToP.createQueryBuilder(); + let userACArray = await newutopQuery.select("p_id").where('u_id=:u_id',{u_id}).andWhere("is_finished=1").getRawMany(); if (syzoj.config.practice_rating) { - const scoreArray = await judgeStateQuery.select("score").where("user_id=:u_id",{u_id}).andWhere("type=2").andWhere("score>100").getMany(); - const newScore = scoreArray.reduce((acc,cur)=>{return acc.score+cur.score}) - scoreArray.length * 100; + const scoreArray = await judgeStateQuery.select("score").addSelect("problem_id").where("user_id=:u_id",{u_id}).andWhere("type=2").andWhere("score>=100").getRawMany(); + let num = 0; + for(let i=0;i item.problem_id === problem_id) + num+=parseInt(item.score); + } + const newScore = num - userACArray.length * 100; 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();