mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: testlib partial correct
This commit is contained in:
1 parent
79138861a6
commit
e04409e71a
16 files changed
+32
-66
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/hydrojudge",
|
"name": "@hydrooj/hydrojudge",
|
||||||
"bin": "bin/hydrojudge.js",
|
"bin": "bin/hydrojudge.js",
|
||||||
"version": "2.11.4",
|
"version": "2.11.5",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable no-template-curly-in-string */
|
/* eslint-disable no-template-curly-in-string */
|
||||||
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
import { SystemError } from './error';
|
import { SystemError } from './error';
|
||||||
import { run } from './sandbox';
|
import { run } from './sandbox';
|
||||||
import * as STATUS from './status';
|
|
||||||
import { parse } from './testlib';
|
import { parse } from './testlib';
|
||||||
|
|
||||||
interface CheckResult {
|
interface CheckResult {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { LangConfig } from '@hydrooj/utils/lib/lang';
|
import { LangConfig } from '@hydrooj/utils/lib/lang';
|
||||||
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
import { CompileError } from './error';
|
import { CompileError } from './error';
|
||||||
import { Execute } from './interface';
|
import { Execute } from './interface';
|
||||||
import { del, run } from './sandbox';
|
import { del, run } from './sandbox';
|
||||||
import * as STATUS from './status';
|
|
||||||
import { compilerText } from './utils';
|
import { compilerText } from './utils';
|
||||||
|
|
||||||
export = async function compile(
|
export = async function compile(
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import { ObjectID } from 'mongodb';
|
|||||||
import PQueue from 'p-queue';
|
import PQueue from 'p-queue';
|
||||||
import WebSocket from 'ws';
|
import WebSocket from 'ws';
|
||||||
import { LangConfig } from '@hydrooj/utils/lib/lang';
|
import { LangConfig } from '@hydrooj/utils/lib/lang';
|
||||||
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
import readCases from '../cases';
|
import readCases from '../cases';
|
||||||
import { getConfig } from '../config';
|
import { getConfig } from '../config';
|
||||||
import { CompileError, FormatError, SystemError } from '../error';
|
import { CompileError, FormatError, SystemError } from '../error';
|
||||||
import judge from '../judge';
|
import judge from '../judge';
|
||||||
import log from '../log';
|
import log from '../log';
|
||||||
import { STATUS_COMPILE_ERROR, STATUS_SYSTEM_ERROR } from '../status';
|
|
||||||
import * as sysinfo from '../sysinfo';
|
import * as sysinfo from '../sysinfo';
|
||||||
import * as tmpfs from '../tmpfs';
|
import * as tmpfs from '../tmpfs';
|
||||||
import {
|
import {
|
||||||
@@ -78,19 +78,19 @@ class JudgeTask {
|
|||||||
if (e instanceof CompileError) {
|
if (e instanceof CompileError) {
|
||||||
this.next({ compiler_text: compilerText(e.stdout, e.stderr) });
|
this.next({ compiler_text: compilerText(e.stdout, e.stderr) });
|
||||||
this.end({
|
this.end({
|
||||||
status: STATUS_COMPILE_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
status: STATUS.STATUS_COMPILE_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
||||||
});
|
});
|
||||||
} else if (e instanceof FormatError) {
|
} else if (e instanceof FormatError) {
|
||||||
this.next({ judge_text: 'Testdata configuration incorrect.' });
|
this.next({ judge_text: 'Testdata configuration incorrect.' });
|
||||||
this.next({ judge_text: { message: e.message, params: e.params } });
|
this.next({ judge_text: { message: e.message, params: e.params } });
|
||||||
this.end({
|
this.end({
|
||||||
status: STATUS_SYSTEM_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
status: STATUS.STATUS_FORMAT_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
this.next({ message: { message: e.message, params: e.params || [], ...argv.options.debug ? { stack: e.stack } : {} } });
|
this.next({ message: { message: e.message, params: e.params || [], ...argv.options.debug ? { stack: e.stack } : {} } });
|
||||||
this.end({
|
this.end({
|
||||||
status: STATUS_SYSTEM_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
status: STATUS.STATUS_SYSTEM_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import Queue from 'p-queue';
|
import Queue from 'p-queue';
|
||||||
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
import { check, compileChecker } from '../check';
|
import { check, compileChecker } from '../check';
|
||||||
import compile from '../compile';
|
import compile from '../compile';
|
||||||
import { getConfig } from '../config';
|
import { getConfig } from '../config';
|
||||||
import { CompileError, SystemError } from '../error';
|
import { CompileError, SystemError } from '../error';
|
||||||
import { run } from '../sandbox';
|
import { run } from '../sandbox';
|
||||||
import signals from '../signals';
|
import signals from '../signals';
|
||||||
import * as STATUS from '../status';
|
|
||||||
import { parseFilename } from '../utils';
|
import { parseFilename } from '../utils';
|
||||||
|
|
||||||
const Score = {
|
const Score = {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
// Not implemented
|
// Not implemented
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
import { check, compileChecker } from '../check';
|
import { check, compileChecker } from '../check';
|
||||||
import compile from '../compile';
|
import compile from '../compile';
|
||||||
import { CompileError } from '../error';
|
import { CompileError } from '../error';
|
||||||
import { run } from '../sandbox';
|
import { run } from '../sandbox';
|
||||||
import signals from '../signals';
|
import signals from '../signals';
|
||||||
import * as STATUS from '../status';
|
|
||||||
import { copyInDir, parseFilename } from '../utils';
|
import { copyInDir, parseFilename } from '../utils';
|
||||||
|
|
||||||
export const judge = async (ctx) => {
|
export const judge = async (ctx) => {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import Queue from 'p-queue';
|
import Queue from 'p-queue';
|
||||||
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
import compile from '../compile';
|
import compile from '../compile';
|
||||||
import { getConfig } from '../config';
|
import { getConfig } from '../config';
|
||||||
import { run } from '../sandbox';
|
import { run } from '../sandbox';
|
||||||
import signals from '../signals';
|
import signals from '../signals';
|
||||||
import * as STATUS from '../status';
|
|
||||||
import { parse } from '../testlib';
|
import { parse } from '../testlib';
|
||||||
import { findFileSync, parseFilename } from '../utils';
|
import { findFileSync, parseFilename } from '../utils';
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
import compile from '../compile';
|
import compile from '../compile';
|
||||||
import { CompileError } from '../error';
|
import { CompileError } from '../error';
|
||||||
import { run } from '../sandbox';
|
import { run } from '../sandbox';
|
||||||
import signals from '../signals';
|
import signals from '../signals';
|
||||||
import * as STATUS from '../status';
|
|
||||||
import { compilerText, parseMemoryMB, parseTimeMS } from '../utils';
|
import { compilerText, parseMemoryMB, parseTimeMS } from '../utils';
|
||||||
|
|
||||||
export const judge = async (ctx) => {
|
export const judge = async (ctx) => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as STATUS from '../status';
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
|
|
||||||
export async function judge({
|
export async function judge({
|
||||||
next, end, config, code,
|
next, end, config, code,
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import Axios from 'axios';
|
import Axios from 'axios';
|
||||||
import cac from 'cac';
|
import cac from 'cac';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
import { getConfig } from './config';
|
import { getConfig } from './config';
|
||||||
import { FormatError, SystemError } from './error';
|
import { FormatError, SystemError } from './error';
|
||||||
import { Logger } from './log';
|
import { Logger } from './log';
|
||||||
import * as STATUS from './status';
|
|
||||||
import { cmd, parseMemoryMB } from './utils';
|
import { cmd, parseMemoryMB } from './utils';
|
||||||
|
|
||||||
const argv = cac().parse();
|
const argv = cac().parse();
|
||||||
@@ -111,7 +111,7 @@ export async function runMultiple(execute) {
|
|||||||
if (argv.options.showSandbox) logger.debug('%d %s', id, JSON.stringify(res.data));
|
if (argv.options.showSandbox) logger.debug('%d %s', id, JSON.stringify(res.data));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof FormatError) throw e;
|
if (e instanceof FormatError) throw e;
|
||||||
throw new SystemError('Sandbox Error');
|
throw new SystemError('Sandbox Error', [e]);
|
||||||
}
|
}
|
||||||
return await Promise.all(res.data.map((i) => adaptResult(i, {})));
|
return await Promise.all(res.data.map((i) => adaptResult(i, {})));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import path from 'path';
|
|||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import { noop } from 'lodash';
|
import { noop } from 'lodash';
|
||||||
import { ObjectID } from 'mongodb';
|
import { ObjectID } from 'mongodb';
|
||||||
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
import { Logger } from 'hydrooj/src/logger';
|
import { Logger } from 'hydrooj/src/logger';
|
||||||
import * as monitor from 'hydrooj/src/service/monitor';
|
import * as monitor from 'hydrooj/src/service/monitor';
|
||||||
import readCases from './cases';
|
import readCases from './cases';
|
||||||
import { getConfig } from './config';
|
import { getConfig } from './config';
|
||||||
import { CompileError, FormatError, SystemError } from './error';
|
import { CompileError, FormatError, SystemError } from './error';
|
||||||
import { STATUS_COMPILE_ERROR, STATUS_SYSTEM_ERROR } from './status';
|
|
||||||
import * as sysinfo from './sysinfo';
|
import * as sysinfo from './sysinfo';
|
||||||
import * as tmpfs from './tmpfs';
|
import * as tmpfs from './tmpfs';
|
||||||
import { compilerText, md5 } from './utils';
|
import { compilerText, md5 } from './utils';
|
||||||
@@ -207,18 +207,18 @@ async function postInit() {
|
|||||||
if (e instanceof CompileError) {
|
if (e instanceof CompileError) {
|
||||||
this.next({ compiler_text: compilerText(e.stdout, e.stderr) });
|
this.next({ compiler_text: compilerText(e.stdout, e.stderr) });
|
||||||
this.end({
|
this.end({
|
||||||
status: STATUS_COMPILE_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
status: STATUS.STATUS_COMPILE_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
||||||
});
|
});
|
||||||
} else if (e instanceof FormatError) {
|
} else if (e instanceof FormatError) {
|
||||||
this.next({ message: { message: e.message, params: e.params } });
|
this.next({ message: { message: e.message, params: e.params } });
|
||||||
this.end({
|
this.end({
|
||||||
status: STATUS_SYSTEM_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
status: STATUS.STATUS_FORMAT_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
this.next({ message: { message: e.message, params: e.params, ...process.env.DEV ? { stack: e.stack } : {} } });
|
this.next({ message: { message: e.message, params: e.params, ...process.env.DEV ? { stack: e.stack } : {} } });
|
||||||
this.end({
|
this.end({
|
||||||
status: STATUS_SYSTEM_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
status: STATUS.STATUS_SYSTEM_ERROR, score: 0, time_ms: 0, memory_kb: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
export const STATUS_WAITING = 0;
|
|
||||||
export const STATUS_ACCEPTED = 1;
|
|
||||||
export const STATUS_WRONG_ANSWER = 2;
|
|
||||||
export const STATUS_TIME_LIMIT_EXCEEDED = 3;
|
|
||||||
export const STATUS_MEMORY_LIMIT_EXCEEDED = 4;
|
|
||||||
export const STATUS_OUTPUT_LIMIT_EXCEEDED = 5;
|
|
||||||
export const STATUS_RUNTIME_ERROR = 6;
|
|
||||||
export const STATUS_COMPILE_ERROR = 7;
|
|
||||||
export const STATUS_SYSTEM_ERROR = 8;
|
|
||||||
export const STATUS_CANCELED = 9;
|
|
||||||
export const STATUS_ETC = 10;
|
|
||||||
export const STATUS_JUDGING = 20;
|
|
||||||
export const STATUS_COMPILING = 21;
|
|
||||||
export const STATUS_FETCHED = 22;
|
|
||||||
export const STATUS_IGNORED = 30;
|
|
||||||
|
|
||||||
export const STATUS_TEXTS = {
|
|
||||||
[STATUS_WAITING]: 'Waiting',
|
|
||||||
[STATUS_ACCEPTED]: 'Accepted',
|
|
||||||
[STATUS_WRONG_ANSWER]: 'Wrong Answer',
|
|
||||||
[STATUS_TIME_LIMIT_EXCEEDED]: 'Time Exceeded',
|
|
||||||
[STATUS_MEMORY_LIMIT_EXCEEDED]: 'Memory Exceeded',
|
|
||||||
[STATUS_OUTPUT_LIMIT_EXCEEDED]: 'Output Exceeded',
|
|
||||||
[STATUS_RUNTIME_ERROR]: 'Runtime Error',
|
|
||||||
[STATUS_COMPILE_ERROR]: 'Compile Error',
|
|
||||||
[STATUS_SYSTEM_ERROR]: 'System Error',
|
|
||||||
[STATUS_CANCELED]: 'Cancelled',
|
|
||||||
[STATUS_ETC]: 'Unknown Error',
|
|
||||||
[STATUS_JUDGING]: 'Running',
|
|
||||||
[STATUS_COMPILING]: 'Compiling',
|
|
||||||
[STATUS_FETCHED]: 'Fetched',
|
|
||||||
[STATUS_IGNORED]: 'Ignored',
|
|
||||||
};
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import * as STATUS from './status';
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
|
|
||||||
export function parse(output: string, fullscore: number) {
|
export function parse(output: string, fullscore: number) {
|
||||||
let status = STATUS.STATUS_WRONG_ANSWER;
|
let status = STATUS.STATUS_WRONG_ANSWER;
|
||||||
let score = 0;
|
let score = 0;
|
||||||
let message = output;
|
let message = output.substr(0, 1024);
|
||||||
if (output.startsWith('ok ')) {
|
if (output.startsWith('ok ')) {
|
||||||
status = STATUS.STATUS_ACCEPTED;
|
status = STATUS.STATUS_ACCEPTED;
|
||||||
score = fullscore;
|
score = fullscore;
|
||||||
@@ -13,19 +13,18 @@ export function parse(output: string, fullscore: number) {
|
|||||||
message = `PE ${output.split('wrong output format ')[1] || ''}`;
|
message = `PE ${output.split('wrong output format ')[1] || ''}`;
|
||||||
} else if (output.startsWith('partially correct ')) {
|
} else if (output.startsWith('partially correct ')) {
|
||||||
message = `PC ${output.split('partially correct ')[1] || ''}`;
|
message = `PC ${output.split('partially correct ')[1] || ''}`;
|
||||||
const p = +output.split('partially correct (')[1].split(')')[0];
|
let p = +output.split('partially correct (')[1].split(')')[0] || 0;
|
||||||
score = Math.floor(fullscore * (p / 200));
|
if (p > 1) p /= 100;
|
||||||
|
score = Math.floor(fullscore * p);
|
||||||
} else if (output.startsWith('points ')) {
|
} else if (output.startsWith('points ')) {
|
||||||
const p = +output.split('points ')[1].split(' ')[0];
|
let p = +output.split('points ')[1].split(' ')[0] || 0;
|
||||||
if (p === 100) {
|
if (p > 1) p /= 100;
|
||||||
|
if (p === 1) {
|
||||||
status = STATUS.STATUS_ACCEPTED;
|
status = STATUS.STATUS_ACCEPTED;
|
||||||
score = fullscore;
|
score = fullscore;
|
||||||
const base = output.split('points ')[1] || '';
|
const base = output.split('points ')[1] || '';
|
||||||
message = base.substr(base.indexOf(' '), 1024);
|
message = base.substr(base.indexOf(' '), 1024);
|
||||||
} else {
|
} else score = Math.floor(fullscore * p);
|
||||||
message = `partially correct ${output.split('points ')[1] || ''}`;
|
|
||||||
score = Math.floor(fullscore * (p / 100));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return { status, score, message };
|
return { status, score, message };
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
"tether": "^1.4.7",
|
"tether": "^1.4.7",
|
||||||
"tether-drop": "^1.4.2",
|
"tether-drop": "^1.4.2",
|
||||||
"through2": "^4.0.2",
|
"through2": "^4.0.2",
|
||||||
"timeago-react": "^3.0.3",
|
"timeago-react": "^3.0.4",
|
||||||
"timeago.js": "^4.0.2",
|
"timeago.js": "^4.0.2",
|
||||||
"vditor": "^3.8.7",
|
"vditor": "^3.8.7",
|
||||||
"vinyl-buffer": "^1.0.1",
|
"vinyl-buffer": "^1.0.1",
|
||||||
@@ -101,7 +101,7 @@
|
|||||||
"webpackbar": "^5.0.0-3"
|
"webpackbar": "^5.0.0-3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"esbuild": "^0.12.28",
|
"esbuild": "^0.12.29",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"jsesc": "^3.0.2",
|
"jsesc": "^3.0.2",
|
||||||
"katex": "^0.13.18",
|
"katex": "^0.13.18",
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
"systeminformation": "^5.9.3"
|
"systeminformation": "^5.9.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/fs-extra": "^9.0.12",
|
"@types/fs-extra": "^9.0.13",
|
||||||
"moment-timezone": "^0.5.33"
|
"moment-timezone": "^0.5.33"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,8 +16,8 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jsdom": "^16.2.13",
|
"@types/jsdom": "^16.2.13",
|
||||||
"@types/lodash": "^4.14.172",
|
"@types/lodash": "^4.14.173",
|
||||||
"@types/superagent": "^4.1.12",
|
"@types/superagent": "^4.1.13",
|
||||||
"@types/superagent-proxy": "^2.0.1"
|
"@types/superagent-proxy": "^2.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user