judge: testlib partial correct

This commit is contained in:
undefined committed 2021-09-23 13:13:09 +08:00
1 parent 79138861a6
commit e04409e71a
16 files changed
+32 -66

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
/* eslint-disable no-template-curly-in-string */
import { STATUS } from '@hydrooj/utils/lib/status';
import { SystemError } from './error';
import { run } from './sandbox';
import * as STATUS from './status';
import { parse } from './testlib';
interface CheckResult {
+1 -1
View File
@@ -1,8 +1,8 @@
import { LangConfig } from '@hydrooj/utils/lib/lang';
import { STATUS } from '@hydrooj/utils/lib/status';
import { CompileError } from './error';
import { Execute } from './interface';
import { del, run } from './sandbox';
import * as STATUS from './status';
import { compilerText } from './utils';
export = async function compile(
+4 -4
View File
@@ -8,12 +8,12 @@ import { ObjectID } from 'mongodb';
import PQueue from 'p-queue';
import WebSocket from 'ws';
import { LangConfig } from '@hydrooj/utils/lib/lang';
import { STATUS } from '@hydrooj/utils/lib/status';
import readCases from '../cases';
import { getConfig } from '../config';
import { CompileError, FormatError, SystemError } from '../error';
import judge from '../judge';
import log from '../log';
import { STATUS_COMPILE_ERROR, STATUS_SYSTEM_ERROR } from '../status';
import * as sysinfo from '../sysinfo';
import * as tmpfs from '../tmpfs';
import {
@@ -78,19 +78,19 @@ class JudgeTask {
if (e instanceof CompileError) {
this.next({ compiler_text: compilerText(e.stdout, e.stderr) });
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) {
this.next({ judge_text: 'Testdata configuration incorrect.' });
this.next({ judge_text: { message: e.message, params: e.params } });
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 {
log.error(e);
this.next({ message: { message: e.message, params: e.params || [], ...argv.options.debug ? { stack: e.stack } : {} } });
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 {
+1 -1
View File
@@ -1,13 +1,13 @@
import path from 'path';
import fs from 'fs-extra';
import Queue from 'p-queue';
import { STATUS } from '@hydrooj/utils/lib/status';
import { check, compileChecker } from '../check';
import compile from '../compile';
import { getConfig } from '../config';
import { CompileError, SystemError } from '../error';
import { run } from '../sandbox';
import signals from '../signals';
import * as STATUS from '../status';
import { parseFilename } from '../utils';
const Score = {
+1 -1
View File
@@ -1,12 +1,12 @@
// Not implemented
import path from 'path';
import fs from 'fs-extra';
import { STATUS } from '@hydrooj/utils/lib/status';
import { check, compileChecker } from '../check';
import compile from '../compile';
import { CompileError } from '../error';
import { run } from '../sandbox';
import signals from '../signals';
import * as STATUS from '../status';
import { copyInDir, parseFilename } from '../utils';
export const judge = async (ctx) => {
+1 -1
View File
@@ -1,10 +1,10 @@
import fs from 'fs-extra';
import Queue from 'p-queue';
import { STATUS } from '@hydrooj/utils/lib/status';
import compile from '../compile';
import { getConfig } from '../config';
import { run } from '../sandbox';
import signals from '../signals';
import * as STATUS from '../status';
import { parse } from '../testlib';
import { findFileSync, parseFilename } from '../utils';
+1 -1
View File
@@ -1,10 +1,10 @@
import path from 'path';
import fs from 'fs-extra';
import { STATUS } from '@hydrooj/utils/lib/status';
import compile from '../compile';
import { CompileError } from '../error';
import { run } from '../sandbox';
import signals from '../signals';
import * as STATUS from '../status';
import { compilerText, parseMemoryMB, parseTimeMS } from '../utils';
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({
next, end, config, code,
+2 -2
View File
@@ -1,10 +1,10 @@
import Axios from 'axios';
import cac from 'cac';
import fs from 'fs-extra';
import { STATUS } from '@hydrooj/utils/lib/status';
import { getConfig } from './config';
import { FormatError, SystemError } from './error';
import { Logger } from './log';
import * as STATUS from './status';
import { cmd, parseMemoryMB } from './utils';
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));
} catch (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, {})));
}
+4 -4
View File
@@ -6,12 +6,12 @@ import path from 'path';
import fs from 'fs-extra';
import { noop } from 'lodash';
import { ObjectID } from 'mongodb';
import { STATUS } from '@hydrooj/utils/lib/status';
import { Logger } from 'hydrooj/src/logger';
import * as monitor from 'hydrooj/src/service/monitor';
import readCases from './cases';
import { getConfig } from './config';
import { CompileError, FormatError, SystemError } from './error';
import { STATUS_COMPILE_ERROR, STATUS_SYSTEM_ERROR } from './status';
import * as sysinfo from './sysinfo';
import * as tmpfs from './tmpfs';
import { compilerText, md5 } from './utils';
@@ -207,18 +207,18 @@ async function postInit() {
if (e instanceof CompileError) {
this.next({ compiler_text: compilerText(e.stdout, e.stderr) });
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) {
this.next({ message: { message: e.message, params: e.params } });
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 {
logger.error(e);
this.next({ message: { message: e.message, params: e.params, ...process.env.DEV ? { stack: e.stack } : {} } });
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,
});
}
}
-33
View File
@@ -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',
};
+9 -10
View File
@@ -1,9 +1,9 @@
import * as STATUS from './status';
import { STATUS } from '@hydrooj/utils/lib/status';
export function parse(output: string, fullscore: number) {
let status = STATUS.STATUS_WRONG_ANSWER;
let score = 0;
let message = output;
let message = output.substr(0, 1024);
if (output.startsWith('ok ')) {
status = STATUS.STATUS_ACCEPTED;
score = fullscore;
@@ -13,19 +13,18 @@ export function parse(output: string, fullscore: number) {
message = `PE ${output.split('wrong output format ')[1] || ''}`;
} else if (output.startsWith('partially correct ')) {
message = `PC ${output.split('partially correct ')[1] || ''}`;
const p = +output.split('partially correct (')[1].split(')')[0];
score = Math.floor(fullscore * (p / 200));
let p = +output.split('partially correct (')[1].split(')')[0] || 0;
if (p > 1) p /= 100;
score = Math.floor(fullscore * p);
} else if (output.startsWith('points ')) {
const p = +output.split('points ')[1].split(' ')[0];
if (p === 100) {
let p = +output.split('points ')[1].split(' ')[0] || 0;
if (p > 1) p /= 100;
if (p === 1) {
status = STATUS.STATUS_ACCEPTED;
score = fullscore;
const base = output.split('points ')[1] || '';
message = base.substr(base.indexOf(' '), 1024);
} else {
message = `partially correct ${output.split('points ')[1] || ''}`;
score = Math.floor(fullscore * (p / 100));
}
} else score = Math.floor(fullscore * p);
}
return { status, score, message };
}