Browse Source

Add page to reset submission count.

master
t123yh 7 years ago
parent
commit
dc323c25ed
  1. 63
      models/problem.js
  2. 35
      modules/admin.js
  3. 36
      modules/problem.js
  4. 3
      views/admin_header.ejs
  5. 7
      views/admin_other.ejs
  6. 1
      views/admin_rejudge.ejs
  7. 1
      views/problem_manage.ejs

63
models/problem.js

@ -21,7 +21,7 @@
let statisticsStatements = {
fastest:
'\
'\
SELECT \
DISTINCT(`user_id`) AS `user_id`, \
( \
@ -46,7 +46,7 @@ WHERE \
ORDER BY `total_time` ASC \
',
slowest:
' \
' \
SELECT \
DISTINCT(`user_id`) AS `user_id`, \
( \
@ -71,7 +71,7 @@ WHERE \
ORDER BY `total_time` DESC \
',
shortest:
' \
' \
SELECT \
DISTINCT(`user_id`) AS `user_id`, \
( \
@ -96,7 +96,7 @@ WHERE \
ORDER BY `code_length` ASC \
',
longest:
' \
' \
SELECT \
DISTINCT(`user_id`) AS `user_id`, \
( \
@ -121,7 +121,7 @@ WHERE \
ORDER BY `code_length` DESC \
',
earliest:
' \
' \
SELECT \
DISTINCT(`user_id`) AS `user_id`, \
( \
@ -146,7 +146,7 @@ WHERE \
ORDER BY `submit_time` ASC \
',
min:
' \
' \
SELECT \
DISTINCT(`user_id`) AS `user_id`, \
( \
@ -171,7 +171,7 @@ WHERE \
ORDER BY `max_memory` ASC \
',
max:
' \
' \
SELECT \
DISTINCT(`user_id`) AS `user_id`, \
( \
@ -201,6 +201,7 @@ let Sequelize = require('sequelize');
let db = syzoj.db;
let User = syzoj.model('user');
let JudgeState = syzoj.model('judge_state');
let File = syzoj.model('file');
const fs = require('fs-extra');
const path = require('path');
@ -249,17 +250,17 @@ let model = db.define('problem', {
values: ['traditional', 'submit-answer', 'interaction']
}
}, {
timestamps: false,
tableName: 'problem',
indexes: [
{
fields: ['title'],
},
{
fields: ['user_id'],
}
]
});
timestamps: false,
tableName: 'problem',
indexes: [
{
fields: ['title'],
},
{
fields: ['user_id'],
}
]
});
let Model = require('./common');
class Problem extends Model {
@ -472,8 +473,6 @@ class Problem extends Model {
async getJudgeState(user, acFirst) {
if (!user) return null;
let JudgeState = syzoj.model('judge_state');
let where = {
user_id: user.id,
problem_id: this.id
@ -498,6 +497,12 @@ class Problem extends Model {
});
}
async resetSubmissionCount() {
this.submit_num = await JudgeState.count({ score: { $not: null }, problem_id: this.id });
this.ac_num = await JudgeState.count({ score: 100, problem_id: this.id });
await this.save();
}
// type: fastest / slowest / shortest / longest / earliest
async countStatistics(type) {
let statement = statisticsStatements[type];
@ -585,10 +590,12 @@ class Problem extends Model {
let addTagIDs = newTagIDs.filter(x => !oldTagIDs.includes(x));
for (let tagID of delTagIDs) {
let map = await ProblemTagMap.findOne({ where: {
problem_id: this.id,
tag_id: tagID
} });
let map = await ProblemTagMap.findOne({
where: {
problem_id: this.id,
tag_id: tagID
}
});
await map.destroy();
}
@ -605,10 +612,10 @@ class Problem extends Model {
async changeID(id) {
id = parseInt(id);
await db.query('UPDATE `problem` SET `id` = ' + id + ' WHERE `id` = ' + this.id);
await db.query('UPDATE `judge_state` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id);
await db.query('UPDATE `problem_tag_map` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id);
await db.query('UPDATE `article` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id);
await db.query('UPDATE `problem` SET `id` = ' + id + ' WHERE `id` = ' + this.id);
await db.query('UPDATE `judge_state` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id);
await db.query('UPDATE `problem_tag_map` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id);
await db.query('UPDATE `article` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id);
let Contest = syzoj.model('contest');
let contests = await Contest.all();

35
modules/admin.js

@ -198,6 +198,19 @@ app.post('/admin/privilege', async (req, res) => {
}
});
app.get('/admin/other', async (req, res) => {
try {
if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。');
res.render('admin_other');
} catch (e) {
syzoj.log(e);
res.render('error', {
err: e
})
}
});
app.get('/admin/rejudge', async (req, res) => {
try {
if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。');
@ -214,6 +227,28 @@ app.get('/admin/rejudge', async (req, res) => {
}
});
app.post('/admin/other', async (req, res) => {
try {
if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。');
if (req.body.type === 'reset_count') {
const problems = await Problem.query();
for(const p of problems) {
await p.resetSubmissionCount();
}
} else {
throw new ErrorMessage("操作类型不正确");
}
res.redirect(syzoj.utils.makeUrl(['admin', 'other']));
} catch (e) {
syzoj.log(e);
res.render('error', {
err: e
})
}
});
app.post('/admin/rejudge', async (req, res) => {
try {
if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。');

36
modules/problem.js

@ -533,30 +533,30 @@ app.post('/problem/:id/manage', app.multer.fields([{ name: 'testdata', maxCount:
// Set problem public
async function setPublic(req, res, is_public) {
try {
let id = parseInt(req.params.id);
let problem = await Problem.fromID(id);
if (!problem) throw new ErrorMessage('无此题目。');
try {
let id = parseInt(req.params.id);
let problem = await Problem.fromID(id);
if (!problem) throw new ErrorMessage('无此题目。');
let allowedManage = await problem.isAllowedManageBy(res.locals.user);
if (!allowedManage) throw new ErrorMessage('您没有权限进行此操作。');
let allowedManage = await problem.isAllowedManageBy(res.locals.user);
if (!allowedManage) throw new ErrorMessage('您没有权限进行此操作。');
problem.is_public = is_public;
problem.publicizer_id = res.locals.user.id;
await problem.save();
problem.is_public = is_public;
problem.publicizer_id = res.locals.user.id;
await problem.save();
res.redirect(syzoj.utils.makeUrl(['problem', id]));
} catch (e) {
syzoj.log(e);
res.render('error', {
err: e
});
res.redirect(syzoj.utils.makeUrl(['problem', id]));
} catch (e) {
syzoj.log(e);
res.render('error', {
err: e
});
}
}
}
app.post('/problem/:id/public', async (req, res) => {
await setPublic(req, res, true);
});
await setPublic(req, res, true);
});
app.post('/problem/:id/dis_public', async (req, res) => {
await setPublic(req, res, false);

3
views/admin_header.ejs

@ -5,7 +5,8 @@ let items = {
privilege: '权限管理',
rejudge: '一键重测',
links: '友链管理',
raw: '配置文件'
raw: '配置文件',
other: '其他操作'
};
%>
<% this.title = items[this.adminPage] + ' - 后台管理'; %>

7
views/admin_other.ejs

@ -0,0 +1,7 @@
<% this.adminPage = 'rejudge'; %>
<% include admin_header %>
<form method="post" class="ui form">
<button class="ui blue button" name="type" value="reset_count" type="submit">重新计算提交及 AC 数</button>
<!-- <button name="type" value="reset_size" type="submit">重新计算代码大小</button> -->
</form>
<% include admin_footer %>

1
views/admin_rejudge.ejs

@ -1,7 +1,6 @@
<% this.adminPage = 'rejudge'; %>
<% include admin_header %>
<form method="post" class="ui form">
<div class="four fields">
<div class="field">
<label>题目 ID</label>

1
views/problem_manage.ejs

@ -4,6 +4,7 @@
<div class="ui grid">
<div class="row">
<div class="seven wide column">
<form class="ui form" method="post" action=""></form>
<% include problem_testcases %>
</div>
<div class="nine wide column">

Loading…
Cancel
Save