mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: contest: tsdoc.startAt
This commit is contained in:
1 parent
a9390d6546
commit
069f420310
5 files changed
+22
-16
No files matched your search
@@ -108,18 +108,18 @@ export class ContestDetailHandler extends Handler {
|
|||||||
const psdict = {};
|
const psdict = {};
|
||||||
let rdict = {};
|
let rdict = {};
|
||||||
if (tsdoc) {
|
if (tsdoc) {
|
||||||
|
if (tsdoc.attend && !tsdoc.startAt) {
|
||||||
|
await contest.setStatus(domainId, tid, this.user._id, { startAt: new Date() });
|
||||||
|
tsdoc.startAt = new Date();
|
||||||
|
}
|
||||||
for (const pdetail of tsdoc.journal || []) psdict[pdetail.pid] = pdetail;
|
for (const pdetail of tsdoc.journal || []) psdict[pdetail.pid] = pdetail;
|
||||||
if (contest.canShowSelfRecord.call(this, tdoc)) {
|
if (contest.canShowSelfRecord.call(this, tdoc)) {
|
||||||
const q = [];
|
rdict = await record.getList(domainId, Object.values(psdict).map((i: any) => i.rid));
|
||||||
for (const i in psdict) q.push(psdict[i].rid);
|
|
||||||
rdict = await record.getList(domainId, q);
|
|
||||||
} else {
|
} else {
|
||||||
for (const i in psdict) rdict[psdict[i].rid] = { _id: psdict[i].rid };
|
for (const i in psdict) rdict[psdict[i].rid] = { _id: psdict[i].rid };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.response.body.pdict = pdict;
|
Object.assign(this.response.body, { pdict, psdict, rdict });
|
||||||
this.response.body.psdict = psdict;
|
|
||||||
this.response.body.rdict = rdict;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@param('tid', Types.ObjectID)
|
@param('tid', Types.ObjectID)
|
||||||
@@ -238,7 +238,7 @@ export class ContestEditHandler extends Handler {
|
|||||||
this.response.template = 'contest_edit.html';
|
this.response.template = 'contest_edit.html';
|
||||||
const rules = {};
|
const rules = {};
|
||||||
for (const i in contest.RULES) rules[i] = contest.RULES[i].TEXT;
|
for (const i in contest.RULES) rules[i] = contest.RULES[i].TEXT;
|
||||||
let ts = new Date().getTime();
|
let ts = Date.now();
|
||||||
ts = ts - (ts % (15 * Time.minute)) + 15 * Time.minute;
|
ts = ts - (ts % (15 * Time.minute)) + 15 * Time.minute;
|
||||||
const dt = this.tdoc?.beginAt || new Date(ts);
|
const dt = this.tdoc?.beginAt || new Date(ts);
|
||||||
this.response.body = {
|
this.response.body = {
|
||||||
@@ -246,8 +246,7 @@ export class ContestEditHandler extends Handler {
|
|||||||
tdoc: this.tdoc,
|
tdoc: this.tdoc,
|
||||||
duration: tid ? (this.tdoc.endAt.getTime() - this.tdoc.beginAt.getTime()) / Time.hour : 2,
|
duration: tid ? (this.tdoc.endAt.getTime() - this.tdoc.beginAt.getTime()) / Time.hour : 2,
|
||||||
pids: tid ? this.tdoc.pids.join(',') : '',
|
pids: tid ? this.tdoc.pids.join(',') : '',
|
||||||
date_text: dt.format('%Y-%m-%d'),
|
startAt: dt,
|
||||||
time_text: dt.format('%H:%M'),
|
|
||||||
page_name: tid ? 'contest_edit' : 'contest_create',
|
page_name: tid ? 'contest_edit' : 'contest_create',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ export class ProblemDetailHandler extends ProblemHandler {
|
|||||||
if (!this.tdoc) throw new ContestNotFoundError(domainId, tid);
|
if (!this.tdoc) throw new ContestNotFoundError(domainId, tid);
|
||||||
this.tsdoc = await contest.getStatus(domainId, tid, this.user._id);
|
this.tsdoc = await contest.getStatus(domainId, tid, this.user._id);
|
||||||
if (contest.isNotStarted(this.tdoc)) throw new ContestNotLiveError(tid);
|
if (contest.isNotStarted(this.tdoc)) throw new ContestNotLiveError(tid);
|
||||||
if (!contest.isDone(this.tdoc) && !this.tsdoc?.attend) throw new ContestNotAttendedError(tid);
|
if (!contest.isDone(this.tdoc, this.tsdoc) && (!this.tsdoc?.attend || !this.tsdoc.startAt)) throw new ContestNotAttendedError(tid);
|
||||||
this.pdoc.tag.length = 0;
|
this.pdoc.tag.length = 0;
|
||||||
if (!contest.canShowScoreboard.call(this, this.tdoc) || !contest.isLocked(this.tdoc)) {
|
if (!contest.canShowScoreboard.call(this, this.tdoc) || !contest.isLocked(this.tdoc)) {
|
||||||
delete this.pdoc.nAccept;
|
delete this.pdoc.nAccept;
|
||||||
|
|||||||
@@ -341,6 +341,11 @@ export interface Tdoc<docType = document['TYPE_CONTEST'] | document['TYPE_TRAINI
|
|||||||
|
|
||||||
// For contest
|
// For contest
|
||||||
lockAt?: Date;
|
lockAt?: Date;
|
||||||
|
/**
|
||||||
|
* In hours
|
||||||
|
* 在比赛有效时间内选择特定的 X 小时参加比赛(从首次打开比赛算起)
|
||||||
|
*/
|
||||||
|
duration: number;
|
||||||
|
|
||||||
// For homework
|
// For homework
|
||||||
penaltySince?: Date;
|
penaltySince?: Date;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { FilterQuery, ObjectID } from 'mongodb';
|
import { FilterQuery, ObjectID } from 'mongodb';
|
||||||
import { Counter } from '@hydrooj/utils/lib/utils';
|
import { Counter, Time } from '@hydrooj/utils/lib/utils';
|
||||||
import {
|
import {
|
||||||
ContestAlreadyAttendedError, ContestNotAttendedError, ContestNotFoundError,
|
ContestAlreadyAttendedError, ContestNotAttendedError, ContestNotFoundError,
|
||||||
ContestScoreboardHiddenError, ValidationError,
|
ContestScoreboardHiddenError, ValidationError,
|
||||||
@@ -542,13 +542,13 @@ export function getMultiStatus(domainId: string, query: any) {
|
|||||||
export function isNew(tdoc: Tdoc, days = 1) {
|
export function isNew(tdoc: Tdoc, days = 1) {
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
const readyAt = tdoc.beginAt.getTime();
|
const readyAt = tdoc.beginAt.getTime();
|
||||||
return (now < readyAt - days * 24 * 3600 * 1000);
|
return (now < readyAt - days * Time.day);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isUpcoming(tdoc: Tdoc, days = 7) {
|
export function isUpcoming(tdoc: Tdoc, days = 7) {
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
const readyAt = tdoc.beginAt.getTime();
|
const readyAt = tdoc.beginAt.getTime();
|
||||||
return (now > readyAt - days * 24 * 3600 * 1000 && now < tdoc.beginAt.getTime());
|
return (now > readyAt - days * Time.day && now < tdoc.beginAt.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isNotStarted(tdoc: Tdoc) {
|
export function isNotStarted(tdoc: Tdoc) {
|
||||||
@@ -560,8 +560,10 @@ export function isOngoing(tdoc: Tdoc) {
|
|||||||
return (tdoc.beginAt <= now && now < tdoc.endAt);
|
return (tdoc.beginAt <= now && now < tdoc.endAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isDone(tdoc: Tdoc) {
|
export function isDone(tdoc: Tdoc, tsdoc?: any) {
|
||||||
return tdoc.endAt <= new Date();
|
if (tdoc.endAt <= new Date()) return true;
|
||||||
|
if (tsdoc?.startAt <= new Date(Date.now() + tdoc.duration * Time.hour)) return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isLocked(tdoc: Tdoc) {
|
export function isLocked(tdoc: Tdoc) {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if model.contest.isOngoing(tdoc) or model.contest.isDone(tdoc) %}
|
{% if model.contest.isOngoing(tdoc) or model.contest.isDone(tdoc, tsdoc) %}
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<div class="section__header">
|
<div class="section__header">
|
||||||
<h1 class="section__title">{{ _('Problem') }}</h1>
|
<h1 class="section__title">{{ _('Problem') }}</h1>
|
||||||
|
|||||||
Reference in new issue
Block a user