mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: 修复pretest结果不回显的问题
This commit is contained in:
1 parent
25570d6275
commit
cce3b3a745
6 files changed
+69
-39
No files matched your search
@@ -5,27 +5,72 @@ import * as STATUS from '../status';
|
|||||||
import { run } from '../sandbox';
|
import { run } from '../sandbox';
|
||||||
import compile from '../compile';
|
import compile from '../compile';
|
||||||
import signals from '../signals';
|
import signals from '../signals';
|
||||||
|
import { compilerText, parseMemoryMB, parseTimeMS } from '../utils';
|
||||||
|
import { CompileError } from '../error';
|
||||||
|
|
||||||
export const judge = async (ctx) => {
|
export const judge = async (ctx) => {
|
||||||
ctx.stat.judge = new Date();
|
ctx.stat.judge = new Date();
|
||||||
ctx.next({ status: STATUS.STATUS_COMPILING });
|
ctx.next({ status: STATUS.STATUS_COMPILING });
|
||||||
ctx.execute = await compile(ctx.lang, ctx.code, 'code', {}, ctx.next);
|
try {
|
||||||
|
ctx.execute = await compile(ctx.lang, ctx.code, 'code', {}, ctx.next);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof CompileError) {
|
||||||
|
ctx.next({
|
||||||
|
status: STATUS.STATUS_COMPILE_ERROR,
|
||||||
|
case: {
|
||||||
|
status: STATUS.STATUS_COMPILE_ERROR,
|
||||||
|
score: 0,
|
||||||
|
time_ms: 0,
|
||||||
|
memory_kb: 0,
|
||||||
|
message: compilerText(e.stdout, e.stderr),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
ctx.end({
|
||||||
|
status: STATUS.STATUS_COMPILE_ERROR,
|
||||||
|
score: 0,
|
||||||
|
time_ms: 0,
|
||||||
|
memory_kb: 0,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ctx.next({
|
||||||
|
status: STATUS.STATUS_SYSTEM_ERROR,
|
||||||
|
case: {
|
||||||
|
status: STATUS.STATUS_SYSTEM_ERROR,
|
||||||
|
score: 0,
|
||||||
|
time_ms: 0,
|
||||||
|
memory_kb: 0,
|
||||||
|
message: `${e.message}\n${JSON.stringify(e.params)}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
ctx.end({
|
||||||
|
status: STATUS.STATUS_COMPILE_ERROR,
|
||||||
|
score: 0,
|
||||||
|
time_ms: 0,
|
||||||
|
memory_kb: 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
ctx.clean.push(ctx.execute.clean);
|
ctx.clean.push(ctx.execute.clean);
|
||||||
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
||||||
const copyIn = { ...ctx.execute.copyIn };
|
const copyIn = { ...ctx.execute.copyIn };
|
||||||
const stdin = path.resolve(ctx.tmpdir, 'stdin');
|
const { filename } = ctx.config;
|
||||||
const stdout = path.resolve(ctx.tmpdir, 'stdout');
|
if (filename) copyIn[`${filename}.in`] = { content: ctx.config.input };
|
||||||
const stderr = path.resolve(ctx.tmpdir, 'stderr');
|
const copyOut = filename ? [`${filename}.out`] : [];
|
||||||
fs.writeFileSync(stdin, ctx.config.input || '');
|
const stdin = path.resolve(ctx.tmpdir, '0.in');
|
||||||
|
await fs.writeFile(stdin, ctx.config.input);
|
||||||
|
const stdout = path.resolve(ctx.tmpdir, '0.out');
|
||||||
|
const stderr = path.resolve(ctx.tmpdir, '0.err');
|
||||||
const res = await run(
|
const res = await run(
|
||||||
ctx.execute.execute.replace(/\$\{name\}/g, 'code'),
|
ctx.execute.execute.replace(/\$\{name\}/g, 'code'),
|
||||||
{
|
{
|
||||||
stdin,
|
stdin: filename ? null : stdin,
|
||||||
stdout,
|
stdout: filename ? null : stdout,
|
||||||
stderr,
|
stderr,
|
||||||
copyIn,
|
copyIn,
|
||||||
time_limit_ms: ctx.config.time,
|
copyOut,
|
||||||
memory_limit_mb: ctx.config.memory,
|
time_limit_ms: parseTimeMS(ctx.config.time),
|
||||||
|
memory_limit_mb: parseMemoryMB(ctx.config.memory),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const { code, time_usage_ms, memory_usage_kb } = res;
|
const { code, time_usage_ms, memory_usage_kb } = res;
|
||||||
|
|||||||
@@ -12,18 +12,19 @@ const MEMORY_UNITS = { k: 0.1, m: 1, g: 1024 };
|
|||||||
const EMPTY_STR = /^[ \r\n\t]*$/i;
|
const EMPTY_STR = /^[ \r\n\t]*$/i;
|
||||||
|
|
||||||
export const cmd = parse;
|
export const cmd = parse;
|
||||||
|
|
||||||
export function noop() { }
|
export function noop() { }
|
||||||
|
|
||||||
export function parseTimeMS(str: string) {
|
export function parseTimeMS(val: string | number) {
|
||||||
const match = TIME_RE.exec(str);
|
if (typeof val === 'number') return val;
|
||||||
if (!match) throw new FormatError('Error parsing time: {0}', [str]);
|
const match = TIME_RE.exec(val);
|
||||||
|
if (!match) throw new FormatError('Error parsing time: {0}', [val]);
|
||||||
return Math.floor(parseFloat(match[1]) * TIME_UNITS[match[2]]);
|
return Math.floor(parseFloat(match[1]) * TIME_UNITS[match[2]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseMemoryMB(str: string) {
|
export function parseMemoryMB(val: string | number) {
|
||||||
const match = MEMORY_RE.exec(str);
|
if (typeof val === 'number') return val;
|
||||||
if (!match) throw new FormatError('Error parsing memory: {0}', [str]);
|
const match = MEMORY_RE.exec(val);
|
||||||
|
if (!match) throw new FormatError('Error parsing memory: {0}', [val]);
|
||||||
return Math.floor(parseFloat(match[1]) * MEMORY_UNITS[match[2]]);
|
return Math.floor(parseFloat(match[1]) * MEMORY_UNITS[match[2]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.15.18",
|
"version": "2.15.19",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -295,9 +295,7 @@ export class ProblemPretestHandler extends ProblemDetailHandler {
|
|||||||
|
|
||||||
export class ProblemPretestConnectionHandler extends ConnectionHandler {
|
export class ProblemPretestConnectionHandler extends ConnectionHandler {
|
||||||
pid: string;
|
pid: string;
|
||||||
|
|
||||||
domainId: string;
|
domainId: string;
|
||||||
|
|
||||||
dispose: bus.Disposable;
|
dispose: bus.Disposable;
|
||||||
|
|
||||||
@param('pid', Types.String)
|
@param('pid', Types.String)
|
||||||
@@ -316,12 +314,6 @@ export class ProblemPretestConnectionHandler extends ConnectionHandler {
|
|||||||
|| rdoc.pid.toString() !== this.pid
|
|| rdoc.pid.toString() !== this.pid
|
||||||
|| rdoc.domainId !== this.domainId
|
|| rdoc.domainId !== this.domainId
|
||||||
) return;
|
) return;
|
||||||
rdoc.compilerTexts = [];
|
|
||||||
rdoc.judgeTexts = [];
|
|
||||||
// @ts-ignore
|
|
||||||
rdoc.testCases = rdoc.testCases.map((c) => ({
|
|
||||||
status: c.status,
|
|
||||||
}));
|
|
||||||
// TODO handle update
|
// TODO handle update
|
||||||
if (rdoc.contest) return;
|
if (rdoc.contest) return;
|
||||||
this.send({ rdoc });
|
this.send({ rdoc });
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { Dictionary } from 'lodash';
|
|
||||||
|
|
||||||
const locales = {};
|
const locales = {};
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@@ -43,7 +41,6 @@ String.prototype.rawformat = function rawFormat(object) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
String.prototype.translate = function translate(...languages: string[]) {
|
String.prototype.translate = function translate(...languages: string[]) {
|
||||||
languages.push(global.Hydro.model.system.get('server.language'));
|
|
||||||
for (const language of languages) {
|
for (const language of languages) {
|
||||||
if (!language) continue;
|
if (!language) continue;
|
||||||
const curr = (locales[language] || {})[this] || (locales[language.split('_')[0]] || {})[this];
|
const curr = (locales[language] || {})[this] || (locales[language.split('_')[0]] || {})[this];
|
||||||
@@ -52,9 +49,9 @@ String.prototype.translate = function translate(...languages: string[]) {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
function load(data: Dictionary<string>) {
|
function load(data: Record<string, Record<string, string>>) {
|
||||||
for (const i in data) {
|
for (const i in data) {
|
||||||
if (!locales[i]) locales[i] = data[i];
|
if (!locales[i]) locales[i] = { __id: i, ...data[i] };
|
||||||
else locales[i] = Object.assign(locales[i], data[i]);
|
else locales[i] = Object.assign(locales[i], data[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,15 +232,10 @@ export namespace Time {
|
|||||||
export const week = day * 7;
|
export const week = day * 7;
|
||||||
export function formatTimeShort(ms: number) {
|
export function formatTimeShort(ms: number) {
|
||||||
const abs = Math.abs(ms);
|
const abs = Math.abs(ms);
|
||||||
if (abs >= day - hour / 2) {
|
if (abs >= day - hour / 2) return `${Math.round(ms / day)}d`;
|
||||||
return `${Math.round(ms / day)}d`;
|
if (abs >= hour - minute / 2) return `${Math.round(ms / hour)}h`;
|
||||||
} if (abs >= hour - minute / 2) {
|
if (abs >= minute - second / 2) return `${Math.round(ms / minute)}m`;
|
||||||
return `${Math.round(ms / hour)}h`;
|
if (abs >= second) return `${Math.round(ms / second)}s`;
|
||||||
} if (abs >= minute - second / 2) {
|
|
||||||
return `${Math.round(ms / minute)}m`;
|
|
||||||
} if (abs >= second) {
|
|
||||||
return `${Math.round(ms / second)}s`;
|
|
||||||
}
|
|
||||||
return `${ms}ms`;
|
return `${ms}ms`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user