mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 01: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
@@ -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