mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
🆕 系统状态,修复题目复制
This commit is contained in:
1 parent
933dc73162
commit
3cb4d2ad49
19 files changed
+67
-30
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/hydrojudge",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"main": "package.json",
|
||||
"author": "masnn",
|
||||
"os": [
|
||||
|
||||
@@ -102,14 +102,13 @@ async function postInit() {
|
||||
data.rid = new ObjectID(that.rid);
|
||||
data.time = data.time_ms || data.time;
|
||||
data.memory = data.memory_kb || data.memory;
|
||||
data.message = data.judge_text || data.message;
|
||||
data.compilerText = data.compiler_text || data.compilerText;
|
||||
if (data.case) {
|
||||
data.case = {
|
||||
status: data.case.status,
|
||||
time: data.case.time_ms || data.case.time,
|
||||
memory: data.case.memory_kb || data.case.memory,
|
||||
message: data.judge_text || data.message || data.judgeText,
|
||||
message: data.message || data.judgeText,
|
||||
};
|
||||
}
|
||||
if (id) {
|
||||
@@ -213,13 +212,13 @@ async function postInit() {
|
||||
status: STATUS_COMPILE_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
||||
});
|
||||
} else if (e instanceof FormatError) {
|
||||
this.next({ judge_text: `${e.message}\n${JSON.stringify(e.params)}` });
|
||||
this.next({ message: `${e.message}\n${JSON.stringify(e.params)}` });
|
||||
this.end({
|
||||
status: STATUS_SYSTEM_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
||||
});
|
||||
} else {
|
||||
console.error(e);
|
||||
this.next({ judge_text: `${e.message}\n${e.stack}\n${JSON.stringify(e.params)}` });
|
||||
this.next({ message: `${e.message}\n${e.stack}\n${JSON.stringify(e.params)}` });
|
||||
this.end({
|
||||
status: STATUS_SYSTEM_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
||||
});
|
||||
|
||||
@@ -147,7 +147,7 @@ async function readAutoCases(folder, { next }) {
|
||||
let result = await read0(folder, files, checkFile);
|
||||
if (!result.count) result = await read1(folder, files, checkFile);
|
||||
Object.assign(config, result);
|
||||
next({ judge_text: `识别到${config.count}个测试点` });
|
||||
next({ message: `识别到${config.count}个测试点` });
|
||||
} catch (e) {
|
||||
throw new SystemError('在自动识别测试点的过程中出现了错误。', [e]);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ function judgeCase(c) {
|
||||
score: 0,
|
||||
time_ms: time_usage_ms,
|
||||
memory_kb: memory_usage_kb,
|
||||
judge_text: message,
|
||||
message,
|
||||
},
|
||||
progress: Math.floor((c.id * 100) / ctx.config.count),
|
||||
}, c.id);
|
||||
@@ -144,7 +144,7 @@ export const judge = async (ctx) => {
|
||||
for (const sid in ctx.config.subtasks) tasks.push(judgeSubtask(ctx.config.subtasks[sid])(ctx));
|
||||
await Promise.all(tasks);
|
||||
ctx.stat.done = new Date();
|
||||
ctx.next({ judge_text: JSON.stringify(ctx.stat) });
|
||||
ctx.next({ message: JSON.stringify(ctx.stat) });
|
||||
ctx.end({
|
||||
status: ctx.total_status,
|
||||
score: ctx.total_score,
|
||||
|
||||
@@ -39,7 +39,7 @@ function judgeCase(c) {
|
||||
status = STATUS.STATUS_RUNTIME_ERROR;
|
||||
if (code < 32) message = signals[code];
|
||||
else message = `您的程序返回了 ${code}.`;
|
||||
} else [status, score, message] = resInteractor.files.stderr.split('\n');
|
||||
} else[status, score, message] = resInteractor.files.stderr.split('\n');
|
||||
ctxSubtask.score = Score[ctxSubtask.subtask.type](ctxSubtask.score, score);
|
||||
ctxSubtask.status = Math.max(ctxSubtask.status, status);
|
||||
ctx.total_time_usage_ms += time_usage_ms;
|
||||
@@ -51,7 +51,7 @@ function judgeCase(c) {
|
||||
score: 0,
|
||||
time_ms: time_usage_ms,
|
||||
memory_kb: memory_usage_kb,
|
||||
judge_text: message,
|
||||
message,
|
||||
},
|
||||
progress: Math.floor((c.id * 100) / ctx.config.count),
|
||||
});
|
||||
@@ -110,7 +110,7 @@ export const judge = async (ctx) => {
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
ctx.stat.done = new Date();
|
||||
ctx.next({ judge_text: JSON.stringify(ctx.stat) });
|
||||
ctx.next({ message: JSON.stringify(ctx.stat) });
|
||||
console.log({
|
||||
status: ctx.total_status,
|
||||
score: ctx.total_score,
|
||||
|
||||
@@ -48,11 +48,11 @@ export const judge = async (ctx) => {
|
||||
status,
|
||||
time_ms: time_usage_ms,
|
||||
memory_kb: memory_usage_kb,
|
||||
judge_text: message,
|
||||
message,
|
||||
},
|
||||
});
|
||||
ctx.stat.done = new Date();
|
||||
ctx.next({ judge_text: JSON.stringify(ctx.stat) });
|
||||
ctx.next({ message: JSON.stringify(ctx.stat) });
|
||||
ctx.end({
|
||||
status,
|
||||
score: status === STATUS.STATUS_ACCEPTED ? 100 : 0,
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function judge({
|
||||
status,
|
||||
progress: 100,
|
||||
case: {
|
||||
status, score, time_ms: 0, memory_kb: 0, judge_text: message,
|
||||
status, score, time_ms: 0, memory_kb: 0, message,
|
||||
},
|
||||
});
|
||||
end({
|
||||
|
||||
@@ -78,6 +78,7 @@ export async function del(fileId) {
|
||||
|
||||
export async function run(execute, params?) {
|
||||
let result;
|
||||
global.reqCount++;
|
||||
// eslint-disable-next-line no-return-await
|
||||
if (typeof execute === 'object') return await runMultiple(execute);
|
||||
try {
|
||||
|
||||
@@ -38,10 +38,10 @@ int main(){
|
||||
},
|
||||
stat: {},
|
||||
clean: [],
|
||||
next: () => { },
|
||||
end: (data) => {
|
||||
if (data.stdout) output = data.stdout;
|
||||
next: (data) => {
|
||||
if (data.case) output = data.case.message;
|
||||
},
|
||||
end: () => { },
|
||||
};
|
||||
context.tmpdir = path.resolve(tmpdir(), 'hydro', 'tmp', 'sysinfo');
|
||||
fs.ensureDirSync(context.tmpdir);
|
||||
@@ -52,7 +52,7 @@ int main(){
|
||||
tmpfs.umount(context.tmpdir);
|
||||
fs.removeSync(context.tmpdir);
|
||||
const a = output.split(' ');
|
||||
return parseInt(a[a.length - 1], 10);
|
||||
return parseInt(a[a.length - 2], 10);
|
||||
}
|
||||
|
||||
export async function get() {
|
||||
@@ -84,11 +84,20 @@ export async function get() {
|
||||
cache.flags = flags;
|
||||
cache.mid = mid;
|
||||
cache.stack = stack;
|
||||
global.reqCount = 0;
|
||||
return {
|
||||
mid, cpu, memory, osinfo, load, flags, CpuTemp, battery, stack,
|
||||
mid, cpu, memory, osinfo, load, flags, CpuTemp, battery, stack, reqCount: 0,
|
||||
};
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
reqCount: number,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function update() {
|
||||
const [Memory, CurrentLoad, CpuTemp, Battery] = await Promise.all([
|
||||
systeminformation.mem(),
|
||||
@@ -104,13 +113,15 @@ export async function update() {
|
||||
let battery;
|
||||
if (!Battery.hasbattery) battery = 'No battery';
|
||||
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`;
|
||||
const reqCount = global.reqCount;
|
||||
global.reqCount = 0;
|
||||
return [
|
||||
mid,
|
||||
{
|
||||
memory, load, battery, CpuTemp,
|
||||
memory, load, battery, CpuTemp, reqCount,
|
||||
},
|
||||
{
|
||||
mid, cpu, memory, osinfo, load, flags, battery, CpuTemp, stack,
|
||||
mid, cpu, memory, osinfo, load, flags, battery, CpuTemp, stack, reqCount,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -646,6 +646,7 @@ Star: 收藏
|
||||
Start at: 开始于
|
||||
Statistics: 统计
|
||||
Status is hidden: 状态已隐藏
|
||||
status: 状态
|
||||
Status: 状态
|
||||
Submission Statistics: 递交统计
|
||||
Submission: 递交
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.12.8",
|
||||
"version": "2.12.9",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -54,6 +54,7 @@ export async function load(call: Entry) {
|
||||
bus.subscribe(['system_database_connected'], h);
|
||||
require('../service/db');
|
||||
});
|
||||
require('../service/monitor');
|
||||
for (const i of builtinModel) require(`../model/${i}`);
|
||||
const modelSystem = require('../model/system');
|
||||
const dbVer = await modelSystem.get('db.ver');
|
||||
|
||||
@@ -199,6 +199,11 @@ class DomainJoinApplicationsHandler extends ManageHandler {
|
||||
if (!this.response.body.joinSettings) {
|
||||
delete this.response.body.expirations[domain.JOIN_EXPIRATION_KEEP_CURRENT];
|
||||
}
|
||||
this.response.body.path = [
|
||||
['Hydro', 'homepage'],
|
||||
['domain', null],
|
||||
['domain_join_applications', null],
|
||||
];
|
||||
this.response.template = 'domain_join_applications.html';
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class ProblemMainHandler extends ProblemHandler {
|
||||
}
|
||||
if (!this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)) query.hidden = false;
|
||||
const [pdocs, ppcount, pcount] = await paginate(
|
||||
problem.getMulti(domainId, query).sort({ pid: 1 }),
|
||||
problem.getMulti(domainId, query).sort({ pid: 1, docId: 1 }),
|
||||
page,
|
||||
CONSTANT.PROBLEM_PER_PAGE,
|
||||
);
|
||||
@@ -119,7 +119,7 @@ class ProblemCategoryHandler extends ProblemHandler {
|
||||
let psdict = {};
|
||||
if (!this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)) q.hidden = false;
|
||||
const [pdocs, ppcount, pcount] = await paginate(
|
||||
problem.getMulti(domainId, q).sort({ pid: 1 }),
|
||||
problem.getMulti(domainId, q).sort({ pid: 1, docId: 1 }),
|
||||
page,
|
||||
CONSTANT.PROBLEM_PER_PAGE,
|
||||
);
|
||||
@@ -190,7 +190,7 @@ class ProblemDetailHandler extends ProblemHandler {
|
||||
// eslint-disable-next-line
|
||||
async get(...args: any[]) { }
|
||||
|
||||
@param('pid', Types.ObjectID)
|
||||
@param('pid', Types.UnsignedInt)
|
||||
@param('dest', Types.String)
|
||||
@param('hidden', Types.Boolean)
|
||||
async postCopy(domainId: string, pid: number, destDomainId: string, hidden = false) {
|
||||
|
||||
@@ -192,7 +192,6 @@ PERM.PERM_DEFAULT = PERM.PERM_VIEW
|
||||
| PERM.PERM_EDIT_DISCUSSION_SELF
|
||||
| PERM.PERM_REPLY_DISCUSSION
|
||||
| PERM.PERM_EDIT_DISCUSSION_REPLY_SELF
|
||||
// PERM_EDIT_DISCUSSION_REPLY_SELF_DISCUSSION
|
||||
| PERM.PERM_DELETE_DISCUSSION_REPLY_SELF
|
||||
| PERM.PERM_DELETE_DISCUSSION_REPLY_SELF_DISCUSSION
|
||||
| PERM.PERM_VIEW_CONTEST
|
||||
@@ -206,7 +205,6 @@ PERM.PERM_DEFAULT = PERM.PERM_VIEW
|
||||
| PERM.PERM_VIEW_TRAINING
|
||||
| PERM.PERM_CREATE_TRAINING
|
||||
| PERM.PERM_EDIT_TRAINING_SELF
|
||||
| PERM.PERM_VIEW_RANKING
|
||||
| PERM.PERM_SUBMIT_PROBLEM
|
||||
| PERM.PERM_CREATE_PROBLEM_SOLUTION
|
||||
| PERM.PERM_VOTE_PROBLEM_SOLUTION
|
||||
|
||||
@@ -18,7 +18,7 @@ export function updateJudger(args) {
|
||||
args.type = 'judger';
|
||||
return coll.updateOne(
|
||||
{ mid: args.mid, type: 'judger' },
|
||||
{ $set: args },
|
||||
{ $set: { ...args, updateAt: new Date() } },
|
||||
{ upsert: true },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -326,6 +326,7 @@ export class Handler {
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
console.log(name, args);
|
||||
console.log(e.stack);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/migrate-vijos",
|
||||
"version": "1.3.3",
|
||||
"version": "1.3.4",
|
||||
"main": "package.json",
|
||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||
"author": "undefined <masnn0@outlook.com>",
|
||||
|
||||
@@ -11,7 +11,7 @@ import mongodb, { ObjectID, Db, Cursor } from 'mongodb';
|
||||
const dst = global.Hydro.service.db;
|
||||
const { file, discussion, document } = global.Hydro.model;
|
||||
const { testdataConfig } = global.Hydro.lib;
|
||||
|
||||
// TODO handle usage_userfile
|
||||
// TODO output enhancement
|
||||
const map = {};
|
||||
|
||||
@@ -398,6 +398,25 @@ async function message(src: Db, report: Function) {
|
||||
}
|
||||
}
|
||||
|
||||
async function removeInvalidPid(src: Db, report: Function) {
|
||||
const count = await dst.collection('document').find({ docType: 10 }).count();
|
||||
const bulk = dst.collection('document').initializeUnorderedBulkOp();
|
||||
await report({ progress: 1, message: `Remove pid: ${count}` });
|
||||
const total = Math.floor(count / 50);
|
||||
for (let i = 0; i <= total; i++) {
|
||||
const docs = await dst.collection('document')
|
||||
.find({ docType: 10 }).skip(i * 50).limit(50)
|
||||
.toArray();
|
||||
for (const doc of docs) {
|
||||
const id = parseInt(doc.pid, 10);
|
||||
if (Number.isSafeInteger(id)) {
|
||||
bulk.find({ _id: doc._id }).updateOne({ $unset: { pid: '' } });
|
||||
}
|
||||
}
|
||||
await bulk.execute();
|
||||
}
|
||||
}
|
||||
|
||||
async function task(name: string, src: Db, report: Function) {
|
||||
const count = await cursor[name](src).count();
|
||||
await report({ progress: 1, message: `${name}: ${count}` });
|
||||
@@ -513,6 +532,7 @@ export async function run({
|
||||
await fixProblem(report);
|
||||
await discussionNode(src, report);
|
||||
await message(src, report);
|
||||
await removeInvalidPid(src, report);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user