You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
4 years ago
|
import * as db from '../service/db';
|
||
|
import { STATUS } from '../model/builtin';
|
||
|
import * as document from '../model/document';
|
||
4 years ago
|
|
||
4 years ago
|
export const description = 'Recalcuates nSubmit and nAccept in problem status.';
|
||
4 years ago
|
|
||
4 years ago
|
export async function run() {
|
||
4 years ago
|
const pipeline = [
|
||
|
{
|
||
|
$match: { hidden: false, type: { $ne: 'run' } },
|
||
|
},
|
||
|
{
|
||
|
$group: {
|
||
|
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
|
||
|
nSubmit: { $sum: 1 },
|
||
|
nAccept: {
|
||
|
$sum: {
|
||
4 years ago
|
$cond: [{ $eq: ['$status', STATUS.STATUS_ACCEPTED] }, 1, 0],
|
||
4 years ago
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
$group: {
|
||
|
_id: { domainId: '$_id.domainId', pid: '$_id.pid' },
|
||
|
nSubmit: { $sum: '$nSubmit' },
|
||
|
nAccept: { $sum: { $min: ['$nAccept', 1] } },
|
||
|
},
|
||
|
},
|
||
|
];
|
||
|
const bulk = db.collection('document').initializeUnorderedBulkOp();
|
||
4 years ago
|
db.collection('record').aggregate(pipeline).each(
|
||
|
(err, adoc: any) => bulk.find({
|
||
4 years ago
|
domainId: adoc._id.domainId,
|
||
|
docType: document.TYPE_PROBLEM,
|
||
|
docId: adoc._id.pid,
|
||
|
}).updateOne({
|
||
|
$set: {
|
||
|
nSubmit: adoc.nSubmit,
|
||
|
nAccept: adoc.nAccept,
|
||
|
},
|
||
|
}),
|
||
|
);
|
||
|
await bulk.execute();
|
||
|
}
|
||
|
|
||
4 years ago
|
export const validate = {};
|
||
|
|
||
|
global.Hydro.script.problemStat = { run, description, validate };
|