vjudge: codeforces: difficulty

This commit is contained in:
undefined committed 2022-04-27 00:16:58 +08:00
1 parent d967808593
commit 30d65501a9
3 files changed
+41

No files matched your search

+20
View File
@@ -9,6 +9,7 @@ import TaskModel from 'hydrooj/src/model/task';
import * as bus from 'hydrooj/src/service/bus';
import db from 'hydrooj/src/service/db';
import { BasicProvider, IBasicProvider, RemoteAccount } from './interface';
import { getDifficulty } from './providers/codeforces';
import providers from './providers/index';
const coll = db.collection('vjudge');
@@ -53,6 +54,7 @@ class Service {
const res = await this.api.getProblem(pid);
if (!res) continue;
const id = await ProblemModel.add(domainId, pid, res.title, res.content, 1, res.tag, false);
if (res.difficulty) await ProblemModel.edit(domainId, id, { difficulty: res.difficulty });
for (const key in res.files) {
await ProblemModel.addAdditionalFile(domainId, id, key, res.files[key]);
}
@@ -104,4 +106,22 @@ async function loadAccounts() {
}
}
declare module 'hydrooj/src/interface' {
interface Model {
vjudge: VJudgeModel;
}
}
class VJudgeModel {
static async fixCodeforcesDifficulty(domainId = 'codeforces') {
const pdocs = await ProblemModel.getMulti(domainId, {}).toArray();
for (const pdoc of pdocs) {
await ProblemModel.edit(domainId, pdoc.docId, { difficulty: getDifficulty(pdoc.tag) });
}
return true;
}
}
global.Hydro.model.vjudge = VJudgeModel;
bus.on('app/started', loadAccounts);