mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
workspace: use esnext set operations
This commit is contained in:
12 files changed
+28
-43
No files matched your search
@@ -66,8 +66,8 @@ export async function judge({
|
||||
if (stdAns instanceof Array) {
|
||||
const stdSet = new Set(stdAns);
|
||||
const ans = new Set(answers[key] instanceof Array ? answers[key] : [answers[key]]);
|
||||
if (stdAns.length === ans.size && Set.isSuperset(stdSet, ans)) report(STATUS.STATUS_ACCEPTED, fullScore, 'Correct');
|
||||
else if (ans.size && Set.isSuperset(stdSet, ans)) report(STATUS.STATUS_WRONG_ANSWER, Math.floor(fullScore / 2), 'Partially Correct');
|
||||
if (stdAns.length === ans.size && stdSet.isSupersetOf(ans)) report(STATUS.STATUS_ACCEPTED, fullScore, 'Correct');
|
||||
else if (ans.size && stdSet.isSupersetOf(ans)) report(STATUS.STATUS_WRONG_ANSWER, Math.floor(fullScore / 2), 'Partially Correct');
|
||||
else report(STATUS.STATUS_WRONG_ANSWER, 0, 'Incorrect');
|
||||
} else if (stdAns.toString() === usrAns) report(STATUS.STATUS_ACCEPTED, fullScore, 'Correct');
|
||||
else report(STATUS.STATUS_WRONG_ANSWER, 0, 'Incorrect');
|
||||
|
||||
@@ -88,7 +88,7 @@ export class ContestDetailBaseHandler extends Handler {
|
||||
]);
|
||||
if (this.tdoc.assign?.length && !this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST)) {
|
||||
const groups = await user.listGroup(domainId, this.user._id);
|
||||
if (!Set.intersection(this.tdoc.assign, groups.map((i) => i.name)).size) {
|
||||
if (!new Set(this.tdoc.assign).intersection(new Set(groups.map((i) => i.name))).size) {
|
||||
throw new NotAssignedError('contest', tid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ class DomainRoleHandler extends ManageHandler {
|
||||
@requireSudo
|
||||
@param('roles', Types.ArrayOf(Types.Role))
|
||||
async postDelete(domainId: string, roles: string[]) {
|
||||
if (Set.intersection(roles, ['root', 'default', 'guest']).size > 0) {
|
||||
if (new Set(roles).intersection(new Set(['root', 'default', 'guest'])).size > 0) {
|
||||
throw new ValidationError('role', null, 'You cannot delete root, default or guest roles');
|
||||
}
|
||||
await Promise.all([
|
||||
|
||||
@@ -84,7 +84,7 @@ class HomeworkDetailHandler extends Handler {
|
||||
this.tdoc = await contest.get(domainId, tid);
|
||||
if (this.tdoc.rule !== 'homework') throw new ContestNotFoundError(domainId, tid);
|
||||
if (this.tdoc.assign?.length && !this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_HOMEWORK)) {
|
||||
if (!Set.intersection(this.tdoc.assign, this.user.group).size) {
|
||||
if (!new Set(this.tdoc.assign).intersection(new Set(this.user.group)).size) {
|
||||
throw new NotAssignedError('homework', this.tdoc.docId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler {
|
||||
contest.getRelated(this.args.domainId, this.pdoc.docId),
|
||||
contest.getRelated(this.args.domainId, this.pdoc.docId, 'homework'),
|
||||
])).map((tdocs) => tdocs.filter((tdoc) =>
|
||||
this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST) || !tdoc.assign?.length || Set.intersection(tdoc.assign, this.user.group).size,
|
||||
this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST) || !tdoc.assign?.length || new Set(tdoc.assign).intersection(new Set(this.user.group)).size,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ class TrainingDetailHandler extends Handler {
|
||||
for (const node of tdoc.dag) {
|
||||
ndict[node._id] = node;
|
||||
const totalCount = node.pids.length;
|
||||
const doneCount = Set.intersection(node.pids, donePids).size;
|
||||
const doneCount = new Set(node.pids).intersection(new Set(donePids)).size;
|
||||
const nsdoc = {
|
||||
progress: totalCount ? Math.floor(100 * (doneCount / totalCount)) : 100,
|
||||
isDone: training.isDone(node, doneNids, donePids),
|
||||
|
||||
@@ -313,7 +313,7 @@ export async function getListVnodes(domainId: string, ddocs: any, getHidden = fa
|
||||
const vnode = await getVnode(domainId, ddoc.parentType, ddoc.parentId.toString());
|
||||
res[ddoc.parentType] ||= {};
|
||||
if (!getHidden && vnode.hidden) return;
|
||||
if (vnode.assign?.length && Set.intersection(vnode.assign, assign).size) return;
|
||||
if (vnode.assign?.length && new Set(vnode.assign).intersection(new Set(assign)).size) return;
|
||||
res[ddoc.parentType][ddoc.parentId] = vnode;
|
||||
}
|
||||
await Promise.all(ddocs.map((ddoc) => task(ddoc)));
|
||||
@@ -325,7 +325,7 @@ export function checkVNodeVisibility(type: number, vnode: any, user: User) {
|
||||
if (vnode.hidden && !user.own(vnode) && !user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)) return false;
|
||||
}
|
||||
if ([document.TYPE_CONTEST, document.TYPE_TRAINING].includes(type as any)) {
|
||||
if (!user.own(vnode) && vnode.assign?.length && !Set.intersection(vnode.assign, user.group).size) return false;
|
||||
if (!user.own(vnode) && vnode.assign?.length && !new Set(vnode.assign).intersection(new Set(user.group)).size) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -63,30 +63,24 @@ export function getPids(dag: TrainingNode[]) {
|
||||
}
|
||||
|
||||
export function isDone(node: TrainingNode, doneNids: Set<number> | number[], donePids: Set<number> | number[]) {
|
||||
return (Set.isSuperset(new Set(doneNids), new Set(node.requireNids))
|
||||
&& Set.isSuperset(new Set(donePids), new Set(node.pids)));
|
||||
return new Set(doneNids).isSupersetOf(new Set(node.requireNids))
|
||||
&& new Set(donePids).isSupersetOf(new Set(node.pids));
|
||||
}
|
||||
|
||||
export function isProgress(node: TrainingNode, doneNids: Set<number> | number[], donePids: Set<number> | number[], progPids: Set<number> | number[]) {
|
||||
return (Set.isSuperset(new Set(doneNids), new Set(node.requireNids))
|
||||
&& !Set.isSuperset(new Set(donePids), new Set(node.pids))
|
||||
&& Set.intersection(
|
||||
Set.union(new Set(donePids), new Set(progPids)),
|
||||
new Set(node.pids),
|
||||
).size);
|
||||
return new Set(doneNids).isSupersetOf(new Set(node.requireNids))
|
||||
&& !new Set(donePids).isSupersetOf(new Set(node.pids))
|
||||
&& new Set(donePids).union(new Set(progPids)).intersection(new Set(node.pids)).size;
|
||||
}
|
||||
|
||||
export function isOpen(node: TrainingNode, doneNids: Set<number> | number[], donePids: Set<number> | number[], progPids: Set<number> | number[]) {
|
||||
return (Set.isSuperset(new Set(doneNids), new Set(node.requireNids))
|
||||
&& !Set.isSuperset(new Set(donePids), new Set(node.pids))
|
||||
&& !Set.intersection(
|
||||
Set.union(new Set(donePids), new Set(progPids)),
|
||||
new Set(node.pids),
|
||||
).size);
|
||||
return new Set(doneNids).isSupersetOf(new Set(node.requireNids))
|
||||
&& !new Set(donePids).isSupersetOf(new Set(node.pids))
|
||||
&& !new Set(donePids).union(new Set(progPids)).intersection(new Set(node.pids)).size;
|
||||
}
|
||||
|
||||
export const isInvalid = (node: TrainingNode, doneNids: Set<number> | number[]) =>
|
||||
!Set.isSuperset(new Set(doneNids), new Set(node.requireNids));
|
||||
!new Set(doneNids).isSupersetOf(new Set(node.requireNids));
|
||||
|
||||
export async function count(domainId: string, query: Filter<TrainingDoc>) {
|
||||
return await document.count(domainId, document.TYPE_TRAINING, query);
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
"html-to-text": "^9.0.5",
|
||||
"js-yaml": "^4.1.1",
|
||||
"jsesc": "^3.1.0",
|
||||
"katex": "^0.16.44",
|
||||
"katex": "^0.16.45",
|
||||
"lodash": "^4.18.1",
|
||||
"markdown-it": "^14.1.1",
|
||||
"markdown-it-anchor": "^9.2.0",
|
||||
|
||||
@@ -27,7 +27,7 @@ class AccountService {
|
||||
this.api = new Provider(account, async (data) => {
|
||||
await coll.updateOne({ _id: account._id }, { $set: data });
|
||||
});
|
||||
this.problemLists = Set.union(this.api.entryProblemLists || ['main'], this.account.problemLists || []);
|
||||
this.problemLists = new Set(this.api.entryProblemLists || ['main']).union(new Set(this.account.problemLists || []));
|
||||
this.main().catch((e) => {
|
||||
logger.error(`Error occured in ${account.type}/${account.handle}`);
|
||||
this.working = false;
|
||||
|
||||
Reference in new issue
Block a user