mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +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 = {};
|
||||
let rdict = {};
|
||||
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;
|
||||
if (contest.canShowSelfRecord.call(this, tdoc)) {
|
||||
const q = [];
|
||||
for (const i in psdict) q.push(psdict[i].rid);
|
||||
rdict = await record.getList(domainId, q);
|
||||
rdict = await record.getList(domainId, Object.values(psdict).map((i: any) => i.rid));
|
||||
} else {
|
||||
for (const i in psdict) rdict[psdict[i].rid] = { _id: psdict[i].rid };
|
||||
}
|
||||
}
|
||||
this.response.body.pdict = pdict;
|
||||
this.response.body.psdict = psdict;
|
||||
this.response.body.rdict = rdict;
|
||||
Object.assign(this.response.body, { pdict, psdict, rdict });
|
||||
}
|
||||
|
||||
@param('tid', Types.ObjectID)
|
||||
@@ -238,7 +238,7 @@ export class ContestEditHandler extends Handler {
|
||||
this.response.template = 'contest_edit.html';
|
||||
const rules = {};
|
||||
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;
|
||||
const dt = this.tdoc?.beginAt || new Date(ts);
|
||||
this.response.body = {
|
||||
@@ -246,8 +246,7 @@ export class ContestEditHandler extends Handler {
|
||||
tdoc: this.tdoc,
|
||||
duration: tid ? (this.tdoc.endAt.getTime() - this.tdoc.beginAt.getTime()) / Time.hour : 2,
|
||||
pids: tid ? this.tdoc.pids.join(',') : '',
|
||||
date_text: dt.format('%Y-%m-%d'),
|
||||
time_text: dt.format('%H:%M'),
|
||||
startAt: dt,
|
||||
page_name: tid ? 'contest_edit' : 'contest_create',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ export class ProblemDetailHandler extends ProblemHandler {
|
||||
if (!this.tdoc) throw new ContestNotFoundError(domainId, tid);
|
||||
this.tsdoc = await contest.getStatus(domainId, tid, this.user._id);
|
||||
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;
|
||||
if (!contest.canShowScoreboard.call(this, this.tdoc) || !contest.isLocked(this.tdoc)) {
|
||||
delete this.pdoc.nAccept;
|
||||
|
||||
@@ -341,6 +341,11 @@ export interface Tdoc<docType = document['TYPE_CONTEST'] | document['TYPE_TRAINI
|
||||
|
||||
// For contest
|
||||
lockAt?: Date;
|
||||
/**
|
||||
* In hours
|
||||
* 在比赛有效时间内选择特定的 X 小时参加比赛(从首次打开比赛算起)
|
||||
*/
|
||||
duration: number;
|
||||
|
||||
// For homework
|
||||
penaltySince?: Date;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { FilterQuery, ObjectID } from 'mongodb';
|
||||
import { Counter } from '@hydrooj/utils/lib/utils';
|
||||
import { Counter, Time } from '@hydrooj/utils/lib/utils';
|
||||
import {
|
||||
ContestAlreadyAttendedError, ContestNotAttendedError, ContestNotFoundError,
|
||||
ContestScoreboardHiddenError, ValidationError,
|
||||
@@ -542,13 +542,13 @@ export function getMultiStatus(domainId: string, query: any) {
|
||||
export function isNew(tdoc: Tdoc, days = 1) {
|
||||
const now = new Date().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) {
|
||||
const now = new Date().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) {
|
||||
@@ -560,8 +560,10 @@ export function isOngoing(tdoc: Tdoc) {
|
||||
return (tdoc.beginAt <= now && now < tdoc.endAt);
|
||||
}
|
||||
|
||||
export function isDone(tdoc: Tdoc) {
|
||||
return tdoc.endAt <= new Date();
|
||||
export function isDone(tdoc: Tdoc, tsdoc?: any) {
|
||||
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) {
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
{% endif %}
|
||||
</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__header">
|
||||
<h1 class="section__title">{{ _('Problem') }}</h1>
|
||||
|
||||
Reference in new issue
Block a user