mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: 优化AC量计算
- 比赛中不计入nAccept - script.problemStat添加用户AC量统计
This commit is contained in:
1 parent
0ceb095314
commit
fa1392fa4b
4 files changed
+56
-13
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.17.12",
|
||||
"version": "2.17.13",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -19,6 +19,10 @@ async function _postJudge(rdoc: Rdoc) {
|
||||
if (typeof rdoc.input === 'string') return;
|
||||
const accept = rdoc.status === builtin.STATUS.STATUS_ACCEPTED;
|
||||
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) {
|
||||
tasks.push(
|
||||
contest.updateStatus(
|
||||
@@ -26,14 +30,8 @@ async function _postJudge(rdoc: Rdoc) {
|
||||
rdoc._id, rdoc.pid, accept, rdoc.score, rdoc.contest.type,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (await problem.updateStatus(rdoc.domainId, rdoc.pid, rdoc.uid, rdoc._id, rdoc.status)) {
|
||||
if (accept && !rdoc.rejudged) {
|
||||
tasks.push(
|
||||
problem.inc(rdoc.domainId, rdoc.pid, 'nAccept', 1),
|
||||
domain.incUserInDomain(rdoc.domainId, rdoc.uid, 'nAccept', 1),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
tasks.push(domain.incUserInDomain(rdoc.domainId, rdoc.uid, 'nAccept', 1));
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
}
|
||||
|
||||
@@ -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]>(
|
||||
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]> {
|
||||
const current = await collStatus.findOne({ domainId, docType, docId, uid }) || {};
|
||||
if (current[key] === ifNot) return current;
|
||||
const res = await collStatus.findOneAndUpdate(
|
||||
{ domainId, docType, docId, uid, [key]: { $not: { $eq: ifNot } } },
|
||||
{ domainId, docType, docId, uid },
|
||||
{ $set: { [key]: value, ...args } },
|
||||
{ upsert: true, returnOriginal: false },
|
||||
);
|
||||
|
||||
@@ -4,11 +4,50 @@ import * as document from '../model/document';
|
||||
|
||||
export const description = 'Recalcuates nSubmit and nAccept in problem status.';
|
||||
|
||||
export async function run() {
|
||||
export async function udoc() {
|
||||
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: {
|
||||
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
|
||||
@@ -48,6 +87,10 @@ export async function run() {
|
||||
if (bulk.length) await bulk.execute();
|
||||
}
|
||||
|
||||
export async function run() {
|
||||
return await Promise.all([udoc(), pdoc()]);
|
||||
}
|
||||
|
||||
export const validate = {};
|
||||
|
||||
global.Hydro.script.problemStat = { run, description, validate };
|
||||
Reference in new issue
Block a user