Browse Source

Add page to reset submission count.

pull/6/head
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 = { let statisticsStatements = {
fastest: fastest:
'\ '\
SELECT \ SELECT \
DISTINCT(`user_id`) AS `user_id`, \ DISTINCT(`user_id`) AS `user_id`, \
( \ ( \
@ -46,7 +46,7 @@ WHERE \
ORDER BY `total_time` ASC \ ORDER BY `total_time` ASC \
', ',
slowest: slowest:
' \ ' \
SELECT \ SELECT \
DISTINCT(`user_id`) AS `user_id`, \ DISTINCT(`user_id`) AS `user_id`, \
( \ ( \
@ -71,7 +71,7 @@ WHERE \
ORDER BY `total_time` DESC \ ORDER BY `total_time` DESC \
', ',
shortest: shortest:
' \ ' \
SELECT \ SELECT \
DISTINCT(`user_id`) AS `user_id`, \ DISTINCT(`user_id`) AS `user_id`, \
( \ ( \
@ -96,7 +96,7 @@ WHERE \
ORDER BY `code_length` ASC \ ORDER BY `code_length` ASC \
', ',
longest: longest:
' \ ' \
SELECT \ SELECT \
DISTINCT(`user_id`) AS `user_id`, \ DISTINCT(`user_id`) AS `user_id`, \
( \ ( \
@ -121,7 +121,7 @@ WHERE \
ORDER BY `code_length` DESC \ ORDER BY `code_length` DESC \
', ',
earliest: earliest:
' \ ' \
SELECT \ SELECT \
DISTINCT(`user_id`) AS `user_id`, \ DISTINCT(`user_id`) AS `user_id`, \
( \ ( \
@ -146,7 +146,7 @@ WHERE \
ORDER BY `submit_time` ASC \ ORDER BY `submit_time` ASC \
', ',
min: min:
' \ ' \
SELECT \ SELECT \
DISTINCT(`user_id`) AS `user_id`, \ DISTINCT(`user_id`) AS `user_id`, \
( \ ( \
@ -171,7 +171,7 @@ WHERE \
ORDER BY `max_memory` ASC \ ORDER BY `max_memory` ASC \
', ',
max: max:
' \ ' \
SELECT \ SELECT \
DISTINCT(`user_id`) AS `user_id`, \ DISTINCT(`user_id`) AS `user_id`, \
( \ ( \
@ -201,6 +201,7 @@ let Sequelize = require('sequelize');
let db = syzoj.db; let db = syzoj.db;
let User = syzoj.model('user'); let User = syzoj.model('user');
let JudgeState = syzoj.model('judge_state');
let File = syzoj.model('file'); let File = syzoj.model('file');
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path'); const path = require('path');
@ -249,17 +250,17 @@ let model = db.define('problem', {
values: ['traditional', 'submit-answer', 'interaction'] values: ['traditional', 'submit-answer', 'interaction']
} }
}, { }, {
timestamps: false, timestamps: false,
tableName: 'problem', tableName: 'problem',
indexes: [ indexes: [
{ {
fields: ['title'], fields: ['title'],
}, },
{ {
fields: ['user_id'], fields: ['user_id'],
} }
] ]
}); });
let Model = require('./common'); let Model = require('./common');
class Problem extends Model { class Problem extends Model {
@ -472,8 +473,6 @@ class Problem extends Model {
async getJudgeState(user, acFirst) { async getJudgeState(user, acFirst) {
if (!user) return null; if (!user) return null;
let JudgeState = syzoj.model('judge_state');
let where = { let where = {
user_id: user.id, user_id: user.id,
problem_id: this.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 // type: fastest / slowest / shortest / longest / earliest
async countStatistics(type) { async countStatistics(type) {
let statement = statisticsStatements[type]; let statement = statisticsStatements[type];
@ -585,10 +590,12 @@ class Problem extends Model {
let addTagIDs = newTagIDs.filter(x => !oldTagIDs.includes(x)); let addTagIDs = newTagIDs.filter(x => !oldTagIDs.includes(x));
for (let tagID of delTagIDs) { for (let tagID of delTagIDs) {
let map = await ProblemTagMap.findOne({ where: { let map = await ProblemTagMap.findOne({
problem_id: this.id, where: {
tag_id: tagID problem_id: this.id,
} }); tag_id: tagID
}
});
await map.destroy(); await map.destroy();
} }
@ -605,10 +612,10 @@ class Problem extends Model {
async changeID(id) { async changeID(id) {
id = parseInt(id); id = parseInt(id);
await db.query('UPDATE `problem` SET `id` = ' + id + ' WHERE `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 `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 `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 `article` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id);
let Contest = syzoj.model('contest'); let Contest = syzoj.model('contest');
let contests = await Contest.all(); 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) => { app.get('/admin/rejudge', async (req, res) => {
try { try {
if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。'); 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) => { app.post('/admin/rejudge', async (req, res) => {
try { try {
if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。'); 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 // Set problem public
async function setPublic(req, res, is_public) { async function setPublic(req, res, is_public) {
try { try {
let id = parseInt(req.params.id); let id = parseInt(req.params.id);
let problem = await Problem.fromID(id); let problem = await Problem.fromID(id);
if (!problem) throw new ErrorMessage('无此题目。'); if (!problem) throw new ErrorMessage('无此题目。');
let allowedManage = await problem.isAllowedManageBy(res.locals.user); let allowedManage = await problem.isAllowedManageBy(res.locals.user);
if (!allowedManage) throw new ErrorMessage('您没有权限进行此操作。'); if (!allowedManage) throw new ErrorMessage('您没有权限进行此操作。');
problem.is_public = is_public; problem.is_public = is_public;
problem.publicizer_id = res.locals.user.id; problem.publicizer_id = res.locals.user.id;
await problem.save(); await problem.save();
res.redirect(syzoj.utils.makeUrl(['problem', id])); res.redirect(syzoj.utils.makeUrl(['problem', id]));
} catch (e) { } catch (e) {
syzoj.log(e); syzoj.log(e);
res.render('error', { res.render('error', {
err: e err: e
}); });
}
} }
}
app.post('/problem/:id/public', async (req, res) => { 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) => { app.post('/problem/:id/dis_public', async (req, res) => {
await setPublic(req, res, false); await setPublic(req, res, false);

3
views/admin_header.ejs

@ -5,7 +5,8 @@ let items = {
privilege: '权限管理', privilege: '权限管理',
rejudge: '一键重测', rejudge: '一键重测',
links: '友链管理', links: '友链管理',
raw: '配置文件' raw: '配置文件',
other: '其他操作'
}; };
%> %>
<% this.title = items[this.adminPage] + ' - 后台管理'; %> <% 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'; %> <% this.adminPage = 'rejudge'; %>
<% include admin_header %> <% include admin_header %>
<form method="post" class="ui form"> <form method="post" class="ui form">
<div class="four fields"> <div class="four fields">
<div class="field"> <div class="field">
<label>题目 ID</label> <label>题目 ID</label>

1
views/problem_manage.ejs

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

Loading…
Cancel
Save