mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
解离比赛赛制为模块
This commit is contained in:
1 parent
1df19a7aa9
commit
474f495e0c
7 files changed
+290
No files matched your search
@@ -0,0 +1,111 @@
|
|||||||
|
module.exports = {
|
||||||
|
TEXT: 'ACM/ICPC',
|
||||||
|
check: () => { },
|
||||||
|
showScoreboard: () => true,
|
||||||
|
showRecord: (tdoc, now) => now > tdoc.endAt,
|
||||||
|
stat: (tdoc, journal) => {
|
||||||
|
const naccept = {};
|
||||||
|
const effective = {};
|
||||||
|
const detail = [];
|
||||||
|
let accept = 0;
|
||||||
|
let time = 0;
|
||||||
|
for (const j in journal) {
|
||||||
|
if (tdoc.pids.includes(j.pid)
|
||||||
|
&& !(effective.includes(j.pid) && effective[j.pid].accept)) {
|
||||||
|
effective[j.pid] = j;
|
||||||
|
}
|
||||||
|
if (!j.accept) naccept[j.pid]++;
|
||||||
|
}
|
||||||
|
function _time(jdoc) {
|
||||||
|
const real = jdoc.rid.generationTime - Math.floor(tdoc.begin_at / 1000);
|
||||||
|
const penalty = 20 * 60 * naccept[jdoc.pid];
|
||||||
|
return real + penalty;
|
||||||
|
}
|
||||||
|
for (const j of effective) detail.push({ ...j, naccept: naccept[j.pid], time: _time(j) });
|
||||||
|
for (const d of detail) {
|
||||||
|
accept += d.accept;
|
||||||
|
if (d.accept) time += d.time;
|
||||||
|
}
|
||||||
|
return { accept, time, detail };
|
||||||
|
},
|
||||||
|
scoreboard(isExport, _, tdoc, rankedTsdocs, udict, pdict) {
|
||||||
|
const columns = [
|
||||||
|
{ type: 'rank', value: _('Rank') },
|
||||||
|
{ type: 'user', value: _('User') },
|
||||||
|
{ type: 'solved_problems', value: _('Solved Problems') },
|
||||||
|
];
|
||||||
|
if (isExport) {
|
||||||
|
columns.push({ type: 'total_time', value: _('Total Time (Seconds)') });
|
||||||
|
columns.push({ type: 'total_time_str', value: _('Total Time') });
|
||||||
|
}
|
||||||
|
for (const i in tdoc.pids) {
|
||||||
|
if (isExport) {
|
||||||
|
columns.push({
|
||||||
|
type: 'problem_flag',
|
||||||
|
value: '#{0} {1}'.format(i + 1, pdict[tdoc.pids[i]].title),
|
||||||
|
});
|
||||||
|
columns.push({
|
||||||
|
type: 'problem_time',
|
||||||
|
value: '#{0} {1}'.format(i + 1, _('Time (Seconds)')),
|
||||||
|
});
|
||||||
|
columns.push({
|
||||||
|
type: 'problem_time_str',
|
||||||
|
value: '#{0} {1}'.format(i + 1, _('Time')),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
columns.push({
|
||||||
|
type: 'problem_detail',
|
||||||
|
value: '#{0}'.format(i + 1),
|
||||||
|
raw: pdict[tdoc.pids[i]],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const rows = [columns];
|
||||||
|
for (const [rank, tsdoc] of rankedTsdocs) {
|
||||||
|
const tsddict = {};
|
||||||
|
if (tdoc.detail) { for (const item of tsdoc.detail) tsddict[item.pid] = item; }
|
||||||
|
const row = [];
|
||||||
|
row.push(
|
||||||
|
{ type: 'string', value: rank },
|
||||||
|
{ type: 'user', value: udict[tsdoc.uid].uname, raw: udict[tsdoc.uid] },
|
||||||
|
{ type: 'string', value: tsdoc.accept || 0 },
|
||||||
|
);
|
||||||
|
if (isExport) {
|
||||||
|
row.push(
|
||||||
|
{ type: 'string', value: tsdoc.time || 0.0 },
|
||||||
|
{ type: 'string', value: tsdoc.time || 0.0 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (const pid of tdoc.pids) {
|
||||||
|
let rdoc;
|
||||||
|
let colAccepted;
|
||||||
|
let colTime;
|
||||||
|
let colTimeStr;
|
||||||
|
if ((tsddict[pid] || {}).accept) {
|
||||||
|
rdoc = tsddict[pid].rid;
|
||||||
|
colAccepted = _('Accepted');
|
||||||
|
colTime = tsddict[pid].time;
|
||||||
|
colTimeStr = colTime;
|
||||||
|
} else {
|
||||||
|
rdoc = null;
|
||||||
|
colAccepted = '-';
|
||||||
|
colTime = '-';
|
||||||
|
colTimeStr = '-';
|
||||||
|
}
|
||||||
|
if (isExport) {
|
||||||
|
row.push({ type: 'string', value: colAccepted });
|
||||||
|
row.push({ type: 'string', value: colTime });
|
||||||
|
row.push({ type: 'string', value: colTimeStr });
|
||||||
|
} else {
|
||||||
|
row.push({
|
||||||
|
type: 'record',
|
||||||
|
value: '{0}\n{1}'.format(colAccepted, colTimeStr),
|
||||||
|
raw: rdoc,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
rows.push(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"name": "contest-rule-basic",
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
const acm = require('./acm');
|
||||||
|
const oi = require('./oi');
|
||||||
|
|
||||||
|
const rules = global.Hydro['model.contest'].RULES;
|
||||||
|
rules.oi = oi;
|
||||||
|
rules.acm = acm;
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* @type {import('../../hydro/lib/rank')}
|
||||||
|
*/
|
||||||
|
const ranked = global.Hydro['lib.rank'];
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
TEXT: 'OI',
|
||||||
|
check: () => { },
|
||||||
|
stat: (tdoc, journal) => {
|
||||||
|
const detail = {};
|
||||||
|
let score = 0;
|
||||||
|
for (const j in journal) {
|
||||||
|
if (tdoc.pids.includes(j.pid)) {
|
||||||
|
detail[j.pid] = j;
|
||||||
|
score += j.score;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { score, detail };
|
||||||
|
},
|
||||||
|
showScoreboard(tdoc, now) {
|
||||||
|
return now > tdoc.endAt;
|
||||||
|
},
|
||||||
|
showRecord(tdoc, now) {
|
||||||
|
return now > tdoc.endAt;
|
||||||
|
},
|
||||||
|
scoreboard(isExport, _, tdoc, rankedTsdocs, udict, pdict) {
|
||||||
|
const columns = [
|
||||||
|
{ type: 'rank', value: _('Rank') },
|
||||||
|
{ type: 'user', value: _('User') },
|
||||||
|
{ type: 'total_score', value: _('Total Score') },
|
||||||
|
];
|
||||||
|
for (const i in tdoc.pids) {
|
||||||
|
if (isExport) {
|
||||||
|
columns.push({
|
||||||
|
type: 'problem_score',
|
||||||
|
value: '#{0} {1}'.format(i + 1, pdict[tdoc.pids[i]].title),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
columns.push({
|
||||||
|
type: 'problem_detail',
|
||||||
|
value: '#{0}'.format(i + 1),
|
||||||
|
raw: pdict[tdoc.pids[i]],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const rows = [columns];
|
||||||
|
for (const [rank, tsdoc] of rankedTsdocs) {
|
||||||
|
const tsddict = {};
|
||||||
|
if (tsdoc.journal) { for (const item of tsdoc.journal) tsddict[item.pid] = item; }
|
||||||
|
const row = [];
|
||||||
|
row.push({ type: 'string', value: rank });
|
||||||
|
row.push({ type: 'user', value: udict[tsdoc.uid].uname, raw: udict[tsdoc.uid] });
|
||||||
|
row.push({ type: 'string', value: tsdoc.score || 0 });
|
||||||
|
for (const pid of tdoc.pids) {
|
||||||
|
row.push({
|
||||||
|
type: 'record',
|
||||||
|
value: (tsddict[pid] || {}).score || '-',
|
||||||
|
raw: (tsddict[pid] || {}).rid || null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
rows.push(row);
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
},
|
||||||
|
rank: (tdocs) => ranked(tdocs, (a, b) => a.score === b.score),
|
||||||
|
};
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
module.exports = {
|
||||||
|
TEXT: 'Assignment',
|
||||||
|
check() {},
|
||||||
|
stat(tdoc, journal) {
|
||||||
|
const effective = {};
|
||||||
|
const detail = [];
|
||||||
|
let score = 0;
|
||||||
|
let time = 0;
|
||||||
|
for (const j in journal) {
|
||||||
|
if (tdoc.pids.includes(j.pid)
|
||||||
|
&& !(effective.includes(j.pid) && effective[j.pid].accept)) {
|
||||||
|
effective[j.pid] = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const _time = (jdoc) => jdoc.rid.generationTime - Math.floor(tdoc.beginAt / 1000);
|
||||||
|
for (const j in effective) {
|
||||||
|
detail.push({
|
||||||
|
...effective[j],
|
||||||
|
time: _time(effective[j]),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (const d of detail) {
|
||||||
|
score += d.score;
|
||||||
|
time += d.time;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
score, time, detail,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
scoreboard(isExport, _, tdoc, rankedTsdocs, udict, pdict) {
|
||||||
|
const columns = [
|
||||||
|
{ type: 'rank', value: _('Rank') },
|
||||||
|
{ type: 'user', value: _('User') },
|
||||||
|
{ type: 'display_name', value: _('Display Name') },
|
||||||
|
{ type: 'total_score', value: _('Score') },
|
||||||
|
];
|
||||||
|
if (isExport) {
|
||||||
|
columns.push(
|
||||||
|
{ type: 'total_original_score', value: _('Original Score') },
|
||||||
|
{ type: 'total_time', value: _('Total Time (Seconds)') },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
columns.push({ type: 'total_time_str', value: _('Total Time') });
|
||||||
|
for (const i in tdoc.pids) {
|
||||||
|
if (isExport) {
|
||||||
|
columns.push(
|
||||||
|
{ type: 'problem_score', value: '#{0} {1}'.format(i + 1, pdict[tdoc.pids[i]].title) },
|
||||||
|
{ type: 'problem_original_score', value: '#{0} {1}'.format(i + 1, _('Original Score')) },
|
||||||
|
{ type: 'problem_time', value: '#{0} {1}'.format(i + 1, _('Time (Seconds)')) },
|
||||||
|
{ type: 'problem_time_str', value: '#{0} {1}'.format(i + 1, _('Time')) },
|
||||||
|
);
|
||||||
|
} else columns.push({ type: 'problem_detail', value: '#{0}'.format(i + 1), raw: pdict[tdoc.pids[i]] });
|
||||||
|
}
|
||||||
|
const rows = [columns];
|
||||||
|
for (const [rank, tsdoc] in rankedTsdocs) {
|
||||||
|
const tsddict = {};
|
||||||
|
if (tsdoc.detail) { for (const item of tsdoc.detail) tsddict[item.pid] = item; }
|
||||||
|
const row = [
|
||||||
|
{ type: 'string', value: rank },
|
||||||
|
{ type: 'user', value: udict[tsdoc.uid].uname, raw: udict[tsdoc.uid] },
|
||||||
|
{ type: 'string', value: tsdoc.penalty_score || 0 },
|
||||||
|
];
|
||||||
|
if (isExport) {
|
||||||
|
row.push(
|
||||||
|
{ type: 'string', value: tsdoc.score || 0 },
|
||||||
|
{ type: 'string', value: tsdoc.time || 0.0 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
row.push({ type: 'string', value: tsdoc.time || 0 });
|
||||||
|
for (const pid of tdoc.pids) {
|
||||||
|
const rdoc = (tsddict[pid] || {}).rid || null;
|
||||||
|
const colScore = (tsddict[pid] || {}).penalty_score || '-';
|
||||||
|
const colOriginalScore = (tsddict[pid] || {}).score || '-';
|
||||||
|
const colTime = (tsddict[pid] || {}).time || '-';
|
||||||
|
const colTimeStr = colTime !== '-' ? colTime : '-';
|
||||||
|
if (isExport) {
|
||||||
|
row.push(
|
||||||
|
{ type: 'string', value: colScore },
|
||||||
|
{ type: 'string', value: colOriginalScore },
|
||||||
|
{ type: 'string', value: colTime },
|
||||||
|
{ type: 'string', value: colTimeStr },
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
row.push({
|
||||||
|
type: 'record',
|
||||||
|
value: '{0} / {1}\n{2}'.format(colScore, colOriginalScore, colTimeStr),
|
||||||
|
raw: rdoc,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rows.push(row);
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"name": "contest-rule-homework",
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
const homework = require('./homework');
|
||||||
|
|
||||||
|
const rules = global.Hydro['model.contest'].RULES;
|
||||||
|
rules.homework = homework;
|
||||||
Reference in new issue
Block a user