mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: allow custom problem difficulty
This commit is contained in:
1 parent
7f74c11bbd
commit
073eaffbd3
14 files changed
+38
-17
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "3.2.15",
|
||||
"version": "3.2.16",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -457,16 +457,16 @@ export class ProblemEditHandler extends ProblemManageHandler {
|
||||
@post('pid', Types.Name, isPid, convertPid, true)
|
||||
@post('hidden', Types.Boolean)
|
||||
@post('tag', Types.Content, true, null, parseCategory)
|
||||
@post('difficulty', Types.PositiveInt, (i) => +i <= 10, true)
|
||||
async post(
|
||||
domainId: string, pid: string | number, title: string, content: string,
|
||||
newPid: string = '', hidden = false, tag: string[] = [],
|
||||
newPid: string = '', hidden = false, tag: string[] = [], difficulty = 0,
|
||||
) {
|
||||
if (newPid !== this.pdoc.pid && await problem.get(domainId, newPid)) throw new BadRequestError('new pid exists');
|
||||
const $update: Partial<ProblemDoc> = {
|
||||
title, content, pid: newPid, hidden, tag: tag ?? [],
|
||||
title, content, pid: newPid, hidden, tag: tag ?? [], difficulty,
|
||||
};
|
||||
let pdoc = await problem.get(domainId, pid);
|
||||
$update.difficulty = difficultyAlgorithm(pdoc.nSubmit, pdoc.nAccept);
|
||||
pdoc = await problem.edit(domainId, pdoc.docId, $update);
|
||||
this.response.redirect = this.url('problem_detail', { pid: newPid || pdoc.docId });
|
||||
}
|
||||
@@ -780,10 +780,12 @@ export class ProblemCreateHandler extends Handler {
|
||||
@post('content', Types.Content)
|
||||
@post('pid', Types.Name, true, isPid, convertPid)
|
||||
@post('hidden', Types.Boolean)
|
||||
@post('difficulty', Types.PositiveInt, (i) => +i <= 10, true)
|
||||
@post('tag', Types.Content, true, null, parseCategory)
|
||||
async post(domainId: string, title: string, content: string, pid: string, hidden = false, tag: string[] = []) {
|
||||
async post(domainId: string, title: string, content: string, pid: string, hidden = false, difficulty = 0, tag: string[] = []) {
|
||||
if (pid && await problem.get(domainId, pid)) throw new BadRequestError('invalid pid');
|
||||
const docId = await problem.add(domainId, pid, title, content, this.user._id, tag ?? [], hidden);
|
||||
if (difficulty) await problem.edit(domainId, docId, { difficulty });
|
||||
this.response.body = { pid: pid || docId };
|
||||
this.response.redirect = this.url('problem_files', { pid: pid || docId });
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { ProblemNotFoundError, ValidationError } from '../error';
|
||||
import type {
|
||||
Document, ProblemDict, ProblemStatusDoc,
|
||||
} from '../interface';
|
||||
import difficultyAlgorithm from '../lib/difficulty';
|
||||
import { parseConfig } from '../lib/testdataConfig';
|
||||
import * as bus from '../service/bus';
|
||||
import {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { NumericDictionary, unionWith } from 'lodash';
|
||||
import { FilterQuery, ObjectID } from 'mongodb';
|
||||
import { ProblemDoc, Tdoc, Udoc } from '../interface';
|
||||
import difficultyAlgorithm from '../lib/difficulty';
|
||||
import rating from '../lib/rating';
|
||||
import { PRIV, STATUS } from '../model/builtin';
|
||||
import * as contest from '../model/contest';
|
||||
@@ -32,7 +33,8 @@ async function runProblem(...arg: any[]) {
|
||||
},
|
||||
).count() + 99) / 100,
|
||||
);
|
||||
const p = (pdoc.difficulty || 5) / (Math.sqrt(Math.sqrt(pdoc.nAccept)) + 1) / 10;
|
||||
pdoc.difficulty = pdoc.difficulty || difficultyAlgorithm(pdoc.nSubmit, pdoc.nAccept) || 5;
|
||||
const p = pdoc.difficulty / (Math.sqrt(Math.sqrt(pdoc.nAccept)) + 1) / 10;
|
||||
for (let page = 1; page <= nPages; page++) {
|
||||
const psdocs = await problem.getMultiStatus(
|
||||
pdoc.domainId, { docId: pdoc.docId, rid: { $ne: null } },
|
||||
@@ -45,7 +47,7 @@ async function runProblem(...arg: any[]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
udict[pdoc.owner] = (udict[pdoc.owner] || 1500) + (pdoc.difficulty || 5);
|
||||
udict[pdoc.owner] = (udict[pdoc.owner] || 1500) + pdoc.difficulty;
|
||||
}
|
||||
|
||||
async function runContest(tdoc: Tdoc<30 | 60>, udict: ND, report: Function): Promise<void>;
|
||||
|
||||
@@ -660,6 +660,11 @@ const scripts: UpgradeScript[] = [
|
||||
if (bulk.length) await bulk.execute();
|
||||
return true;
|
||||
},
|
||||
async function _55_56() {
|
||||
const _FRESH_INSTALL_IGNORE = 1;
|
||||
await db.collection('document').updateMany({ docType: document.TYPE_PROBLEM }, { $unset: { difficulty: '' } });
|
||||
return true;
|
||||
},
|
||||
];
|
||||
|
||||
export default scripts;
|
||||
Reference in new issue
Block a user