core: calc difficulty after each submission

This commit is contained in:
undefined committed 2021-03-12 17:08:14 +08:00
1 parent 139c1e2f59
commit 44ec26ac89
7 files changed
+24 -23

No files matched your search

+6 -1
View File
@@ -2,6 +2,7 @@ import { ObjectID } from 'mongodb';
import { JudgeResultBody, Rdoc, TestCase } from '../interface';
import { sleep } from '../utils';
import { Logger } from '../logger';
import difficultyAlgorithm from '../lib/difficulty';
import * as record from '../model/record';
import * as problem from '../model/problem';
import * as builtin from '../model/builtin';
@@ -27,7 +28,11 @@ async function _postJudge(rdoc: Rdoc) {
rdoc._id, rdoc.pid, accept, rdoc.score, rdoc.contest.type,
);
} else if (updated) await domain.incUserInDomain(rdoc.domainId, rdoc.uid, 'nAccept', 1);
if (accept && updated) await problem.inc(rdoc.domainId, rdoc.pid, 'nAccept', 1);
const pdoc = (accept && updated)
? await problem.inc(rdoc.domainId, rdoc.pid, 'nAccept', 1)
: await problem.get(rdoc.domainId, rdoc.pid);
const difficulty = difficultyAlgorithm(pdoc.nSubmit, pdoc.nAccept);
await problem.edit(pdoc.domainId, pdoc.docId, { difficulty });
}
export async function next(body: JudgeResultBody) {
+2 -1
View File
@@ -10,6 +10,7 @@ import {
} from '../interface';
import paginate from '../lib/paginate';
import { isTitle, isContent, isPid } from '../lib/validator';
import difficultyAlgorithm from '../lib/difficulty';
import * as system from '../model/system';
import * as problem from '../model/problem';
import * as record from '../model/record';
@@ -333,10 +334,10 @@ export class ProblemEditHandler extends ProblemManageHandler {
title, content, pid: newPid, hidden, tag: tag ?? [],
};
let pdoc = await problem.get(domainId, pid);
$update.difficulty = difficultyAlgorithm(pdoc.nSubmit, pdoc.nAccept);
await bus.serial('problem/before-edit', $update);
pdoc = await problem.edit(domainId, pdoc.docId, $update);
await bus.emit('problem/edit', pdoc);
await global.Hydro.script.difficulty.run({ domainId, pid }, console.log);
this.response.redirect = this.url('problem_detail', { pid: newPid || pdoc.docId });
}
}