mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
v2.5.0
This commit is contained in:
1 parent
0de7cd7b59
commit
7d7b12392f
18 files changed
+90
-47
No files matched your search
@@ -1,3 +1,5 @@
|
||||
const description = 'Add blacklist by ip, uid';
|
||||
|
||||
// This code format is just for fun. DO NOT DO THIS IN YOUR CODE !
|
||||
/* eslint-disable */
|
||||
const { ObjectID } = require('bson');
|
||||
@@ -61,4 +63,4 @@ async function run({address = null, discuss = null, user = null, dryrun = true},
|
||||
if (user)
|
||||
await _user(user, new Set(), new Set(), new Set(), dryrun, report) }
|
||||
|
||||
global.Hydro.script.blacklist = module.exports = { run };
|
||||
global.Hydro.script.blacklist = module.exports = { run, description };
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Delete a user';
|
||||
|
||||
/* eslint-disable no-await-in-loop */
|
||||
const user = require('../model/user');
|
||||
const document = require('../model/document');
|
||||
@@ -85,4 +87,4 @@ async function run({
|
||||
return uid;
|
||||
}
|
||||
|
||||
global.Hydro.script.deleteUser = module.exports = { run };
|
||||
global.Hydro.script.deleteUser = module.exports = { run, description };
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Install';
|
||||
|
||||
const { defaults } = require('lodash');
|
||||
const db = require('../service/db');
|
||||
const { PRIV_ALL } = require('../model/builtin').PRIV;
|
||||
@@ -66,4 +68,4 @@ async function run({ username, password } = {}) {
|
||||
await Promise.all(tasks);
|
||||
}
|
||||
|
||||
global.Hydro.script.install = module.exports = { run };
|
||||
global.Hydro.script.install = module.exports = { run, description };
|
||||
@@ -0,0 +1,47 @@
|
||||
const description = 'Recalcuates nSubmit and nAccept in problem status.';
|
||||
|
||||
const db = require('../service/db');
|
||||
const { STATUS_ACCEPTED } = require('../model/builtin').STATUS;
|
||||
const document = require('../model/document');
|
||||
|
||||
async function run() {
|
||||
const pipeline = [
|
||||
{
|
||||
$match: { hidden: false, type: { $ne: 'run' } },
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
|
||||
nSubmit: { $sum: 1 },
|
||||
nAccept: {
|
||||
$sum: {
|
||||
$cond: [{ $eq: ['$status', STATUS_ACCEPTED] }, 1, 0],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: { domainId: '$_id.domainId', pid: '$_id.pid' },
|
||||
nSubmit: { $sum: '$nSubmit' },
|
||||
nAccept: { $sum: { $min: ['$nAccept', 1] } },
|
||||
},
|
||||
},
|
||||
];
|
||||
const bulk = db.collection('document').initializeUnorderedBulkOp();
|
||||
db.collection('record').aggregate(pipeline).forEach(
|
||||
(adoc) => bulk.find({
|
||||
domainId: adoc._id.domainId,
|
||||
docType: document.TYPE_PROBLEM,
|
||||
docId: adoc._id.pid,
|
||||
}).updateOne({
|
||||
$set: {
|
||||
nSubmit: adoc.nSubmit,
|
||||
nAccept: adoc.nAccept,
|
||||
},
|
||||
}),
|
||||
);
|
||||
await bulk.execute();
|
||||
}
|
||||
|
||||
global.Hydro.script.problemStat = module.exports = { run, description };
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Calculate the rating of a contest';
|
||||
|
||||
const { ObjectID } = require('bson');
|
||||
const contest = require('../model/contest');
|
||||
const user = require('../model/user');
|
||||
@@ -18,4 +20,4 @@ async function run({ domainId, contestId }) {
|
||||
return rated;
|
||||
}
|
||||
|
||||
global.Hydro.script.rating = module.exports = { run };
|
||||
global.Hydro.script.rating = module.exports = { run, description };
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Calculate rating of a domain, or all domains';
|
||||
|
||||
/* eslint-disable no-await-in-loop */
|
||||
const domain = require('../model/domain');
|
||||
const contest = require('../model/contest');
|
||||
@@ -64,4 +66,4 @@ async function run({ domainId, isSub = false }, report) {
|
||||
return true;
|
||||
}
|
||||
|
||||
global.Hydro.script.recalcRating = module.exports = { run };
|
||||
global.Hydro.script.recalcRating = module.exports = { run, description };
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Create a new user';
|
||||
|
||||
const user = require('../model/user');
|
||||
const system = require('../model/system');
|
||||
|
||||
@@ -13,4 +15,4 @@ async function run({
|
||||
return uid;
|
||||
}
|
||||
|
||||
global.Hydro.script.register = module.exports = { run };
|
||||
global.Hydro.script.register = module.exports = { run, description };
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Set a user as superadmin.';
|
||||
|
||||
const user = require('../model/user');
|
||||
const { PRIV_ALL } = require('../model/builtin').PRIV;
|
||||
|
||||
@@ -10,4 +12,4 @@ async function run({
|
||||
return uid;
|
||||
}
|
||||
|
||||
global.Hydro.script.setSuperadmin = module.exports = { run };
|
||||
global.Hydro.script.setSuperadmin = module.exports = { run, description };
|
||||
@@ -1,8 +0,0 @@
|
||||
const db = require('../service/db.js');
|
||||
|
||||
async function run() {
|
||||
await db.dropDatabase();
|
||||
console.log('Dropped');
|
||||
}
|
||||
|
||||
global.Hydro.script.uninstall = module.exports = { run };
|
||||
Reference in new issue
Block a user