module.add(user,problem,record)

This commit is contained in:
masnn committed 2020-04-01 18:13:04 +08:00
commit d5b1f623f8
43 files changed
+5965

No files matched your search

+102
View File
@@ -0,0 +1,102 @@
module.exports = {
check: () => { },
stat: (tdoc, journal) => {
let naccept = {}, effective = {}, detail = [], accept = 0, time = 0;
for (let 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) {
let real = jdoc.rid.generation_time - Math.floor(tdoc.begin_at / 1000);
let penalty = 20 * 60 * naccept[jdoc.pid];
return real + penalty;
}
for (let j of effective)
detail.push(Object.assign({}, j, {
naccept: naccept[j.pid], time: _time(j)
}));
for (let d of detail) {
accept += d.accept;
if (d.accept) time += d.time;
}
return { accept, time, detail };
},
scoreboard(is_export, _, tdoc, ranked_tsdocs, udict, dudict, pdict) {
let columns = [
{ type: 'rank', value: _('Rank') },
{ type: 'user', value: _('User') },
{ type: 'display_name', value: _('Display Name') },
{ type: 'solved_problems', value: _('Solved Problems') }
];
if (is_export) {
columns.push({ 'type': 'total_time', 'value': _('Total Time (Seconds)') });
columns.push({ 'type': 'total_time_str', 'value': _('Total Time') });
}
for (let i in tdoc.pids)
if (is_export) {
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]]
});
let rows = [columns];
for (let [rank, tsdoc] of ranked_tsdocs) {
let tsddict = {};
if (tdoc.detail)
for (let item of tsdoc.detail)
tsddict[item.pid] = item;
let row = [];
row.push(
{ type: 'string', value: rank },
{ type: 'user', value: udict[tsdoc.uid].uname, raw: udict[tsdoc.uid] },
{ type: 'display_name', value: (dudict[tsdoc.uid] || {}).display_name || '' },
{ type: 'string', value: tsdoc.accept || 0 });
if (is_export)
row.push(
{ type: 'string', value: tsdoc.time || 0.0 },
{ type: 'string', value: tsdoc.time || 0.0 }
);
for (let pid of tdoc.pids) {
let rdoc, col_accepted, col_time, col_time_str;
if ((tsddict[pid] || {}).accept) {
rdoc = tsddict[pid].rid;
col_accepted = _('Accepted');
col_time = tsddict[pid].time;
col_time_str = col_time;
} else {
rdoc = null;
col_accepted = '-';
col_time = '-';
col_time_str = '-';
}
if (is_export) {
row.push({ type: 'string', value: col_accepted });
row.push({ type: 'string', value: col_time });
row.push({ type: 'string', value: col_time_str });
} else {
row.push({
type: 'record',
value: '{0}\n{1}'.format(col_accepted, col_time_str),
raw: rdoc
});
}
rows.push(row);
}
}
return rows;
}
};
+93
View File
@@ -0,0 +1,93 @@
const { ValidationError } = require('../../error');
module.exports = {
check(data) {
if (!data.penalty_since) throw new ValidationError('penalty_since');
if (data.penalty_since < data.begin_at) throw new ValidationError('penalty_since', 'begin_at');
if (data.penalty_since > data.end_at) throw new ValidationError('penalty_since', 'end_at');
},
stat(tdoc, journal) {
let effective = {}, detail = [], score = 0, penalty_score = 0, time = 0;
for (let 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.begin_at / 1000);
function _penalty_score(jdoc) {
let exceed_seconds = jdoc.rid.generation_time - Math.floor(tdoc.penalty_since / 1000);
if (exceed_seconds < 0) return jdoc.score;
else return 0.5 * jdoc.score;
}
for (let j in effective) {
detail.push(Object.assign({}, effective[j], {
penalty_score: _penalty_score(effective[j]), time: _time(effective[j])
}));
}
for (let d of detail) {
score += d.score;
penalty_score += d.penalty_score;
time += d.time;
}
return { score, penalty_score, time, detail };
},
scoreboard(is_export, _, tdoc, ranked_tsdocs, udict, dudict, pdict) {
let columns = [
{ 'type': 'rank', 'value': _('Rank') },
{ 'type': 'user', 'value': _('User') },
{ 'type': 'display_name', 'value': _('Display Name') },
{ 'type': 'total_score', 'value': _('Score') }
];
if (is_export)
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 (let i in tdoc.pids)
if (is_export)
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]] });
let rows = [columns];
for (let [rank, tsdoc] in ranked_tsdocs) {
let tsddict = {};
if (tsdoc.detail)
for (let item of tsdoc.detail)
tsddict[item.pid] = item;
let row = [
{ type: 'string', value: rank },
{ type: 'user', value: udict[tsdoc.uid].uname, raw: udict[tsdoc.uid] },
{ type: 'display_name', value: (dudict[tsdoc.uid] || {}).display_name || '' },
{ type: 'string', value: tsdoc.penalty_score || 0 }
];
if (is_export)
row.push(
{ type: 'string', value: tsdoc.score || 0 },
{ type: 'string', value: tsdoc.time || 0.0 }
);
row.push({ type: 'string', value: tsdoc.time || 0 });
for (let pid of tdoc.pids) {
let rdoc = (tsddict[pid] || {}).rid || null;
let col_score = (tsddict[pid] || {}).penalty_score || '-';
let col_original_score = (tsddict[pid] || {}).score || '-';
let col_time = (tsddict[pid] || {}).time || '-';
let col_time_str = col_time != '-' ? col_time : '-';
if (is_export) row.push(
{ type: 'string', value: col_score },
{ type: 'string', value: col_original_score },
{ type: 'string', value: col_time },
{ type: 'string', value: col_time_str },
);
else row.push({
type: 'record',
value: '{0} / {1}\n{2}'.format(col_score, col_original_score, col_time_str),
raw: rdoc
});
}
rows.push(row);
}
return rows;
}
};
+49
View File
@@ -0,0 +1,49 @@
module.exports = {
check: () => { },
stat: (tdoc, journal) => {
let detail = {}, score = 0;
for (let j in journal)
if (tdoc.pids.includes(j.pid)) {
detail[j.pid] = j;
score += j.score;
}
return { score, detail };
},
scoreboard(is_export, _, tdoc, ranked_tsdocs, udict, dudict, pdict) {
let columns = [
{ type: 'rank', value: _('Rank') },
{ type: 'user', value: _('User') },
{ type: 'display_name', value: _('Display Name') },
{ type: 'total_score', value: _('Total Score') }
];
for (let i in tdoc.pids)
if (is_export)
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]]
});
let rows = [columns];
for (let [rank, tsdoc] of ranked_tsdocs) {
let tsddict = {};
if (tdoc.detail)
for (let item of tsdoc.detail)
tsddict[item.pid] = item;
let row = [];
row.push({ type: 'string', value: rank });
row.push({ type: 'user', value: udict[tsdoc.uid].uname, raw: udict[tsdoc.uid] });
row.push({ type: 'display_name', value: dudict[tsdoc.uid].display_name || '' });
row.push({ type: 'string', value: tsdoc.score || 0 });
for (let pid of tdoc.pids)
row.push({
type: 'record',
value: (tsddict[pid] || {}).score || '-',
raw: (tsddict[pid] || {}).rid || null
});
rows.push(row);
}
return rows;
}
};