mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
vjudge: codeforces: difficulty
This commit is contained in:
1 parent
d967808593
commit
30d65501a9
3 files changed
+41
No files matched your search
@@ -27,6 +27,7 @@ export interface IBasicProvider {
|
||||
files: Record<string, any>;
|
||||
tag: string[];
|
||||
content: string;
|
||||
difficulty?: number;
|
||||
}>;
|
||||
listProblem(page: number, resync: boolean): Promise<string[]>;
|
||||
submitProblem(id: string, lang: string, code: string, info: any, next: any, end: any): Promise<string>;
|
||||
|
||||
@@ -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);
|
||||
@@ -27,6 +27,25 @@ puppeteer.use(StealthPlugin()).use(PortalPlugin({
|
||||
},
|
||||
}));
|
||||
|
||||
export function getDifficulty(tags: string[]) {
|
||||
const d = tags.find((i) => /^\*\d+$/.test(i))?.split('*')[1];
|
||||
if (!(d && +d)) return null;
|
||||
const map = [
|
||||
[500, 1],
|
||||
[800, 2],
|
||||
[1200, 3],
|
||||
[1500, 4],
|
||||
[1800, 5],
|
||||
[2000, 6],
|
||||
[2200, 7],
|
||||
[2400, 8],
|
||||
[2600, 9],
|
||||
[2800, 10],
|
||||
];
|
||||
for (const [i, j] of map) if (+d < i) return j;
|
||||
return 10;
|
||||
}
|
||||
|
||||
export default class CodeforcesProvider implements IBasicProvider {
|
||||
constructor(public account: RemoteAccount, private save: (data: any) => Promise<void>) {
|
||||
if (account.cookie) this.cookie = account.cookie;
|
||||
@@ -269,6 +288,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
||||
},
|
||||
files,
|
||||
tag,
|
||||
difficulty: getDifficulty(tag),
|
||||
content: buildContent([
|
||||
{
|
||||
type: 'Text', sectionTitle: 'Description', subType: 'markdown', text: description,
|
||||
|
||||
Reference in new issue
Block a user