mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
更新rating计算逻辑:(score-,rid+,allUsers)
This commit is contained in:
1 parent
d077019e0d
commit
51dc2e972d
3 files changed
+34
-12
No files matched your search
+31
-10
@@ -23,22 +23,24 @@ function calc(udict: ND, rankedDocs: [number, number][]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runProblem(pdoc: Pdoc, udict: ND): Promise<void>
|
async function runProblem(pdoc: Pdoc, udict: ND, uids: number[]): Promise<void>
|
||||||
async function runProblem(domainId: string, pid: number, udict: ND): Promise<void>
|
async function runProblem(domainId: string, pid: number, udict: ND, uids: number[]): Promise<void>
|
||||||
async function runProblem(...arg: Array<any>) {
|
async function runProblem(...arg: any[]) {
|
||||||
const pdoc: Pdoc = (typeof arg[0] === 'string')
|
const pdoc: Pdoc = (typeof arg[0] === 'string')
|
||||||
? await contest.get(arg[0], arg[1], -1)
|
? await contest.get(arg[0], arg[1], -1)
|
||||||
: arg[0];
|
: arg[0];
|
||||||
const udict: ND = (typeof arg[0] === 'string') ? arg[2] : arg[1];
|
const udict: ND = (typeof arg[0] === 'string') ? arg[2] : arg[1];
|
||||||
// TODO maybe some other rules?
|
const uids = (typeof arg[0] === 'string') ? arg[3] : arg[2];
|
||||||
// TODO pagination
|
|
||||||
const psdocs = await problem.getMultiStatus(
|
const psdocs = await problem.getMultiStatus(
|
||||||
pdoc.domainId, { docId: pdoc.docId, status: STATUS.STATUS_ACCEPTED },
|
pdoc.domainId, { docId: pdoc.docId },
|
||||||
).sort('rid', 1).toArray();
|
).sort({ score: -1, _id: 1 }).toArray();
|
||||||
const ranked = [];
|
const ranked = [];
|
||||||
|
const u = new Set(Array.from(uids));
|
||||||
for (const index in psdocs) {
|
for (const index in psdocs) {
|
||||||
ranked.push([index + 1, psdocs[index].uid]);
|
ranked.push([index + 1, psdocs[index].uid]);
|
||||||
|
u.delete(psdocs[index].uid);
|
||||||
}
|
}
|
||||||
|
u.forEach((uid) => ranked.push(psdocs.length, uid));
|
||||||
calc(udict, ranked);
|
calc(udict, ranked);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +48,7 @@ async function runContest(tdoc: Tdoc, udict: ND, report: Function): Promise<void
|
|||||||
async function runContest(
|
async function runContest(
|
||||||
domainId: string, tid: ObjectID, udict: ND, report: Function
|
domainId: string, tid: ObjectID, udict: ND, report: Function
|
||||||
): Promise<void>
|
): Promise<void>
|
||||||
async function runContest(...arg: Array<any>) {
|
async function runContest(...arg: any[]) {
|
||||||
const start = new Date().getTime();
|
const start = new Date().getTime();
|
||||||
const tdoc: Tdoc = (typeof arg[0] === 'string')
|
const tdoc: Tdoc = (typeof arg[0] === 'string')
|
||||||
? await contest.get(arg[0], arg[1], -1)
|
? await contest.get(arg[0], arg[1], -1)
|
||||||
@@ -72,15 +74,34 @@ async function runContest(...arg: Array<any>) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getRelatedUsers(domainId: string) {
|
||||||
|
const uids: Set<number> = new Set();
|
||||||
|
const problems = await problem.getMulti(domainId, { hidden: false }).toArray();
|
||||||
|
for (const pdoc of problems) {
|
||||||
|
const psdocs = await problem.getMultiStatus(
|
||||||
|
pdoc.domainId, { docId: pdoc.docId, status: STATUS.STATUS_ACCEPTED },
|
||||||
|
).sort('rid', 1).toArray();
|
||||||
|
for (const psdoc of psdocs) uids.add(psdoc.uid);
|
||||||
|
}
|
||||||
|
const contests = await contest.getMulti(domainId, { rated: true }, -1).sort('endAt', -1).toArray();
|
||||||
|
for (const tdoc of contests) {
|
||||||
|
const tsdocs = await contest.getMultiStatus(tdoc.domainId, tdoc.docId, tdoc.docType)
|
||||||
|
.sort(contest.RULES[tdoc.rule].statusSort).toArray();
|
||||||
|
for (const tsdoc of tsdocs) uids.add(tsdoc.uid);
|
||||||
|
}
|
||||||
|
return Array.from(uids);
|
||||||
|
}
|
||||||
|
|
||||||
async function runInDomain(domainId: string, isSub: boolean, report: Function) {
|
async function runInDomain(domainId: string, isSub: boolean, report: Function) {
|
||||||
await domain.setMultiUserInDomain(domainId, {}, { rating: 1500 });
|
await domain.setMultiUserInDomain(domainId, {}, { rating: 1500 });
|
||||||
|
const uids = await getRelatedUsers(domainId);
|
||||||
const udict: ND = {};
|
const udict: ND = {};
|
||||||
// TODO pagination
|
// TODO pagination
|
||||||
const problems = await problem.getMulti(domainId, { hidden: false }).toArray();
|
const problems = await problem.getMulti(domainId, { hidden: false }).toArray();
|
||||||
await report({ message: `Found ${problems.length} problems in ${domainId}` });
|
await report({ message: `Found ${problems.length} problems in ${domainId}` });
|
||||||
for (const i in problems) {
|
for (const i in problems) {
|
||||||
const pdoc = problems[i];
|
const pdoc = problems[i];
|
||||||
runProblem(pdoc, udict);
|
await runProblem(pdoc, udict, uids);
|
||||||
if (!isSub) {
|
if (!isSub) {
|
||||||
await report({
|
await report({
|
||||||
progress: Math.floor(((parseInt(i, 10) + 1) / problems.length) * 100),
|
progress: Math.floor(((parseInt(i, 10) + 1) / problems.length) * 100),
|
||||||
@@ -91,7 +112,7 @@ async function runInDomain(domainId: string, isSub: boolean, report: Function) {
|
|||||||
await report({ message: `Found ${contests.length} contests in ${domainId}` });
|
await report({ message: `Found ${contests.length} contests in ${domainId}` });
|
||||||
for (const i in contests) {
|
for (const i in contests) {
|
||||||
const tdoc = contests[i];
|
const tdoc = contests[i];
|
||||||
runContest(tdoc, udict, report);
|
await runContest(tdoc, udict, report);
|
||||||
if (!isSub) {
|
if (!isSub) {
|
||||||
await report({
|
await report({
|
||||||
progress: Math.floor(((parseInt(i, 10) + 1) / contests.length) * 100),
|
progress: Math.floor(((parseInt(i, 10) + 1) / contests.length) * 100),
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ export const description = 'Upgrade database from 0 to 1';
|
|||||||
export async function run() {
|
export async function run() {
|
||||||
const ddoc = await domain.get('system');
|
const ddoc = await domain.get('system');
|
||||||
if (!ddoc) await domain.add('system', 0, 'Hydro', 'Hydro System');
|
if (!ddoc) await domain.add('system', 0, 'Hydro', 'Hydro System');
|
||||||
|
// TODO discussion node?
|
||||||
}
|
}
|
||||||
|
|
||||||
export const validate = {};
|
export const validate = {};
|
||||||
|
|
||||||
global.Hydro.script.setSuperadmin = { run, description, validate };
|
global.Hydro.script.upgrade0_1 = { run, description, validate };
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.10.12",
|
"version": "2.10.13",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
Reference in new issue
Block a user