mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: add contest score ratio (#765)
Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
1 parent
9013c4eaa6
commit
e25db178fd
11 files changed
+121
-23
No files matched your search
@@ -253,6 +253,7 @@ export class ContestProblemListHandler extends ContestDetailBaseHandler {
|
||||
pdict, psdict: {}, udict, rdict: {}, tdoc: this.tdoc, tsdoc: this.tsdoc, tcdocs,
|
||||
};
|
||||
this.response.template = 'contest_problemlist.html';
|
||||
this.response.body.showScore = Object.values(this.tdoc.score || {}).some((i) => i && i !== 100);
|
||||
if (!this.tsdoc) return;
|
||||
if (this.tsdoc.attend && !this.tsdoc.startAt && contest.isOngoing(this.tdoc)) {
|
||||
await contest.setStatus(domainId, tid, this.user._id, { startAt: new Date() });
|
||||
@@ -651,6 +652,16 @@ export class ContestManagementHandler extends ContestManagementBaseHandler {
|
||||
]);
|
||||
this.back();
|
||||
}
|
||||
|
||||
@param('pid', Types.PositiveInt)
|
||||
@param('score', Types.PositiveInt)
|
||||
async postSetScore(domainId: string, pid: number, score: number) {
|
||||
if (!this.tdoc.pids.includes(pid)) throw new ValidationError('pid');
|
||||
this.tdoc.score ||= {};
|
||||
this.tdoc.score[pid] = score;
|
||||
await contest.edit(domainId, this.tdoc.docId, { score: this.tdoc.score });
|
||||
this.back();
|
||||
}
|
||||
}
|
||||
|
||||
export class ContestFileDownloadHandler extends ContestDetailBaseHandler {
|
||||
|
||||
@@ -358,9 +358,9 @@ export interface JudgeRequest extends Omit<RecordDoc, '_id' | 'testCases'> {
|
||||
|
||||
export interface ScoreboardNode {
|
||||
type: 'string' | 'rank' | 'user' | 'email' | 'record' | 'records' | 'problem' | 'solved' | 'time' | 'total_score';
|
||||
value: string;
|
||||
value: string; // 显示分数
|
||||
raw?: any;
|
||||
score?: number;
|
||||
score?: number; // 原始分数(100,不含赛制加成)
|
||||
style?: string;
|
||||
hover?: string;
|
||||
}
|
||||
@@ -396,6 +396,7 @@ export interface Tdoc extends Document {
|
||||
unlocked?: boolean;
|
||||
autoHide?: boolean;
|
||||
balloon?: Record<number, string>;
|
||||
score?: Record<number, number>;
|
||||
|
||||
/**
|
||||
* In hours
|
||||
|
||||
@@ -291,7 +291,9 @@ const oi = buildContestRule({
|
||||
display[j.pid] = j;
|
||||
}
|
||||
}
|
||||
for (const i in display) score += display[i].score || 0;
|
||||
for (const i in display) {
|
||||
score += ((tdoc.score?.[i] || 100) * (display[i].score || 0)) / 100;
|
||||
}
|
||||
return { score, detail, display };
|
||||
},
|
||||
showScoreboard: (tdoc, now) => now > tdoc.endAt,
|
||||
@@ -332,6 +334,10 @@ const oi = buildContestRule({
|
||||
{ type: 'rank', value: rank.toString() },
|
||||
{ type: 'user', value: udoc.uname, raw: tsdoc.uid },
|
||||
];
|
||||
const displayScore = (pid: number, score?: number) => {
|
||||
if (typeof score !== 'number') return '-';
|
||||
return score * ((tdoc.score?.[pid] || 100) / 100);
|
||||
};
|
||||
if (config.isExport) {
|
||||
row.push({ type: 'email', value: udoc.mail });
|
||||
row.push({ type: 'string', value: udoc.school || '' });
|
||||
@@ -357,17 +363,20 @@ const oi = buildContestRule({
|
||||
type: 'records',
|
||||
value: '',
|
||||
raw: [{
|
||||
value: tsddict[pid]?.score ?? '-',
|
||||
value: displayScore(pid, tsddict[pid]?.score),
|
||||
raw: tsddict[pid]?.rid || null,
|
||||
score: tsddict[pid]?.score,
|
||||
}, {
|
||||
value: meta?.psdict?.[index]?.score ?? '-',
|
||||
value: displayScore(pid, meta?.psdict?.[index]?.score),
|
||||
raw: meta?.psdict?.[index]?.rid ?? null,
|
||||
score: meta?.psdict?.[index]?.score,
|
||||
}],
|
||||
} : {
|
||||
type: 'record',
|
||||
value: `${tsddict[pid]?.score ?? '-'}${tsddict[pid]?.npending
|
||||
value: `${displayScore(pid, tsddict[pid]?.score)}${tsddict[pid]?.npending
|
||||
? `<span style="color:orange">+${tsddict[pid]?.npending}</span>` : ''}`,
|
||||
raw: tsddict[pid]?.rid || null,
|
||||
score: tsddict[pid]?.score,
|
||||
};
|
||||
if (tsddict[pid]?.status === STATUS.STATUS_ACCEPTED && tsddict[pid]?.rid.getTimestamp().getTime() === meta?.first?.[pid]) {
|
||||
node.style = 'background-color: rgb(217, 240, 199);';
|
||||
@@ -461,7 +470,7 @@ const strictioi = buildContestRule({
|
||||
j.status = Math.max(...Object.values(subtasks[j.pid]).map((i) => i.status));
|
||||
if (!detail[j.pid] || detail[j.pid].score < j.score) detail[j.pid] = { ...j, subtasks: subtasks[j.pid] };
|
||||
}
|
||||
for (const i in detail) score += detail[i].score;
|
||||
for (const i in detail) score += ((tdoc.score?.[i] || 100) * (detail[i].score || 0)) / 100;
|
||||
return { score, detail };
|
||||
},
|
||||
async scoreboardRow(config, _, tdoc, pdict, udoc, rank, tsdoc, meta) {
|
||||
@@ -485,9 +494,10 @@ const strictioi = buildContestRule({
|
||||
for (const pid of tdoc.pids) {
|
||||
row.push({
|
||||
type: 'record',
|
||||
value: tsddict[pid]?.score || '',
|
||||
value: ((tsddict[pid]?.score || 0) * ((tdoc.score?.[pid] || 100) / 100)).toString() || '',
|
||||
hover: Object.values(tsddict[pid]?.subtasks || {}).map((i: SubtaskResult) => `${STATUS_SHORT_TEXTS[i.status]} ${i.score}`).join(','),
|
||||
raw: tsddict[pid]?.rid,
|
||||
score: tsddict[pid]?.score,
|
||||
style: tsddict[pid]?.status === STATUS.STATUS_ACCEPTED && tsddict[pid]?.rid.getTimestamp().getTime() === meta?.first?.[pid]
|
||||
? 'background-color: rgb(217, 240, 199);'
|
||||
: undefined,
|
||||
@@ -523,8 +533,9 @@ const ledo = buildContestRule({
|
||||
let originalScore = 0;
|
||||
for (const pid of tdoc.pids) {
|
||||
if (!detail[pid]) continue;
|
||||
score += detail[pid].penaltyScore;
|
||||
originalScore += detail[pid].score;
|
||||
const rate = (tdoc.score?.[pid] || 100) / 100;
|
||||
score += detail[pid].penaltyScore * rate;
|
||||
originalScore += detail[pid].score * rate;
|
||||
}
|
||||
return {
|
||||
score, originalScore, detail,
|
||||
@@ -555,9 +566,10 @@ const ledo = buildContestRule({
|
||||
for (const pid of tdoc.pids) {
|
||||
row.push({
|
||||
type: 'record',
|
||||
value: tsddict[pid]?.penaltyScore?.toString() || '',
|
||||
value: ((tsddict[pid]?.penaltyScore || 0) * ((tdoc.score?.[pid] || 100) / 100)).toString(),
|
||||
hover: tsddict[pid]?.ntry ? `-${tsddict[pid].ntry} (${Math.round(Math.max(0.7, 0.95 ** tsddict[pid].ntry) * 100)}%)` : '',
|
||||
raw: tsddict[pid]?.rid,
|
||||
score: tsddict[pid]?.score,
|
||||
style: tsddict[pid]?.status === STATUS.STATUS_ACCEPTED && tsddict[pid]?.rid.getTimestamp().getTime() === meta?.first?.[pid]
|
||||
? 'background-color: rgb(217, 240, 199);'
|
||||
: undefined,
|
||||
@@ -587,17 +599,18 @@ const homework = buildContestRule({
|
||||
}
|
||||
|
||||
function penaltyScore(jdoc) {
|
||||
const rate = (tdoc.score?.[jdoc.pid] || 100) / 100;
|
||||
const exceedSeconds = Math.floor(
|
||||
(jdoc.rid.getTimestamp().getTime() - tdoc.penaltySince.getTime()) / 1000,
|
||||
);
|
||||
if (exceedSeconds < 0) return jdoc.score;
|
||||
if (exceedSeconds < 0) return rate * jdoc.score;
|
||||
let coefficient = 1;
|
||||
const keys = Object.keys(tdoc.penaltyRules).map(parseFloat).sort((a, b) => a - b);
|
||||
for (const i of keys) {
|
||||
if (i * 3600 <= exceedSeconds) coefficient = tdoc.penaltyRules[i];
|
||||
else break;
|
||||
}
|
||||
return jdoc.score * coefficient;
|
||||
return rate * jdoc.score * coefficient;
|
||||
}
|
||||
const detail = [];
|
||||
for (const j in effective) {
|
||||
@@ -691,7 +704,7 @@ const homework = buildContestRule({
|
||||
} else {
|
||||
row.push({
|
||||
type: 'record',
|
||||
score: tsddict[pid]?.penaltyScore || 0,
|
||||
score: tsddict[pid]?.score,
|
||||
value: colScore === colOriginalScore
|
||||
? '{0}\n{1}'.format(colScore, colTimeStr)
|
||||
: '{0} / {1}\n{2}'.format(colScore, colOriginalScore, colTimeStr),
|
||||
|
||||
@@ -821,6 +821,7 @@ Set Privilege: 设置权限
|
||||
Set Role: 设置角色
|
||||
Set Roles for Selected User: 设置所选用户的角色
|
||||
Set Roles for selected users: 为所选用户设置角色
|
||||
Set Score for Contest: 设置赛时分数
|
||||
Set time and memory limits: 设置时空限制
|
||||
setting_customize: 个性化
|
||||
setting_display: 显示偏好
|
||||
|
||||
@@ -120,6 +120,10 @@ $highlight-button-color = #F6DF45
|
||||
&.nojs .col--submit-at
|
||||
width: rem(160px)
|
||||
|
||||
.col--score
|
||||
width: rem(80px)
|
||||
text-align: center;
|
||||
|
||||
.col--problem
|
||||
border-left: 1px solid $table-border-color
|
||||
|
||||
@@ -208,3 +212,7 @@ $highlight-button-color = #F6DF45
|
||||
|
||||
.col--awards
|
||||
width: rem(130px)
|
||||
|
||||
.page--contest_manage
|
||||
.col--score
|
||||
width: rem(80px)
|
||||
@@ -1,5 +1,9 @@
|
||||
import $ from 'jquery';
|
||||
import { ActionDialog } from 'vj/components/dialog';
|
||||
import Notification from 'vj/components/notification';
|
||||
import { NamedPage } from 'vj/misc/Page';
|
||||
import { i18n, request, tpl } from 'vj/utils';
|
||||
|
||||
function handleReplyOrBroadcast(ev) {
|
||||
const title = $(ev.currentTarget).data('title');
|
||||
const did = $(ev.currentTarget).data('did');
|
||||
@@ -19,6 +23,50 @@ function handleReplyOrBroadcast(ev) {
|
||||
const page = new NamedPage('contest_manage', () => {
|
||||
$(document).on('click', '[name="broadcast"]', handleReplyOrBroadcast);
|
||||
$(document).on('click', '[name="reply"]', handleReplyOrBroadcast);
|
||||
$(document).on('click', '[name="set_score"]', async (ev) => {
|
||||
const pid = $(ev.currentTarget).data('pid');
|
||||
const op = await new ActionDialog({
|
||||
$body: tpl`
|
||||
<div class="row"><div class="columns">
|
||||
<h1>${i18n('Set Score for Contest')}</h1>
|
||||
</div></div>
|
||||
<div class="row"><div class="columns">
|
||||
<label>
|
||||
${i18n('score')}
|
||||
<div class="textbox-container">
|
||||
<input class="textbox" type="number" step="1" name="score" data-autofocus value="${$(ev.currentTarget).data('score')}"></input>
|
||||
</div>
|
||||
</label>
|
||||
</div></div>
|
||||
`,
|
||||
onDispatch(action) {
|
||||
if (action === 'ok' && $('[name="score"]').val() === null) {
|
||||
$('[name="score"]').focus();
|
||||
return false;
|
||||
}
|
||||
if (!Number.isFinite(+$('[name="score"]').val()) || +$('[name="score"]').val() <= 0) {
|
||||
Notification.error('Invalid score');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
}).open();
|
||||
if (op !== 'ok') return;
|
||||
try {
|
||||
const res = await request.post('', {
|
||||
operation: 'set_score',
|
||||
pid,
|
||||
score: $('[name="score"]').val(),
|
||||
});
|
||||
if (!res.error) {
|
||||
Notification.success('Score Updated');
|
||||
$(ev.currentTarget).text($('[name="score"]').val() as number);
|
||||
$(ev.currentTarget).data('score', $('[name="score"]').val());
|
||||
}
|
||||
} catch (e) {
|
||||
Notification.error(e.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export default page;
|
||||
@@ -3,7 +3,7 @@
|
||||
width: 60px
|
||||
|
||||
.col--size
|
||||
width: 120px
|
||||
width: 100px
|
||||
|
||||
.col--operation
|
||||
width: 40px
|
||||
@@ -1,4 +1,4 @@
|
||||
{% macro render_status_td(rdoc, rid_key='_id', class='', allDomain=false, short=false) %}
|
||||
{% macro render_status_td(rdoc, rid_key='_id', class='', allDomain=false, short=false, displayScore) %}
|
||||
<td class="col--status record-status--border {{ class }} {{ model.builtin.STATUS_CODES[rdoc.status] }}">
|
||||
<div class="col--status__text">
|
||||
<span class="icon record-status--icon {{ model.builtin.STATUS_CODES[rdoc.status] }}"></span>
|
||||
@@ -7,7 +7,7 @@
|
||||
class="record-status--text {{ model.builtin.STATUS_CODES[rdoc.status] }}"
|
||||
>
|
||||
{% if typeof(rdoc['score']) == 'number' %}
|
||||
<span style="color: {{ utils.status.getScoreColor(rdoc.score|default(0)) }}">{{ rdoc.score|default(0) }}</span>
|
||||
<span style="color: {{ utils.status.getScoreColor(rdoc.score|default(0)) }}">{{ displayScore|default(rdoc.score|default(0)) }}</span>
|
||||
{% endif %}
|
||||
{{ model.builtin.STATUS_SHORT_TEXTS[rdoc.status] if short else model.builtin.STATUS_TEXTS[rdoc.status] }}
|
||||
</a>
|
||||
|
||||
@@ -11,10 +11,12 @@
|
||||
<table class="data-table">
|
||||
<colgroup>
|
||||
<col class="col--problem">
|
||||
<col class="col--score">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="col--problem">{{ _('Problem') }}</th>
|
||||
<th class="col--score">{{ _('Score') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -25,6 +27,9 @@
|
||||
{{ problem.render_problem_title(pdict[pid], tdoc=tdoc, invalid=true, alphabetic=true) }}
|
||||
</a>
|
||||
</td>
|
||||
<td class="col--score">
|
||||
<a class="typo-a" data-tooltip="{{ _('Set Score for Contest') }}" name="set_score" data-pid="{{ pid }}" data-score="{{ tdoc.score[pid]|default(100) }}">{{ tdoc.score[pid]|default(100) }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
{%- endfor -%}
|
||||
</tbody>
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
|
||||
<col class="col--status">
|
||||
<col class="col--submit-at">
|
||||
{% endif %}
|
||||
{% if showScore %}
|
||||
<col class="col--score">
|
||||
{% endif %}
|
||||
<col class="col--problem">
|
||||
</colgroup>
|
||||
@@ -25,6 +28,9 @@
|
||||
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
|
||||
<th class="col--status record-status--border">{{ _('Status') }}</th>
|
||||
<th class="col--submit-at">{{ _('Last Submit At') }}</th>
|
||||
{% endif %}
|
||||
{% if showScore %}
|
||||
<th class="col--score">{{ _('Score') }}</th>
|
||||
{% endif %}
|
||||
<th class="col--problem">{{ _('Problem') }}</th>
|
||||
</tr>
|
||||
@@ -34,17 +40,21 @@
|
||||
<tr>
|
||||
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
|
||||
{% if psdict[pid] and psdict[pid].rid %}
|
||||
{% set rdoc = rdict[psdict[pid].rid] %}
|
||||
{% if model.contest.canShowSelfRecord.call(handler, tdoc) %}
|
||||
{{ record.render_status_td(rdoc) }}
|
||||
{% else %}
|
||||
<td class="col--status record-status--border"><a href="{{ url('record_detail', rid=rdoc._id) }}">{{ _('Submitted') }}</a></td>
|
||||
{% endif %}
|
||||
{% set rdoc = rdict[psdict[pid].rid] %}
|
||||
{% set displayScore = ((tdoc.score[pid]|default(100)) * (psdict[pid].score|default(0)) / 100) if showScore else (psdict[pid].penaltyScore|default(psdict[pid].score)) %}
|
||||
{% if model.contest.canShowSelfRecord.call(handler, tdoc) %}
|
||||
{{ record.render_status_td(rdoc, displayScore=displayScore) }}
|
||||
{% else %}
|
||||
<td class="col--status record-status--border"><a href="{{ url('record_detail', rid=rdoc._id) }}">{{ _('Submitted') }}</a></td>
|
||||
{% endif %}
|
||||
<td class="col--submit-at">{{ datetimeSpan(rdoc._id)|safe }}</td>
|
||||
{% else %}
|
||||
<td class="col--status record-status--border">{{ _('No Submissions') }}</td>
|
||||
<td class="col--submit-at">-</td>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if showScore %}
|
||||
<td class="col--score">{{ tdoc.score[pid]|default(100) }}</td>
|
||||
{% endif %}
|
||||
<td class="col--problem col--problem-name">
|
||||
{{ problem.render_problem_title(pdict[pid], tdoc, alphabetic=true) }}
|
||||
|
||||
@@ -80,6 +80,7 @@ export const STATUS_CODES: Record<STATUS, string> = {
|
||||
};
|
||||
|
||||
export function getScoreColor(score: number | string): string {
|
||||
if (score === null || score === undefined || !Number.isFinite(+score)) return '#000000';
|
||||
return [
|
||||
'#ff4f4f',
|
||||
'#ff694f',
|
||||
|
||||
Reference in new issue
Block a user