core: 优化AC量计算

- 比赛中不计入nAccept
- script.problemStat添加用户AC量统计
This commit is contained in:
undefined committed 2021-02-10 12:53:42 +08:00
1 parent 0ceb095314
commit fa1392fa4b
4 files changed
+56 -13

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.17.12", "version": "2.17.13",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
+6 -8
View File
@@ -19,6 +19,10 @@ async function _postJudge(rdoc: Rdoc) {
if (typeof rdoc.input === 'string') return; if (typeof rdoc.input === 'string') return;
const accept = rdoc.status === builtin.STATUS.STATUS_ACCEPTED; const accept = rdoc.status === builtin.STATUS.STATUS_ACCEPTED;
const tasks = []; const tasks = [];
tasks.push(
problem.inc(rdoc.domainId, rdoc.pid, 'nAccept', 1),
problem.updateStatus(rdoc.domainId, rdoc.pid, rdoc.uid, rdoc._id, rdoc.status),
);
if (rdoc.contest) { if (rdoc.contest) {
tasks.push( tasks.push(
contest.updateStatus( contest.updateStatus(
@@ -26,14 +30,8 @@ async function _postJudge(rdoc: Rdoc) {
rdoc._id, rdoc.pid, accept, rdoc.score, rdoc.contest.type, rdoc._id, rdoc.pid, accept, rdoc.score, rdoc.contest.type,
), ),
); );
} } else {
if (await problem.updateStatus(rdoc.domainId, rdoc.pid, rdoc.uid, rdoc._id, rdoc.status)) { tasks.push(domain.incUserInDomain(rdoc.domainId, rdoc.uid, 'nAccept', 1));
if (accept && !rdoc.rejudged) {
tasks.push(
problem.inc(rdoc.domainId, rdoc.pid, 'nAccept', 1),
domain.incUserInDomain(rdoc.domainId, rdoc.uid, 'nAccept', 1),
);
}
} }
await Promise.all(tasks); await Promise.all(tasks);
} }
+4 -2
View File
@@ -303,10 +303,12 @@ export async function setMultiStatus<K extends keyof DocStatusType>(
export async function setIfNotStatus<T extends keyof DocStatusType, K extends keyof DocStatusType[T]>( export async function setIfNotStatus<T extends keyof DocStatusType, K extends keyof DocStatusType[T]>(
domainId: string, docType: T, docId: DocStatusType[T]['docId'], uid: number, domainId: string, docType: T, docId: DocStatusType[T]['docId'], uid: number,
key: K, value: number, ifNot: DocStatusType[T][K], args: Partial<DocStatusType[T]>, key: K, value: DocStatusType[T][K], ifNot: DocStatusType[T][K], args: Partial<DocStatusType[T]>,
): Promise<DocStatusType[T]> { ): Promise<DocStatusType[T]> {
const current = await collStatus.findOne({ domainId, docType, docId, uid }) || {};
if (current[key] === ifNot) return current;
const res = await collStatus.findOneAndUpdate( const res = await collStatus.findOneAndUpdate(
{ domainId, docType, docId, uid, [key]: { $not: { $eq: ifNot } } }, { domainId, docType, docId, uid },
{ $set: { [key]: value, ...args } }, { $set: { [key]: value, ...args } },
{ upsert: true, returnOriginal: false }, { upsert: true, returnOriginal: false },
); );
+45 -2
View File
@@ -4,11 +4,50 @@ import * as document from '../model/document';
export const description = 'Recalcuates nSubmit and nAccept in problem status.'; export const description = 'Recalcuates nSubmit and nAccept in problem status.';
export async function run() { export async function udoc() {
const pipeline = [ const pipeline = [
{ $match: { hidden: false, type: { $ne: 'run' } } },
{ {
$match: { hidden: false, type: { $ne: 'run' } }, $group: {
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
nSubmit: { $sum: 1 },
nAccept: {
$sum: {
$cond: [{ $eq: ['$status', STATUS.STATUS_ACCEPTED] }, 1, 0],
},
},
},
}, },
{
$group: {
_id: { domainId: '$_id.domainId', uid: '$_id.uid' },
nSubmit: { $sum: '$nSubmit' },
nAccept: { $sum: { $min: ['$nAccept', 1] } },
},
},
];
const bulk = db.collection('domain.user').initializeUnorderedBulkOp();
db.collection('record').aggregate(pipeline).each(
(err, adoc: any) => {
if (adoc) {
bulk.find({
domainId: adoc._id.domainId,
uid: adoc._id.uid,
}).updateOne({
$set: {
nSubmit: adoc.nSubmit,
nAccept: adoc.nAccept,
},
});
}
},
);
if (bulk.length) await bulk.execute();
}
export async function pdoc() {
const pipeline = [
{ $match: { hidden: false, type: { $ne: 'run' } } },
{ {
$group: { $group: {
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' }, _id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
@@ -48,6 +87,10 @@ export async function run() {
if (bulk.length) await bulk.execute(); if (bulk.length) await bulk.execute();
} }
export async function run() {
return await Promise.all([udoc(), pdoc()]);
}
export const validate = {}; export const validate = {};
global.Hydro.script.problemStat = { run, description, validate }; global.Hydro.script.problemStat = { run, description, validate };