From a38618dfc83d4e85a2b48d0c9c9279d0d62250f1 Mon Sep 17 00:00:00 2001 From: zjz1993 <1429595365@qq.com> Date: Thu, 12 Sep 2019 14:19:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=83=E4=B9=A0=E5=8A=A0=E5=88=86?= =?UTF-8?q?=E8=A7=84=E5=88=99=E4=BF=AE=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/judger.js | 11 +++++++++-- models/judge_state.ts | 1 + modules/practice.js | 9 +++++---- modules/problem.js | 2 +- views/submission_practice.ejs | 1 + 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/libs/judger.js b/libs/judger.js index ff7d812..cfe40a0 100644 --- a/libs/judger.js +++ b/libs/judger.js @@ -194,9 +194,16 @@ async function connect() { } const flatTimeArray = flat(timeArray); const maxItemTime = Math.max.apply(this, flatTimeArray); - if (judge_state.type_info && convertedResult.statusString === 'Accepted' && maxItemTime < problem_time_limit * 0.9) { + let baseScore = 0; + if (judge_state.type === 0) { + baseScore = 100; + } + if (judge_state.type === 2) { + baseScore = syzoj.config.practice_rating + } + 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)*100; + const extraScore = (beyondTime / problem_time_limit).toString().slice(0,3)*baseScore; 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 d5ff7d1..9e647d1 100644 --- a/models/judge_state.ts +++ b/models/judge_state.ts @@ -89,6 +89,7 @@ export default class JudgeState extends Model { /* * "type" indicate it's contest's submission(type = 1) or normal submission(type = 0) + * 2说明是练习的提交 * if it's contest's submission (type = 1), the type_info is contest_id * use this way represent because it's easy to expand // Menci:这锅我不背,是 Chenyao 留下来的坑。 */ diff --git a/modules/practice.js b/modules/practice.js index 66fadfe..304faf3 100644 --- a/modules/practice.js +++ b/modules/practice.js @@ -1,4 +1,5 @@ let Classify = syzoj.model('classify'); +let JudgeState = syzoj.model('judge_state'); let Problem = syzoj.model('problem'); let CToP = syzoj.model('classify_to_problem'); let Article = syzoj.model('article'); @@ -176,6 +177,7 @@ app.get('/api/pass/:cid/:pid/:sid',async (req, res) => { let utopQuery = UToP.createQueryBuilder(); let query = Classify.createQueryBuilder(); let userQuery = User.createQueryBuilder(); + let judgeStateQuery = JudgeState.createQueryBuilder(); let classify = await Classify.queryAll(query); classify.sort(function(a,b) { return a.order - b.order; @@ -198,12 +200,11 @@ app.get('/api/pass/:cid/:pid/:sid',async (req, res) => { }); await utop.save(); } - let newutopQuery = UToP.createQueryBuilder(); - let userACArray = await newutopQuery.where('u_id=:u_id',{u_id}).andWhere("is_finished=1").getMany(); - console.log(userACArray.length); 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 originRating = syzoj.config.default.user.rating; - const newRating = originRating + userACArray.length * syzoj.config.practice_rating; + const newRating = originRating + newScore; await userQuery.update(User).set({rating: newRating}).where('id=:u_id',{u_id}).execute(); } res.send(); diff --git a/modules/problem.js b/modules/problem.js index 01e172f..48f9823 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -633,7 +633,7 @@ app.post('/problem/practice/:pid/:cid/submit', app.multer.fields([{ name: 'answe }); if (!await problem.isAllowedUseBy(curUser)) throw new ErrorMessage('您没有权限进行此操作。'); - judge_state.type = 0; + judge_state.type = 2; await judge_state.save(); await judge_state.updateRelatedInfo(true); diff --git a/views/submission_practice.ejs b/views/submission_practice.ejs index 79fcf77..88865f0 100644 --- a/views/submission_practice.ejs +++ b/views/submission_practice.ejs @@ -37,6 +37,7 @@
是否分享 | 编号 | 题目 | 状态 |
---|