Contest rule: ACM/ICPC

This commit is contained in:
masnn committed 2020-04-15 18:48:17 +08:00
1 parent d1ec9064fc
commit e06283c0cc
43 files changed
+158 -891

No files matched your search

+15 -3
View File
@@ -69,7 +69,7 @@ class ContestDetailHandler extends ContestHandler {
}
async postAttend() {
if (contest.is_done(this.tdoc)) throw new ContestNotLiveError(this.tdoc._id);
if (contest.isDone(this.tdoc)) throw new ContestNotLiveError(this.tdoc._id);
await contest.attend(this.tdoc._id, this.user._id);
this.back();
}
@@ -88,6 +88,17 @@ class ContestScoreboardHandler extends ContestDetailHandler {
};
}
}
class ContestScoreboardDownloadHandler extends ContestDetailHandler {
async get({ tid, ext }) {
const getContent = {
csv: async (rows) => `\uFEFF${rows.map((c) => (c.map((i) => i.value).join(','))).join('\n')}`,
html: (rows) => this.renderHTML('contest_scoreboard_download_html.html', { rows }),
};
if (!getContent[ext]) throw new ValidationError('ext');
const [, rows] = await this.getScoreboard(tid, true);
this.binary(await getContent[ext](rows), `${this.tdoc.title}.${ext}`);
}
}
class ContestEditHandler extends ContestDetailHandler {
async prepare({ tid }) {
const tdoc = await contest.get(tid);
@@ -150,9 +161,9 @@ class ContestProblemHandler extends ContestDetailHandler {
]);
this.attended = this.tsdoc && this.tsdoc.attend === 1;
this.response.template = 'problem_detail.html';
if (contest.is_done(this.tdoc)) {
if (contest.isDone(this.tdoc)) {
if (!this.attended) throw new ContestNotAttendedError(this.tdoc._id);
if (!contest.is_ongoing(this.tdoc)) throw new ContestNotLiveError(this.tdoc._id);
if (!contest.isOngoing(this.tdoc)) throw new ContestNotLiveError(this.tdoc._id);
}
console.log(this.tdoc.pids, this.pdoc._id);
if (!this.tdoc.pids.map((s) => s.toString()).includes(this.pdoc._id.toString())) {
@@ -260,6 +271,7 @@ Route('/c', ContestListHandler);
Route('/c/:tid', ContestDetailHandler);
Route('/c/:tid/edit', ContestEditHandler);
Route('/c/:tid/scoreboard', ContestScoreboardHandler);
Route('/c/:tid/export/:ext', ContestScoreboardDownloadHandler);
Route('/c/:tid/p/:pid', ContestProblemHandler);
Route('/c/:tid/p/:pid/submit', ContestProblemSubmitHandler);
Route('/contest/create', ContestCreateHandler);