From cbcf9ebbc220dc03276118f9c83dc7531e543dd8 Mon Sep 17 00:00:00 2001 From: masnn Date: Sun, 17 May 2020 20:20:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A2=98=E7=9B=AE=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=88=86=E9=A1=B5=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hydro/handler/problem.js | 4 +- hydro/interface.js | 4 +- hydro/interface.ts | 2 +- module/migrate-vijos/script.js | 139 ++++++++++++++++++++++++++------- templates/partials/footer.html | 4 +- 5 files changed, 118 insertions(+), 35 deletions(-) diff --git a/hydro/handler/problem.js b/hydro/handler/problem.js index d77520094..fdd8a82e4 100644 --- a/hydro/handler/problem.js +++ b/hydro/handler/problem.js @@ -34,7 +34,7 @@ class ProblemHandler extends Handler { let psdict = {}; if (category) q.category = category; if (!this.user.hasPerm(PERM_VIEW_PROBLEM_HIDDEN)) q.hidden = false; - const [pdocs, pcount] = await paginate( + const [pdocs, ppcount, pcount] = await paginate( problem.getMulti(q).sort({ pid: 1 }), page, await system.get('PROBLEM_PER_PAGE'), @@ -47,7 +47,7 @@ class ProblemHandler extends Handler { ['problem_main', null], ]; this.response.body = { - path, page, pcount, pdocs, psdict, category, + path, page, pcount, ppcount, pdocs, psdict, category, }; } } diff --git a/hydro/interface.js b/hydro/interface.js index be9363d85..4d093da3f 100644 --- a/hydro/interface.js +++ b/hydro/interface.js @@ -1,3 +1,5 @@ +const { ObjectID } = require('bson'); + exports.udoc = { _id: 0, mail: '', @@ -44,7 +46,7 @@ export interface TestCase { export interface Rdoc { _id: ObjectID, pid: ObjectID, - owner: number, + uid: number, lang: string, code: string, score: number, diff --git a/hydro/interface.ts b/hydro/interface.ts index b4c93821a..6c4f1fbb4 100644 --- a/hydro/interface.ts +++ b/hydro/interface.ts @@ -42,7 +42,7 @@ export interface TestCase { export interface Rdoc { _id: ObjectID, pid: ObjectID, - owner: number, + uid: number, lang: string, code: string, score: number, diff --git a/module/migrate-vijos/script.js b/module/migrate-vijos/script.js index b9ed5cf1c..d85327844 100644 --- a/module/migrate-vijos/script.js +++ b/module/migrate-vijos/script.js @@ -38,7 +38,13 @@ const tasks = { problem: async (docs) => { const problems = []; for (const doc of docs) { - if (doc.pname) map[doc.doc_id.toString()] = doc.pname; + if (typeof doc.doc_id === 'number') { + map[doc.doc_id] = doc._id; + if (doc.pname) map[doc.pname] = doc._id; + } else { + map[doc.doc_id] = doc.doc_id; + if (doc.pname) map[doc.pname] = doc.doc_id; + } problems.push({ _id: doc._id, pid: doc.pname || pid(doc.doc_id), @@ -58,16 +64,12 @@ const tasks = { 'problem.status': async (docs) => { const problems = []; for (const doc of docs) { - try { - problems.push({ - pid: await problem.get(pid(doc.doc_id)), - rid: doc.rid, - uid: doc.uid, - status: doc.status, - }); - } catch (e) { - // Ignore - } + problems.push({ + pid: pid(doc.doc_id), + rid: doc.rid, + uid: doc.uid, + status: doc.status, + }); } return problems; }, @@ -79,14 +81,13 @@ const tasks = { content: r.content, _id: r._id, })); - const pdoc = await problem.get(pid(doc.parent_doc_id)); solutions.push({ _id: doc._id, owner: doc.owner_uid, content: doc.content, vote: doc.vote, reply, - pid: pdoc._id, + pid: pid(doc.parent_doc_id), }); } return solutions; @@ -130,11 +131,6 @@ const tasks = { }; const contests = []; for (const doc of docs) { - const pids = []; - for (const p of doc.pids) { - const pdoc = await problem.get(pid(p)); - pids.push(pdoc._id); - } contests.push({ _id: doc._id, title: doc.title, @@ -143,27 +139,50 @@ const tasks = { rule: RULES[doc.rule], beginAt: doc.begin_at, endAt: doc.end_at, - pids, + pids: doc.pids.map((id) => pid(id)), attend: doc.attend, }); } return contests; }, + 'contest.status': async (docs) => { + const contests = []; + for (const doc of docs) { + const journal = []; + const detail = []; + for (const i of doc.journal || []) { + const pdoc = await problem.get(pid(i.pid)); + journal.push({ ...i, id: pdoc._id }); + } + for (const i of doc.detail || []) { + const pdoc = await problem.get(pid(i.pid)); + detail.push({ ...i, id: pdoc._id }); + } + contests.push({ + _id: doc._id, + tid: doc.doc_id, + uid: doc.uid, + attend: doc.attend, + rev: doc.rev, + journal, + detail, + score: doc.score, + accept: doc.accept || 0, + time: doc.time || 0, + }); + } + return contests; + }, training: async (docs) => { const trainings = []; for (const doc of docs) { const dag = []; for (const t of doc.dag) { - const pids = []; - for (const p of t.pids) { - const pdoc = await problem.get(pid(p)); - pids.push(pdoc._id); - } dag.push({ _id: t._id, title: t.title, requireNids: t.require_nids, - pids, + pids: t.pids.map((id) => pid(id)), }); } trainings.push({ @@ -178,6 +197,57 @@ const tasks = { } return trainings; }, + 'training.status': async (docs) => { + const trainings = []; + for (const doc of docs) { + trainings.push({ + _id: doc._id, + pid: pid(doc.doc_id), + rid: doc.rid, + uid: doc.uid, + done: doc.done, + enroll: doc.enroll, + tid: doc.doc_id, + doneNids: doc.done_nids, + donePids: doc.done_pids.map((id) => pid(id)), + }); + } + return trainings; + }, + record: async (docs) => { + const records = []; + for (const doc of docs) { + const testCases = []; + for (const c of doc.cases) { + testCases.push({ + status: c.status, + score: c.score, + time: c.time, + memory: c.memory, + judge_text: c.judge_text, + }); + } + records.push({ + _id: doc._id, + status: doc.status, + score: doc.score, + time: doc.time_ms, + memory: doc.memory_kn, + code: doc.code, + lang: doc.lang, + uid: doc.uid, + pid: pid(doc.pid), + tid: doc.tid, + judger: doc.judge_uid, + judgeAt: doc.judge_at, + judgeTexts: doc.judge_texts, + compileTexts: doc.compile_texts, + rejudged: doc.rejudged, + testCases, + }); + } + return records; + }, 'fs.files': async (docs) => docs, 'fs.chunks': async (docs) => docs, }; @@ -190,7 +260,10 @@ const cursor = { discussion: (s) => s.collection('document').find({ doc_type: 21 }), 'discussion.reply': (s) => s.collection('document').find({ doc_type: 22 }), contest: (s) => s.collection('document').find({ doc_type: 30 }), + 'contest.status': (s) => s.collection('document.status').find({ doc_type: 30 }), training: (s) => s.collection('document').find({ doc_type: 40 }), + 'training.status': (s) => s.collection('document.status').find({ doc_type: 40 }), + record: (s) => s.collection('record').find(), 'fs.files': (s) => s.collection('fs.files').find(), 'fs.chunks': (s) => s.collection('fs.chunks').find(), }; @@ -229,18 +302,26 @@ async function migrateVijos({ ); await report({ progress: 1, message: 'Collection:system done.' }); await dst.collection('user').deleteMany({ _id: { $nin: [0, 1] } }); + if (!await dst.collection('system').findOne({ _id: 'migrateVijosFs' })) { + const f = ['fs.files', 'fs.chunks']; + for (const i of f) { + await dst.collection(i).deleteMany(); + await task(i, src, report); + } + await dst.collection('system').insertOne({ _id: 'migrateVijosFs', value: true }); + } const d = [ - 'problem', 'problem.status', 'solution', 'discussion', - 'discussion.reply', 'contest', 'training', 'fs.files', 'fs.chunks', + 'problem', 'problem.status', 'solution', 'discussion', 'discussion.reply', + 'contest', 'training', 'training.status', 'record', ]; for (const i of d) { await dst.collection(i).deleteMany(); } const t = [ 'user', 'problem', 'problem.status', 'solution', 'discussion', - 'discussion.reply', 'contest', 'training', 'fs.files', 'fs.chunks', + 'discussion.reply', 'contest', 'training', 'training.status', 'record', ]; for (const i of t) await task(i, src, report); } -global.Hydro.script.migrateVijos = module.exports = migrateVijos; +global.Hydro.script.migrateVijos = module.exports = { run: migrateVijos }; diff --git a/templates/partials/footer.html b/templates/partials/footer.html index 6f8eeb03f..1b01eaa9f 100644 --- a/templates/partials/footer.html +++ b/templates/partials/footer.html @@ -47,8 +47,8 @@
    - - + +