update interface: ProblemConfig

This commit is contained in:
undefined committed 2020-07-24 17:22:59 +08:00
1 parent 92335d8529
commit 57881792f3
15 files changed
+226 -145

No files matched your search

+6 -14
View File
@@ -1,17 +1,15 @@
import { ObjectID } from 'mongodb';
import * as user from './user';
import * as problem from './problem';
import * as document from './document';
import { PERM } from './builtin';
import {
ValidationError, ContestNotFoundError, ContestAlreadyAttendedError,
ContestNotAttendedError, ContestScoreboardHiddenError,
} from '../error';
import * as document from './document';
import { PERM } from './builtin';
import {
Tdoc, ContestRule, ContestRules,
Udict, ScoreboardNode,
ContestRule, ContestRules, ScoreboardNode, Tdoc, Udict,
} from '../interface';
import * as validator from '../lib/validator';
import * as misc from '../lib/misc';
import ranked from '../lib/rank';
@@ -21,7 +19,7 @@ const acm: ContestRule = {
statusSort: { accept: -1, time: 1 },
showScoreboard: () => true,
showRecord: (tdoc, now) => now > tdoc.endAt,
stat: (tdoc, journal: any[]) => {
stat: (tdoc, journal) => {
const naccept = {};
const effective = {};
const detail = [];
@@ -156,12 +154,8 @@ const oi: ContestRule = {
}
return { score, detail };
},
showScoreboard(tdoc, now) {
return now > tdoc.endAt;
},
showRecord(tdoc, now) {
return now > tdoc.endAt;
},
showScoreboard: (tdoc, now) => now > tdoc.endAt,
showRecord: (tdoc, now) => now > tdoc.endAt,
scoreboard(isExport, _, tdoc, rankedTsdocs, udict, pdict) {
const columns: ScoreboardNode[] = [
{ type: 'rank', value: _('Rank') },
@@ -364,8 +358,6 @@ export function add(
rule: string, beginAt = new Date(), endAt = new Date(), pids = [],
rated = false, data = {}, type = document.TYPE_CONTEST,
) {
validator.checkTitle(title);
validator.checkContent(content);
if (!this.RULES[rule]) throw new ValidationError('rule');
if (beginAt >= endAt) throw new ValidationError('beginAt', 'endAt');
Object.assign(data, {
+3 -3
View File
@@ -5,7 +5,7 @@ import * as document from './document';
import * as domain from './domain';
import { Pdoc, Pdict, ProblemDataSource } from '../interface';
import { ProblemNotFoundError } from '../error';
import readConfig from '../lib/readConfig';
import * as testdataConfig from '../lib/testdataConfig';
export const pdocHidden: Pdoc = {
_id: new ObjectID(),
@@ -22,7 +22,7 @@ export const pdocHidden: Pdoc = {
category: [],
data: null,
hidden: true,
config: '',
config: {},
acMsg: '',
};
@@ -151,7 +151,7 @@ export function setStar(domainId: string, pid: number, uid: number, star: boolea
export async function setTestdata(domainId: string, _id: number, filePath: string) {
const pdoc = await get(domainId, _id);
const config = await readConfig(filePath);
const config = await testdataConfig.readConfig(filePath);
const id = await file.add(filePath, 'data.zip', 1);
if (pdoc.data instanceof ObjectID) file.del(pdoc.data);
return await edit(domainId, _id, { data: id, config });
+33 -13
View File
@@ -4,7 +4,9 @@ import { ObjectID } from 'mongodb';
import { STATUS } from './builtin';
import * as task from './task';
import * as problem from './problem';
import { Rdoc, TestCase } from '../interface';
import {
Rdoc, TestCase, PretestConfig, ContestInfo,
} from '../interface';
import { RecordNotFoundError } from '../error';
import * as db from '../service/db';
@@ -46,28 +48,50 @@ export interface JudgeTask {
type?: string,
}
export async function add(domainId: string, data: RdocBase, addTask: boolean): Promise<ObjectID> {
_.defaults(data, {
export async function add(
domainId: string, pid: number, uid: number,
lang: string, code: string, addTask: boolean, contest?: ContestInfo,
): Promise<ObjectID>
export async function add(
domainId: string, pid: number, uid: number,
lang: string, code: string, addTask: boolean, config: PretestConfig,
): Promise<ObjectID>
export async function add(
domainId: string, pid: number, uid: number,
lang: string, code: string, addTask: boolean, contestOrConfig?: ContestInfo | PretestConfig,
) {
const data: Rdoc = {
status: STATUS.STATUS_WAITING,
type: 'judge',
_id: new ObjectID(),
uid,
code,
lang,
pid,
domainId,
score: 0,
time: 0,
memory: 0,
hidden: false,
hidden: !!contestOrConfig,
judgeTexts: [],
compilerTexts: [],
testCases: [],
judger: null,
judgeAt: null,
});
rejudged: false,
};
if ((contestOrConfig as ContestInfo).type) {
// is contest
data.contest = contestOrConfig as ContestInfo;
} else {
data.config = contestOrConfig as PretestConfig;
}
const [pdoc, res] = await Promise.all([
problem.get(domainId, data.pid, null),
problem.get(domainId, pid, null),
coll.insertOne(data),
]);
if (addTask) {
const t: any = {
type: data.type || 'judge',
type: 'judge',
rid: res.insertedId,
domainId,
pid: data.pid,
@@ -78,11 +102,7 @@ export async function add(domainId: string, data: RdocBase, addTask: boolean): P
t.data = pdoc.data;
t.config = pdoc.config;
} else {
t.config = yaml.safeDump({
time: data.time,
memory: data.memory,
input: data.input,
});
t.config = yaml.safeDump(contestOrConfig);
}
await task.add(t);
}