diff --git a/import.ts b/import.ts index 47cbed3..4771918 100644 --- a/import.ts +++ b/import.ts @@ -30,31 +30,31 @@ luogu.c/99/gcco2: display: C(O2) comment: // monaco: cpp - pretest: cc + pretest: c luogu.cxx/98/gcc: highlight: cpp astyle-c display: C++98 comment: // monaco: cpp - pretest: cc + pretest: cc.cc98 luogu.cxx/98/gcco2: highlight: cpp astyle-c display: C++98(O2) comment: // monaco: cpp - pretest: cc + pretest: cc.cc98o2 luogu.cxx/11/gcc: highlight: cpp astyle-c display: C++11 comment: // monaco: cpp - pretest: cc + pretest: cc.cc11 luogu.cxx/11/gcco2: highlight: cpp astyle-c display: C++11(O2) comment: // monaco: cpp - pretest: cc + pretest: cc.cc11o2 luogu.python3/c: highlight: python display: Python 3 @@ -73,25 +73,37 @@ luogu.cxx/14/gcc: display: C++14 comment: // monaco: cpp - pretest: cc + pretest: cc.cc14 luogu.cxx/14/gcco2: highlight: cpp astyle-c display: C++14(O2) comment: // monaco: cpp - pretest: cc + pretest: cc.cc14o2 +luogu.cxx/noi/202107: + highlight: cpp astyle-c + display: C++14(GCC 9.3.0) + comment: // + monaco: cpp + # pretest: cc.cc14 +luogu.cxx/noi/202107o2: + highlight: cpp astyle-c + display: C++14(O2, GCC 9.3.0) + comment: // + monaco: cpp + # pretest: cc.cc14o2 luogu.cxx/17/gcc: highlight: cpp astyle-c display: C++17 comment: // monaco: cpp - pretest: cc + pretest: cc.cc17 luogu.cxx/17/gcco2: highlight: cpp astyle-c display: C++17(O2) comment: // monaco: cpp - pretest: cc + pretest: cc.cc17o2 luogu.ruby: highlight: ruby display: Ruby @@ -126,7 +138,6 @@ luogu.kotlin/jvm: display: Kotlin/JVM comment: // luogu.scala: - disabled: true highlight: scala display: Scala comment: // @@ -137,7 +148,20 @@ luogu.perl: luogu.python3/py: highlight: python display: PyPy 3 - comments: '#'`; + comments: '#' + pretest: py.pypy3 +luogu.cxx/20/gcc: + highlight: cpp astyle-c + display: C++20 + comment: // + monaco: cpp + pretest: cc.cc20 +luogu.cxx/20/gcco2: + highlight: cpp astyle-c + display: C++20(O2) + comment: // + monaco: cpp + pretest: cc.cc20`; function processContent(content: string) { return content.replace(/\r/g, '').replace(/\n+/g, '\n') diff --git a/index.ts b/index.ts index 67af0a1..dd8b000 100644 --- a/index.ts +++ b/index.ts @@ -15,7 +15,15 @@ declare module 'hydrooj' { } async function addAccount(token: string) { - // TODO check validity + const newProvider = new LuoguProvider({ + _id: 'test', type: 'luogu', handle: token.split(':')[0], password: token.split(':')[1], + }, async () => {}); + try { + const info = await newProvider.checkStatus(true); + console.log(info); + } catch (e) { + throw new Error('Invalid account'); + } await db.collection('vjudge').insertOne({ _id: String.random(8), handle: token.split(':')[0], @@ -31,7 +39,7 @@ global.Hydro.model.luogu = { }; export async function apply(ctx: Context) { - ctx.using(['vjudge'], (c) => { + ctx.inject(['vjudge'], (c) => { c.vjudge.addProvider('luogu', LuoguProvider); }); diff --git a/package.json b/package.json index 4460c2a..c37f82d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/vjudge-luogu", - "version": "0.0.2", + "version": "0.0.3", "dependencies": { "fancy-progress": "^1.0.1" } diff --git a/provider.ts b/provider.ts index 604ec1a..c3d4c9f 100644 --- a/provider.ts +++ b/provider.ts @@ -159,33 +159,41 @@ export default class LuoguProvider extends BasicFetcher implements IBasicProvide const judge = body.data.judge; const total = judge.subtasks.flatMap((i) => i.cases).length; const cases = []; + const subtasks: Record = {}; let progress = (finished / total) * 100; for (const subtask of judge.subtasks) { + const subtaskId = +subtask.id || 0; for (const c of subtask.cases) { if (done[`${subtask.id}.${c.id}`]) continue; finished++; done[`${subtask.id}.${c.id}`] = true; cases.push({ id: +c.id || 0, - subtaskId: +subtask.id || 0, + subtaskId, status: STATUS_MAP[c.status], time: c.time, memory: c.memory, message: c.description, }); progress = (finished / total) * 100; + subtasks[subtaskId] ||= { status: STATUS_MAP[c.status], score: STATUS_MAP[c.status] === STATUS.STATUS_ACCEPTED ? 100 : 0 }; + if (STATUS_MAP[c.status] > subtasks[subtaskId].status) { + subtasks[subtaskId].status = STATUS_MAP[c.status]; + subtasks[subtaskId].score = STATUS_MAP[c.status] === STATUS.STATUS_ACCEPTED ? 100 : 0; + } } } if (cases.length) await next({ status: STATUS.STATUS_JUDGING, cases, progress }); if (judge.status < 2) continue; logger.info('RecordID:', id, 'done'); - // TODO calc total status - // TODO return subtask status + // TODO return real score + const status = Math.min(...Object.values(subtasks).map((i) => i.status)); return await end({ - status: STATUS_MAP[judge.status], - score: judge.score, + status, + score: status === STATUS.STATUS_ACCEPTED ? 100 : judge.score, time: judge.time, memory: judge.memory, + subtasks, }); } catch (e) { logger.error(e);