Browse Source

bugfix: 修复练习功能异常

master
zjz1993 5 years ago
parent
commit
faec00d65a
  1. 16
      modules/practice.js
  2. 4
      views/submission_practice.ejs

16
modules/practice.js

@ -204,19 +204,23 @@ app.get('/api/pass/:cid/:pid/:sid',async (req, res) => {
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").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);
let newScore = 0;
if (scoreArray && scoreArray.length !== 0) {
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);
}
newScore = num - userACArray.length * 100;
}
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();
res.send({newRating: newRating});
}
} catch(e) {
console.log(e);
res.send({ error_code: e.errno, error_msg: '练习失败,请稍后重试' });
}
});

4
views/submission_practice.ejs

@ -348,7 +348,7 @@ if (token != null) {
console.log("Judge finished");
vueApp.roughData.running = false;
vueApp.roughData.result = p.roughResult;
if (p.roughResult.result === 'Accepted') {
if (p.roughResult && p.roughResult.result === 'Accepted') {
$.ajax({
url: `/api/pass/${cid}/${pid}/${sid}`,
type: 'GET',
@ -384,7 +384,7 @@ if (token != null) {
// }
// data.running=false;
if (data && data.ok) {
if (data.roughResult.result === 'Accepted') {
if (data.roughResult && data.roughResult.result === 'Accepted') {
$.ajax({
url: `/api/pass/${cid}/${pid}/${sid}`,
type: 'GET',

Loading…
Cancel
Save