Browse Source

Fix statistics bugs

pull/6/head
Menci 5 years ago
parent
commit
8cc93d5745
  1. 41
      models/problem.ts
  2. 2
      views/problem.ejs
  3. 8
      views/statistics.ejs

41
models/problem.ts

@ -356,7 +356,10 @@ export default class Problem extends Model {
.getRawMany();
const resultRow = result[0];
if (!resultRow || resultRow[column] == null) return;
let toDelete = false;
if (!resultRow || resultRow[column] == null) {
toDelete = true;
}
const baseColumns = {
user_id,
@ -365,6 +368,15 @@ export default class Problem extends Model {
};
let record = await SubmissionStatistics.findOne(baseColumns);
if (toDelete) {
if (record) {
await record.destroy();
}
return;
}
if (!record) {
record = SubmissionStatistics.create(baseColumns);
}
@ -378,6 +390,10 @@ export default class Problem extends Model {
}
async countStatistics(type) {
if (!statisticsTypes[type] || this.type === ProblemType.SubmitAnswer && statisticsCodeOnly.includes(type)) {
return null;
}
return await SubmissionStatistics.count({
problem_id: this.id,
type: type
@ -385,9 +401,11 @@ export default class Problem extends Model {
}
async getStatistics(type, paginate) {
const entityManager = TypeORM.getManager();
if (!statisticsTypes[type] || this.type === ProblemType.SubmitAnswer && statisticsCodeOnly.includes(type)) {
return null;
}
let statistics = {
const statistics = {
type: type,
judge_state: null,
scoreDistribution: null,
@ -409,15 +427,14 @@ export default class Problem extends Model {
.getMany()
: [];
JudgeState.createQueryBuilder()
.select('score')
.addSelect('COUNT(*)', 'count')
.where('problem_id = :problem_id', { problem_id: this.id })
.andWhere('type = 0')
.andWhere('pending = false')
.groupBy('score')
.getRawMany()
let a = (await entityManager.query('SELECT `score`, COUNT(*) AS `count` FROM `judge_state` WHERE `problem_id` = __PROBLEM_ID__ AND `type` = 0 AND `pending` = 0 GROUP BY `score`'.replace('__PROBLEM_ID__', this.id.toString())));
const a = await JudgeState.createQueryBuilder()
.select('score')
.addSelect('COUNT(*)', 'count')
.where('problem_id = :problem_id', { problem_id: this.id })
.andWhere('type = 0')
.andWhere('pending = false')
.groupBy('score')
.getRawMany();
let scoreCount = [];
for (let score of a) {

2
views/problem.ejs

@ -92,7 +92,7 @@ if (contest) {
<a class="small ui primary button" href="#submit_code">提交</a>
<% } %>
<a class="small ui positive button" href="<%= syzoj.utils.makeUrl(['submissions'], { problem_id: problem.id }) %>">提交记录</a>
<a class="small ui orange button" href="<%= syzoj.utils.makeUrl(['problem', problem.id, 'statistics', problem.type === 'submit-answer' ? 'min' : 'fastest']) %>">统计</a>
<a class="small ui orange button" href="<%= syzoj.utils.makeUrl(['problem', problem.id, 'statistics', problem.type === 'submit-answer' ? 'shortest' : 'fastest']) %>">统计</a>
<a class="small ui yellow button" href="<%= syzoj.utils.makeUrl(['problem', problem.id, 'testdata']) %>">测试数据</a>
<% if (problem.additional_file) { %>
<a class="small ui teal button" href="<%= syzoj.utils.makeUrl(['problem', problem.id, 'download', 'additional_file']) %>">附加文件</a>

8
views/statistics.ejs

@ -3,11 +3,11 @@ this.title = '统计';
let types = {
fastest: problem.type === 'submit-answer' ? null : '最快',
slowest: problem.type === 'submit-answer' ? null : '最慢',
shortest: problem.type === 'submit-answer' ? null : '最短',
longest: problem.type === 'submit-answer' ? null : '最长',
shortest: problem.type === 'submit-answer' ? '最小' : '最短',
longest: problem.type === 'submit-answer' ? '最大' : '最长',
earliest: '最早',
min: problem.type === 'submit-answer' ? '最小' : '最小内存',
max: problem.type === 'submit-answer' ? '最大' : '最大内存'
min: problem.type === 'submit-answer' ? null : '最小内存',
max: problem.type === 'submit-answer' ? null : '最大内存'
};
%>
<% include header %>

Loading…
Cancel
Save