Browse Source

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

pull/1/head
richie 5 years ago committed by Gogs
parent
commit
50c6168267
  1. 11
      libs/judger.js
  2. 1
      models/judge_state.ts
  3. 9
      modules/practice.js
  4. 2
      modules/problem.js
  5. 1
      views/submission_practice.ejs

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

1
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 留下来的坑。
*/

9
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();

2
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);

1
views/submission_practice.ejs

@ -37,6 +37,7 @@
<table class="ui very basic center aligned table" id="status_table">
<thead>
<tr>
<th>是否分享</th>
<th>编号</th>
<th>题目</th>
<th>状态</th>

Loading…
Cancel
Save