Browse Source

Merge branch 'master' of zhaojunzhe/fair-web into master

pull/1/head
richie 5 years ago committed by Gogs
parent
commit
cf5d11af7f
  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) { 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) {
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;

2
models/judge_state.ts

@ -131,7 +131,7 @@ export default class JudgeState extends Model {
await this.loadRelationships(); await this.loadRelationships();
if (user && user.id === this.problem.user_id) return true; 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) { else if (this.type === 1) {
let contest = await Contest.findById(this.type_info); let contest = await Contest.findById(this.type_info);
if (contest.isRunning()) { if (contest.isRunning()) {

12
modules/practice.js

@ -200,9 +200,17 @@ app.get('/api/pass/:cid/:pid/:sid',async (req, res) => {
}); });
await utop.save(); 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) { 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 scoreArray = await judgeStateQuery.select("score").addSelect("problem_id").where("user_id=:u_id",{u_id}).andWhere("type=2").andWhere("score>=100").getRawMany();
const newScore = scoreArray.reduce((acc,cur)=>{return acc.score+cur.score}) - scoreArray.length * 100; 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 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();

Loading…
Cancel
Save