Skip to content

Commit

Permalink
Merge pull request #2 from hydro-dev/override_score
Browse files Browse the repository at this point in the history
  • Loading branch information
undefined-moe authored Mar 22, 2024
2 parents 40faebd + 739a95a commit 42dccb2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 19 deletions.
46 changes: 35 additions & 11 deletions import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -126,7 +138,6 @@ luogu.kotlin/jvm:
display: Kotlin/JVM
comment: //
luogu.scala:
disabled: true
highlight: scala
display: Scala
comment: //
Expand All @@ -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')
Expand Down
12 changes: 10 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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);
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/vjudge-luogu",
"version": "0.0.2",
"version": "0.0.3",
"dependencies": {
"fancy-progress": "^1.0.1"
}
Expand Down
18 changes: 13 additions & 5 deletions provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, { score: number; status: number }> = {};
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);
Expand Down

0 comments on commit 42dccb2

Please sign in to comment.