Browse Source

bugfix: 解决练习不能加分的bug。

master
zjz1993 5 years ago
parent
commit
00b1fcacc5
  1. 3
      libs/judger.js
  2. 2
      models/judge_state.ts
  3. 12
      modules/practice.js

3
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;

2
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()) {

12
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<userACArray.length;i++){
const problem_id = userACArray[i].p_id;
const item = scoreArray.find(item => 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();

Loading…
Cancel
Save