judge: support generate testdata (#695)

Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
undefinedandpanda authored and GitHub committed 2023-12-14 17:03:42 +08:00
1 parent b83b2e792e
commit 55b4e1aaf0
27 files changed
+454 -68

No files matched your search

+15 -6
View File
@@ -26,6 +26,9 @@ export default class RecordModel {
'files',
];
static RECORD_PRETEST = new ObjectId('000000000000000000000000');
static RECORD_GENERATE = new ObjectId('000000000000000000000001');
static async submissionPriority(uid: number, base: number = 0) {
const timeRecent = await RecordModel.coll
.find({ _id: { $gte: Time.getObjectID(moment().add(-30, 'minutes')) }, uid, rejudged: { $ne: true } })
@@ -82,8 +85,9 @@ export default class RecordModel {
}
meta = { ...meta, problemOwner: pdoc.owner };
if (typeof pdoc.config === 'string') throw new Error(pdoc.config);
const type = (pdoc.config.type === 'remote_judge' && rdoc.contest?.toHexString() !== '0'.repeat(24)) ? 'remotejudge' : 'judge';
config.type = pdoc.config.type === 'fileio' ? 'default' : pdoc.config.type as any;
let type = 'judge';
if (pdoc.config.type === 'remote_judge' && rdoc.contest?.toHexString() !== '0'.repeat(24)) type = 'remotejudge';
else if (meta?.type === 'generate') type = 'generate';
return await task.addMany(rids.map((rid) => ({
...(pdoc.config as any),
priority,
@@ -104,7 +108,7 @@ export default class RecordModel {
contest?: ObjectId,
input?: string,
files?: Record<string, string>,
type: 'judge' | 'rejudge' | 'contest' | 'pretest' | 'hack',
type: 'judge' | 'rejudge' | 'pretest' | 'hack' | 'generate',
} = { type: 'judge' },
) {
const data: RecordDoc = {
@@ -125,6 +129,7 @@ export default class RecordModel {
judgeAt: null,
rejudged: false,
};
let isContest = !!args.contest;
if (args.contest) data.contest = args.contest;
if (args.files) data.files = args.files;
if (args.type === 'rejudge') {
@@ -132,12 +137,16 @@ export default class RecordModel {
data.rejudged = true;
} else if (args.type === 'pretest') {
data.input = args.input || '';
data.contest = new ObjectId('000000000000000000000000');
isContest = false;
data.contest = RecordModel.RECORD_PRETEST;
}
const res = await RecordModel.coll.insertOne(data);
if (addTask) {
const priority = await RecordModel.submissionPriority(uid, args.type === 'pretest' ? -20 : (args.type === 'contest' ? 50 : 0));
await RecordModel.judge(domainId, res.insertedId, priority, args.type === 'contest' ? { detail: false } : {}, { rejudge: data.rejudged });
const priority = await RecordModel.submissionPriority(uid, args.type === 'pretest' ? -20 : (isContest ? 50 : 0));
await RecordModel.judge(domainId, res.insertedId, priority, isContest ? { detail: false } : {}, {
type: args.type,
rejudge: data.rejudged,
});
}
return res.insertedId;
}
+2 -1
View File
@@ -6,6 +6,7 @@ import { Schedule } from '../interface';
import { Logger } from '../logger';
import * as bus from '../service/bus';
import db from '../service/db';
import RecordModel from './record';
const logger = new Logger('model/schedule');
const coll = db.collection('schedule');
@@ -136,7 +137,7 @@ export async function apply(ctx: Context) {
ctx.worker = Worker;
Worker.addHandler('task.daily', async () => {
await global.Hydro.model.record.coll.deleteMany({ contest: new ObjectId('000000000000000000000000') });
await RecordModel.coll.deleteMany({ contest: { $in: [RecordModel.RECORD_PRETEST, RecordModel.RECORD_GENERATE] } });
await global.Hydro.script.rp?.run({}, new Logger('task/rp').debug);
await global.Hydro.script.problemStat?.run({}, new Logger('task/problem').debug);
if (global.Hydro.model.system.get('server.checkUpdate') && !(new Date().getDay() % 3)) {