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

+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 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 };