diff --git a/hydro/script/rating.ts b/hydro/script/rating.ts index 9b7f0d72b..de81f363c 100644 --- a/hydro/script/rating.ts +++ b/hydro/script/rating.ts @@ -23,22 +23,24 @@ function calc(udict: ND, rankedDocs: [number, number][]) { } } -async function runProblem(pdoc: Pdoc, udict: ND): Promise -async function runProblem(domainId: string, pid: number, udict: ND): Promise -async function runProblem(...arg: Array) { +async function runProblem(pdoc: Pdoc, udict: ND, uids: number[]): Promise +async function runProblem(domainId: string, pid: number, udict: ND, uids: number[]): Promise +async function runProblem(...arg: any[]) { const pdoc: Pdoc = (typeof arg[0] === 'string') ? await contest.get(arg[0], arg[1], -1) : arg[0]; const udict: ND = (typeof arg[0] === 'string') ? arg[2] : arg[1]; - // TODO maybe some other rules? - // TODO pagination + const uids = (typeof arg[0] === 'string') ? arg[3] : arg[2]; const psdocs = await problem.getMultiStatus( - pdoc.domainId, { docId: pdoc.docId, status: STATUS.STATUS_ACCEPTED }, - ).sort('rid', 1).toArray(); + pdoc.domainId, { docId: pdoc.docId }, + ).sort({ score: -1, _id: 1 }).toArray(); const ranked = []; + const u = new Set(Array.from(uids)); for (const index in psdocs) { ranked.push([index + 1, psdocs[index].uid]); + u.delete(psdocs[index].uid); } + u.forEach((uid) => ranked.push(psdocs.length, uid)); calc(udict, ranked); } @@ -46,7 +48,7 @@ async function runContest(tdoc: Tdoc, udict: ND, report: Function): Promise -async function runContest(...arg: Array) { +async function runContest(...arg: any[]) { const start = new Date().getTime(); const tdoc: Tdoc = (typeof arg[0] === 'string') ? await contest.get(arg[0], arg[1], -1) @@ -72,15 +74,34 @@ async function runContest(...arg: Array) { }); } +async function getRelatedUsers(domainId: string) { + const uids: Set = 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) { await domain.setMultiUserInDomain(domainId, {}, { rating: 1500 }); + const uids = await getRelatedUsers(domainId); const udict: ND = {}; // TODO pagination const problems = await problem.getMulti(domainId, { hidden: false }).toArray(); await report({ message: `Found ${problems.length} problems in ${domainId}` }); for (const i in problems) { const pdoc = problems[i]; - runProblem(pdoc, udict); + await runProblem(pdoc, udict, uids); if (!isSub) { await report({ 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}` }); for (const i in contests) { const tdoc = contests[i]; - runContest(tdoc, udict, report); + await runContest(tdoc, udict, report); if (!isSub) { await report({ progress: Math.floor(((parseInt(i, 10) + 1) / contests.length) * 100), diff --git a/hydro/script/upgrade0_1.ts b/hydro/script/upgrade0_1.ts index ebd7872b6..8a7ec77a2 100644 --- a/hydro/script/upgrade0_1.ts +++ b/hydro/script/upgrade0_1.ts @@ -5,8 +5,9 @@ export const description = 'Upgrade database from 0 to 1'; export async function run() { const ddoc = await domain.get('system'); if (!ddoc) await domain.add('system', 0, 'Hydro', 'Hydro System'); + // TODO discussion node? } export const validate = {}; -global.Hydro.script.setSuperadmin = { run, description, validate }; +global.Hydro.script.upgrade0_1 = { run, description, validate }; diff --git a/package.json b/package.json index 45aacb6f3..0d526a4c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.10.12", + "version": "2.10.13", "main": "dist/loader.js", "bin": "bin/hydrooj.js", "repository": "https://github.com/hydro-dev/Hydro.git",