Skip to content

Commit d7b41fd

Browse files
authored
migrate: hustoj: bug fixes (#1009)
1 parent 10f1517 commit d7b41fd

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

packages/migrate/scripts/hustoj.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export async function run({
100100
const udocs = await query('SELECT * FROM `users`');
101101
const precheck = await UserModel.getMulti({ unameLower: { $in: udocs.map((u) => u.user_id.toLowerCase()) } }).toArray();
102102
if (precheck.length) throw new Error(`Conflict username: ${precheck.map((u) => u.unameLower).join(', ')}`);
103-
for (const udoc of udocs) {
103+
for (let uidx = 0; uidx < udocs.length; uidx += 1) {
104+
const udoc = udocs[uidx];
104105
if (randomMail) delete udoc.email;
105106
let current = await UserModel.getByEmail(domainId, udoc.email || `${udoc.user_id}@hustoj.local`);
106107
current ||= await UserModel.getByUname(domainId, udoc.user_id);
@@ -128,6 +129,13 @@ export async function run({
128129
nAccept: 0,
129130
});
130131
}
132+
133+
if (uidx % 100 === 0) {
134+
const progress = Math.round(((uidx + 1) / udocs.length) * 100);
135+
report({
136+
message: `user finished ${uidx + 1} / ${udocs.length} (${progress}%)`,
137+
});
138+
}
131139
}
132140

133141
const admins = await query("SELECT * FROM `privilege` WHERE `rightstr` = 'administrator'");
@@ -220,6 +228,12 @@ target: ybtbas/${+pdoc.id - 3000}
220228
await SolutionModel.add(domainId, pidMap[pdoc.problem_id], 1, md);
221229
}
222230
}
231+
if (pageId % 10 === 0) {
232+
const progress = Math.round(((pageId * step) / pcount) * 100);
233+
report({
234+
message: `problem finished ${pageId * step} / ${pcount} (${progress}%)`,
235+
});
236+
}
223237
}
224238
if (remoteUsed) {
225239
MessageModel.sendNotification(`您导入的数据中使用了一本通编程启蒙远端测试题目。
@@ -245,8 +259,9 @@ hydrooj install https://hydro.ac/hydroac-client.zip
245259
*/
246260
const tidMap: Record<string, string> = {};
247261
const tdocs = await query('SELECT * FROM `contest`');
248-
for (const tdoc of tdocs) {
249-
const pdocs = await query(`SELECT * FROM \`contest_problem\` WHERE \`contest_id\` = ${tdoc.contest_id}`);
262+
for (let tidx = 0; tidx < tdocs.length; tidx += 1) {
263+
const tdoc = tdocs[tidx];
264+
const pdocs = await query(`SELECT * FROM \`contest_problem\` WHERE \`contest_id\` = ${tdoc.contest_id} ORDER BY \`num\` ASC`);
250265
const pids = pdocs.map((i) => pidMap[i.problem_id]).filter((i) => i);
251266
const files = {};
252267
let description = tdoc.description;
@@ -260,11 +275,18 @@ hydrooj install https://hydro.ac/hydroac-client.zip
260275
const tid = await ContestModel.add(
261276
domainId, tdoc.title, description || 'Description',
262277
adminUids[0], contestType, tdoc.start_time, endAt, pids, true,
263-
{ _code: password },
278+
{ _code: tdoc.password },
264279
);
265280
tidMap[tdoc.contest_id] = tid.toHexString();
266281
await Promise.all(Object.keys(files).map((filename) => addContestFile(domainId, tid, filename, files[filename])));
267282
if (Object.keys(files).length) report({ message: `move ${Object.keys(files).length} file for contest ${tidMap[tdoc.contest_id]}` });
283+
284+
if (tidx % 100 === 0) {
285+
const progress = Math.round(((tidx + 1) / tdocs.length) * 100);
286+
report({
287+
message: `contest finished ${tidx + 1} / ${tdocs.length} (${progress}%)`,
288+
});
289+
}
268290
}
269291
report({ message: 'contest finished' });
270292
/*
@@ -288,11 +310,12 @@ hydrooj install https://hydro.ac/hydroac-client.zip
288310
lint_error int N ???
289311
judger char(16) N 判题机
290312
*/
291-
const [{ 'count(*)': _rcount }] = await query('SELECT count(*) FROM `solution`');
313+
// 测试运行 problem_id=0 导致非比赛的提交无法确定属于哪个题目,因此跳过测试运行
314+
const [{ 'count(*)': _rcount }] = await query('SELECT count(*) FROM `solution` WHERE `problem_id` > 0');
292315
const rcount = BigInt(_rcount);
293316
const rpageCount = rcount / BigInt(step) + (rcount % BigInt(step) === 0n ? 0n : 1n);
294317
for (let pageId = 0n; pageId < rpageCount; pageId++) {
295-
const rdocs = await query(`SELECT * FROM \`solution\` LIMIT ${pageId * BigInt(step)}, ${step}`);
318+
const rdocs = await query(`SELECT * FROM \`solution\` WHERE \`problem_id\` > 0 LIMIT ${pageId * BigInt(step)}, ${step}`);
296319
for (const rdoc of rdocs) {
297320
const data: RecordDoc = {
298321
status: statusMap[rdoc.result] || 0,

0 commit comments

Comments
 (0)