onsite-toolkit: add resolver (#706)

Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
undefinedandpanda authored and GitHub committed 2024-11-13 10:26:13 +08:00
1 parent d1e79f3a9c
commit f888537757
7 files changed
+510 -6

No files matched your search

+44 -1
View File
@@ -1,6 +1,8 @@
import {
Context, db, ForbiddenError, UserModel,
avatar, ContestModel, Context, db, ForbiddenError,
ObjectId, PERM, STATUS, Time, UserModel,
} from 'hydrooj';
import { ResolverInput } from './interface';
interface IpLoginInfo {
_id: string;
@@ -33,4 +35,45 @@ export function apply(ctx: Context) {
that.session.user = that.user;
}
});
ctx.inject(['scoreboard'], ({ scoreboard }) => {
scoreboard.addView('resolver-tiny', 'Resolver(Tiny)', { tdoc: 'tdoc' }, {
async display({ tdoc }) {
if (!this.user.own(tdoc)) this.checkPerm(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
const teams = await ContestModel.getMultiStatus(tdoc.domainId, { docId: tdoc.docId }).toArray();
const udict = await UserModel.getList(tdoc.domainId, teams.map((i) => i.uid));
const teamIds: Record<number, number> = {};
for (let i = 1; i <= teams.length; i++) teamIds[teams[i - 1].uid] = i;
const time = (t: ObjectId) => Math.floor((t.getTimestamp().getTime() - tdoc.beginAt.getTime()) / Time.second);
const pid = (i: number) => String.fromCharCode(65 + i);
const unknownSchool = this.translate('Unknown School');
const submissions = teams.flatMap((i) => {
if (!i.journal) return [];
return i.journal.filter((s) => tdoc.pids.includes(s.pid)).map((s) => ({ ...s, uid: i.uid }));
});
this.response.body = {
payload: {
name: tdoc.title,
duration: Math.floor((new Date(tdoc.endAt).getTime() - new Date(tdoc.beginAt).getTime()) / 1000),
frozen: Math.floor((new Date(tdoc.endAt).getTime() - new Date(tdoc.lockAt).getTime()) / 1000),
problems: tdoc.pids.map((i, n) => ({ name: pid(n), id: i.toString() })),
teams: teams.map((t) => ({
id: t.uid.toString(),
name: udict[t.uid].uname,
avatar: avatar(udict[t.uid].avatar),
institution: udict[t.uid].school || unknownSchool,
})),
submissions: submissions.map((i) => ({
team: i.uid.toString(),
problem: i.pid.toString(),
verdict: i.status === STATUS.STATUS_ACCEPTED ? 'AC' : 'RJ',
time: time(i.rid),
})),
} as ResolverInput,
};
this.response.template = 'resolver.html';
},
supportedRules: ['acm'],
});
});
}