core: allow custom problem difficulty

This commit is contained in:
undefined committed 2021-12-11 20:09:23 +08:00
1 parent 7f74c11bbd
commit 073eaffbd3
14 files changed
+38 -17

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "3.2.15", "version": "3.2.16",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "src/loader", "main": "src/loader",
"module": "src/loader", "module": "src/loader",
+6 -4
View File
@@ -457,16 +457,16 @@ export class ProblemEditHandler extends ProblemManageHandler {
@post('pid', Types.Name, isPid, convertPid, true) @post('pid', Types.Name, isPid, convertPid, true)
@post('hidden', Types.Boolean) @post('hidden', Types.Boolean)
@post('tag', Types.Content, true, null, parseCategory) @post('tag', Types.Content, true, null, parseCategory)
@post('difficulty', Types.PositiveInt, (i) => +i <= 10, true)
async post( async post(
domainId: string, pid: string | number, title: string, content: string, 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'); if (newPid !== this.pdoc.pid && await problem.get(domainId, newPid)) throw new BadRequestError('new pid exists');
const $update: Partial<ProblemDoc> = { 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); let pdoc = await problem.get(domainId, pid);
$update.difficulty = difficultyAlgorithm(pdoc.nSubmit, pdoc.nAccept);
pdoc = await problem.edit(domainId, pdoc.docId, $update); pdoc = await problem.edit(domainId, pdoc.docId, $update);
this.response.redirect = this.url('problem_detail', { pid: newPid || pdoc.docId }); 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('content', Types.Content)
@post('pid', Types.Name, true, isPid, convertPid) @post('pid', Types.Name, true, isPid, convertPid)
@post('hidden', Types.Boolean) @post('hidden', Types.Boolean)
@post('difficulty', Types.PositiveInt, (i) => +i <= 10, true)
@post('tag', Types.Content, true, null, parseCategory) @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'); 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); 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.body = { pid: pid || docId };
this.response.redirect = this.url('problem_files', { pid: pid || docId }); this.response.redirect = this.url('problem_files', { pid: pid || docId });
} }
+1
View File
@@ -8,6 +8,7 @@ import { ProblemNotFoundError, ValidationError } from '../error';
import type { import type {
Document, ProblemDict, ProblemStatusDoc, Document, ProblemDict, ProblemStatusDoc,
} from '../interface'; } from '../interface';
import difficultyAlgorithm from '../lib/difficulty';
import { parseConfig } from '../lib/testdataConfig'; import { parseConfig } from '../lib/testdataConfig';
import * as bus from '../service/bus'; import * as bus from '../service/bus';
import { import {
+4 -2
View File
@@ -2,6 +2,7 @@
import { NumericDictionary, unionWith } from 'lodash'; import { NumericDictionary, unionWith } from 'lodash';
import { FilterQuery, ObjectID } from 'mongodb'; import { FilterQuery, ObjectID } from 'mongodb';
import { ProblemDoc, Tdoc, Udoc } from '../interface'; import { ProblemDoc, Tdoc, Udoc } from '../interface';
import difficultyAlgorithm from '../lib/difficulty';
import rating from '../lib/rating'; import rating from '../lib/rating';
import { PRIV, STATUS } from '../model/builtin'; import { PRIV, STATUS } from '../model/builtin';
import * as contest from '../model/contest'; import * as contest from '../model/contest';
@@ -32,7 +33,8 @@ async function runProblem(...arg: any[]) {
}, },
).count() + 99) / 100, ).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++) { for (let page = 1; page <= nPages; page++) {
const psdocs = await problem.getMultiStatus( const psdocs = await problem.getMultiStatus(
pdoc.domainId, { docId: pdoc.docId, rid: { $ne: null } }, 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>; async function runContest(tdoc: Tdoc<30 | 60>, udict: ND, report: Function): Promise<void>;
+5
View File
@@ -660,6 +660,11 @@ const scripts: UpgradeScript[] = [
if (bulk.length) await bulk.execute(); if (bulk.length) await bulk.execute();
return true; 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; export default scripts;
@@ -129,6 +129,7 @@ env.addGlobal('size', misc.size);
env.addGlobal('utils', { status }); env.addGlobal('utils', { status });
env.addGlobal('avatarUrl', avatar); env.addGlobal('avatarUrl', avatar);
env.addGlobal('formatSeconds', misc.formatSeconds); env.addGlobal('formatSeconds', misc.formatSeconds);
env.addGlobal('lib', global.Hydro.lib);
env.addGlobal('model', global.Hydro.model); env.addGlobal('model', global.Hydro.model);
env.addGlobal('ui', global.Hydro.ui); env.addGlobal('ui', global.Hydro.ui);
env.addGlobal('isIE', (str) => (str ? (str.includes('MSIE') || str.includes('rv:11.0')) : false)); env.addGlobal('isIE', (str) => (str ? (str.includes('MSIE') || str.includes('rv:11.0')) : false));
-1
View File
@@ -295,7 +295,6 @@ Enabled: 开启
End at: 结束于 End at: 结束于
End Date: 结束日期 End Date: 结束日期
End Time: 结束时间 End Time: 结束时间
English: 英文
Enroll Training: 参加训练 Enroll Training: 参加训练
Enrolled: 已参加 Enrolled: 已参加
Enrollees: 参加人数 Enrollees: 参加人数
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.27.4", "version": "4.27.5",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",
@@ -4,18 +4,18 @@
position: relative position: relative
.col--submit-at .col--submit-at
width: rem(120px) width: rem(115px)
text-align: center text-align: center
&.nojs .col--submit-at &.nojs .col--submit-at
width: rem(160px) width: rem(160px)
.col--submit-by .col--submit-by
width: rem(120px) width: rem(140px)
text-align: right text-align: right
.col--time, .col--memory, .col--lang .col--time, .col--memory, .col--lang
width: rem(100px) width: rem(95px)
text-align: center text-align: center
.col--status, .col--submit-by, .col--lang .col--status, .col--submit-by, .col--lang
@@ -10,7 +10,7 @@
<dt>{{ _('Memory') }}</dt> <dt>{{ _('Memory') }}</dt>
<dd>{{ pdoc.config.memoryMax if pdoc.config.memoryMax == pdoc.config.memoryMin else pdoc.config.memoryMin+'~'+pdoc.config.memoryMax }}MiB</dd> <dd>{{ pdoc.config.memoryMax if pdoc.config.memoryMax == pdoc.config.memoryMin else pdoc.config.memoryMin+'~'+pdoc.config.memoryMax }}MiB</dd>
<dt>{{ _('Difficulty') }}</dt> <dt>{{ _('Difficulty') }}</dt>
<dd>{{ pdoc['difficulty'] or _('(None)') }}</dd> <dd>{{ pdoc['difficulty'] or lib.difficulty(pdoc.nSubmit, pdoc.nAccept) or _('(None)') }}</dd>
<dt>{{ _('Category') }}</dt> <dt>{{ _('Category') }}</dt>
<dd> <dd>
{% if pdoc['category'] %} {% if pdoc['category'] %}
@@ -68,7 +68,7 @@
</td> </td>
<td class="col--tried">{{ pdoc.nSubmit }}</td> <td class="col--tried">{{ pdoc.nSubmit }}</td>
<td class="col--ac">{{ pdoc.nAccept }}</td> <td class="col--ac">{{ pdoc.nAccept }}</td>
<td class="col--difficulty">{{ pdoc['difficulty'] or _('(None)') }}</td> <td class="col--difficulty">{{ pdoc['difficulty'] or lib.difficulty(pdoc.nSubmit, pdoc.nAccept) or _('(None)') }}</td>
</tr> </tr>
{%- endfor -%} {%- endfor -%}
</tbody> </tbody>
@@ -58,7 +58,7 @@
{% if not tdoc %} {% if not tdoc %}
<a class="bp3-tag bp3-large bp3-minimal bp3-interactive problem__tag-item" href="{{ url('record_main', query={pid:pdoc.docId}) }}">{{ _('Tried') }}: {{ pdoc.nSubmit }}</a> <a class="bp3-tag bp3-large bp3-minimal bp3-interactive problem__tag-item" href="{{ url('record_main', query={pid:pdoc.docId}) }}">{{ _('Tried') }}: {{ pdoc.nSubmit }}</a>
<a class="bp3-tag bp3-large bp3-minimal bp3-interactive problem__tag-item" href="{{ url('record_main', query={pid:pdoc.docId, status:1}) }}">{{ _('Accepted') }}: {{ pdoc.nAccept if ((not tdoc) or showAccept) else '?' }}</a> <a class="bp3-tag bp3-large bp3-minimal bp3-interactive problem__tag-item" href="{{ url('record_main', query={pid:pdoc.docId, status:1}) }}">{{ _('Accepted') }}: {{ pdoc.nAccept if ((not tdoc) or showAccept) else '?' }}</a>
<span class="bp3-tag bp3-large bp3-minimal problem__tag-item">{{ _('Difficulty') }}: {{ pdoc['difficulty'] or _('(None)') }}</span> <span class="bp3-tag bp3-large bp3-minimal problem__tag-item">{{ _('Difficulty') }}: {{ pdoc['difficulty'] or lib.difficulty(pdoc.nSubmit, pdoc.nAccept) or _('(None)') }}</span>
{% endif %} {% endif %}
<span class="bp3-tag bp3-large bp3-minimal bp3-interactive problem__tag-item">{{ _('Uploaded By') }}: {{ user.render_inline(udoc, badge=false) }}</span> <span class="bp3-tag bp3-large bp3-minimal bp3-interactive problem__tag-item">{{ _('Uploaded By') }}: {{ user.render_inline(udoc, badge=false) }}</span>
{% if pdoc.tag.length %} {% if pdoc.tag.length %}
@@ -30,13 +30,24 @@
</label> </label>
</div> </div>
</div> </div>
<div class="row">
{{ form.form_text({ {{ form.form_text({
columns:12, row:false,
columns:8,
label:'Tags', label:'Tags',
help_text:'Split by \', \'.', help_text:'Split by \', \'.',
name:'tag', name:'tag',
value:pdoc['tag']|default([])|join(', ') value:pdoc['tag']|default([])|join(', ')
}) }} }) }}
{{ form.form_text({
row:false,
columns:4,
label:'Difficulty',
help_text:'From 1-10',
name:'difficulty',
value:pdoc['difficulty']
}) }}
</div>
<div class="section__tab-container nojs--hide"> <div class="section__tab-container nojs--hide">
<div class="section__tab-header-wrapper"> <div class="section__tab-header-wrapper">
<ul class="section__tab-header"> <ul class="section__tab-header">
@@ -133,7 +133,7 @@
</td> </td>
<td class="col--tried">{{ pdoc.nSubmit }}</td> <td class="col--tried">{{ pdoc.nSubmit }}</td>
<td class="col--ac">{{ pdoc.nAccept }}</td> <td class="col--ac">{{ pdoc.nAccept }}</td>
<td class="col--difficulty">{{ pdoc['difficulty'] or _('(None)') }}</td> <td class="col--difficulty">{{ pdoc['difficulty'] or lib.difficulty(pdoc.nSubmit, pdoc.nAccept) or _('(None)') }}</td>
</tr> </tr>
{% else %} {% else %}
{% set pdoc = {'_id': pid, 'hidden': true, 'title': '*'} %} {% set pdoc = {'_id': pid, 'hidden': true, 'title': '*'} %}