core: homework: 自动转换pids

This commit is contained in:
undefined committed 2021-01-24 13:11:35 +08:00
1 parent f2a999aacb
commit 25e7e00518
6 files changed
+20 -17

No files matched your search

+4 -2
View File
@@ -338,6 +338,8 @@ Homework Introduction: 作业介绍
Homework scoreboard is not visible.: 目前无法查看作业成绩表。 Homework scoreboard is not visible.: 目前无法查看作业成绩表。
homework_create: 创建作业 homework_create: 创建作业
homework_detail_problem_submit: 递交作业题目 homework_detail_problem_submit: 递交作业题目
homework_detail_problem: 题目详情
homework_detail: 作业详情
homework_edit: 编辑作业 homework_edit: 编辑作业
homework_main: 作业 homework_main: 作业
homework_scoreboard: 作业成绩表 homework_scoreboard: 作业成绩表
@@ -602,9 +604,9 @@ RP Algorithm: RP 算法
Rule: 规则 Rule: 规则
Run Pretest: 运行自测 Run Pretest: 运行自测
Run: 运行 Run: 运行
Sample: 样例
Sample Input: 输入数据 Sample Input: 输入数据
Sample Output: 输出数据 Sample Output: 输出数据
Sample: 样例
Save All Changes: 保存所有修改 Save All Changes: 保存所有修改
Saved session: 已保存的会话 Saved session: 已保存的会话
score canceled: 成绩取消 score canceled: 成绩取消
@@ -819,4 +821,4 @@ You've already attended this contest.: 您已经参加本次比赛。
You've already claimed this homework.: 您已认领过该作业。 You've already claimed this homework.: 您已认领过该作业。
You've already voted.: 您已经投过票。 You've already voted.: 您已经投过票。
Your permission: 您的权限 Your permission: 您的权限
Your role: 您的角色 Your role: 您的角色
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.16.0", "version": "2.16.1",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
+6 -6
View File
@@ -140,7 +140,7 @@ class HomeworkDetailProblemHandler extends HomeworkHandler {
]; ];
this.response.template = 'problem_detail.html'; this.response.template = 'problem_detail.html';
this.response.body = { this.response.body = {
tdoc: this.tdoc, pdoc: this.pdoc, tsdoc: this.tsdoc, udoc, attended, path, tdoc: this.tdoc, pdoc: this.pdoc, tsdoc: this.tsdoc, udoc, attended, path, page_name: 'homework_detail_problem',
}; };
} }
} }
@@ -247,9 +247,9 @@ class HomeworkCreateHandler extends HomeworkHandler {
const endAt = penaltySince.clone().add(extensionDays, 'days'); const endAt = penaltySince.clone().add(extensionDays, 'days');
if (beginAt.isSameOrAfter(penaltySince)) throw new ValidationError('endAtDate', 'endAtTime'); if (beginAt.isSameOrAfter(penaltySince)) throw new ValidationError('endAtDate', 'endAtTime');
if (penaltySince.isAfter(endAt)) throw new ValidationError('extensionDays'); if (penaltySince.isAfter(endAt)) throw new ValidationError('extensionDays');
await this.verifyProblems(domainId, pids); const verified = await this.verifyProblems(domainId, pids);
const tid = await contest.add(domainId, title, content, this.user._id, const tid = await contest.add(domainId, title, content, this.user._id,
'homework', beginAt.toDate(), endAt.toDate(), pids, rated, 'homework', beginAt.toDate(), endAt.toDate(), verified, rated,
{ penaltySince: penaltySince.toDate(), penaltyRules }, document.TYPE_HOMEWORK); { penaltySince: penaltySince.toDate(), penaltyRules }, document.TYPE_HOMEWORK);
this.response.body = { tid }; this.response.body = { tid };
this.response.redirect = this.url('homework_detail', { tid }); this.response.redirect = this.url('homework_detail', { tid });
@@ -324,17 +324,17 @@ class HomeworkEditHandler extends HomeworkHandler {
} }
let endAt = penaltySince.clone().add(extensionDays, 'days'); let endAt = penaltySince.clone().add(extensionDays, 'days');
if (beginAt.isSameOrAfter(penaltySince)) throw new ValidationError('endAtDate', 'endAtTime'); if (beginAt.isSameOrAfter(penaltySince)) throw new ValidationError('endAtDate', 'endAtTime');
await this.verifyProblems(domainId, pids); const verified = await this.verifyProblems(domainId, pids);
beginAt = beginAt.toDate(); beginAt = beginAt.toDate();
endAt = endAt.toDate(); endAt = endAt.toDate();
penaltySince = penaltySince.toDate(); penaltySince = penaltySince.toDate();
await contest.edit(domainId, tid, { await contest.edit(domainId, tid, {
title, content, beginAt, endAt, pids, penaltySince, penaltyRules, rated, title, content, beginAt, endAt, verified, penaltySince, penaltyRules, rated,
}, document.TYPE_HOMEWORK); }, document.TYPE_HOMEWORK);
if (tdoc.beginAt !== beginAt if (tdoc.beginAt !== beginAt
|| tdoc.endAt !== endAt || tdoc.endAt !== endAt
|| tdoc.penaltySince !== penaltySince || tdoc.penaltySince !== penaltySince
|| new Set(tdoc.pids) !== new Set(pids)) { || tdoc.pids.sort().join(' ') !== verified.sort().join(' ')) {
await contest.recalcStatus(domainId, tdoc.docId, document.TYPE_HOMEWORK); await contest.recalcStatus(domainId, tdoc.docId, document.TYPE_HOMEWORK);
} }
this.response.body = { tid }; this.response.body = { tid };
+1 -1
View File
@@ -190,7 +190,7 @@ export async function getList(
} }
} }
} }
return r; return Object.assign(r, l);
} }
export async function getListStatus(domainId: string, uid: number, pids: number[]) { export async function getListStatus(domainId: string, uid: number, pids: number[]) {
+1 -1
View File
@@ -446,7 +446,7 @@ export class Handler extends HandlerCommon {
this.getSession(), this.getSession(),
this.getBdoc(), this.getBdoc(),
]); ]);
if (inferDomain) { if (inferDomain && !this.request.path.startsWith('/d/')) {
this.domainId = inferDomain._id; this.domainId = inferDomain._id;
this.args.domainId = inferDomain._id; this.args.domainId = inferDomain._id;
this.domain = inferDomain; this.domain = inferDomain;
+7 -6
View File
@@ -21,14 +21,15 @@ import * as system from './model/system';
const logger = new Logger('upgrade'); const logger = new Logger('upgrade');
type UpgradeScript = () => Promise<boolean | void>; type UpgradeScript = () => Promise<boolean | void>;
async function iterateAllDomain(cb: (ddoc: DomainDoc) => Promise<any>) { async function iterateAllDomain(cb: (ddoc: DomainDoc, current?: number, total?: number) => Promise<any>) {
const domains = await domain.getMulti().project({ _id: 1 }).toArray(); const ddocs = await domain.getMulti().project({ _id: 1 }).toArray();
for (const d of domains) await cb(d); for (const i in ddocs) await cb(ddocs[i], +i, ddocs.length);
} }
async function iterateAllProblem(cb: (pdoc: problem.Pdoc) => Promise<any>) { async function iterateAllProblem(cb: (pdoc: problem.Pdoc, current?: number, total?: number) => Promise<any>) {
await iterateAllDomain(async (d) => { await iterateAllDomain(async (d) => {
await problem.getMulti(d._id, {}).forEach(cb); const pdocs = await problem.getMulti(d._id, {}).toArray();
for (const i in pdocs) await cb(pdocs[i], +i, pdocs.length);
}); });
} }
@@ -77,7 +78,7 @@ const scripts: UpgradeScript[] = [
if (savedProgress) savedProgress = JSON.parse(savedProgress); if (savedProgress) savedProgress = JSON.parse(savedProgress);
else savedProgress = { pdocs: [] }; else savedProgress = { pdocs: [] };
const ddocs = await domain.getMulti().project({ _id: 1 }).toArray(); const ddocs = await domain.getMulti().project({ _id: 1 }).toArray();
logger.info('Total found %d domains.', ddocs.length); logger.info('Found %d domains.', ddocs.length);
for (let i = 0; i < ddocs.length; i++) { for (let i = 0; i < ddocs.length; i++) {
const ddoc = ddocs[i]; const ddoc = ddocs[i];
logger.info('Domain %s (%d/%d)', ddoc._id, i + 1, ddocs.length); logger.info('Domain %s (%d/%d)', ddoc._id, i + 1, ddocs.length);