MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / add

Method add

packages/hydrooj/src/model/record.ts:129–184  ·  view source on GitHub ↗
(
        domainId: string, pid: number, uid: number,
        lang: string, code: string, addTask: boolean,
        args: {
            contest?: ObjectId;
            input?: string[];
            files?: Record<string, string>;
            hackTarget?: ObjectId;
            type: 'judge' | 'rejudge' | 'pretest' | 'hack' | 'generate';
            notify?: boolean;
        } = { type: 'judge' },
    )

Source from the content-addressed store, hash-verified

127 }
128
129 static async add(
130 domainId: string, pid: number, uid: number,
131 lang: string, code: string, addTask: boolean,
132 args: {
133 contest?: ObjectId;
134 input?: string[];
135 files?: Record<string, string>;
136 hackTarget?: ObjectId;
137 type: 'judge' | 'rejudge' | 'pretest' | 'hack' | 'generate';
138 notify?: boolean;
139 } = { type: 'judge' },
140 ) {
141 const data: RecordDoc = {
142 status: STATUS.STATUS_WAITING,
143 _id: new ObjectId(),
144 uid,
145 code,
146 lang,
147 pid,
148 domainId,
149 score: 0,
150 time: 0,
151 memory: 0,
152 judgeTexts: [],
153 compilerTexts: [],
154 testCases: [],
155 judger: null,
156 judgeAt: null,
157 rejudged: false,
158 };
159 let isContest = !!args.contest;
160 if (args.contest) data.contest = args.contest;
161 if (args.files) data.files = args.files;
162 if (args.hackTarget) data.hackTarget = args.hackTarget;
163 if (args.notify) data.notify = true;
164 if (args.type === 'rejudge') {
165 args.type = 'judge';
166 data.rejudged = true;
167 } else if (args.type === 'pretest') {
168 data.input = args.input || [];
169 isContest = false;
170 data.contest = RecordModel.RECORD_PRETEST;
171 } else if (args.type === 'generate') {
172 data.contest = RecordModel.RECORD_GENERATE;
173 }
174 const res = await RecordModel.coll.insertOne(data);
175 bus.broadcast('record/change', data);
176 if (addTask) {
177 const priority = await RecordModel.submissionPriority(uid, args.type === 'pretest' ? -20 : (isContest ? 50 : 0));
178 await RecordModel.judge(domainId, data, priority, isContest ? { detail: false } : {}, {
179 type: args.type,
180 rejudge: data.rejudged,
181 });
182 }
183 return res.insertedId;
184 }
185
186 static getMulti(domainId: string, query: any, options?: FindOptions) {

Callers 2

submissionPriorityMethod · 0.45
statMethod · 0.45

Calls 2

submissionPriorityMethod · 0.80
judgeMethod · 0.45

Tested by

no test coverage detected