feat(remote_judger): judge details for codeforces
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2023-01-28 18:28:02 +08:00
parent e9abdd53ae
commit 50efed50fd
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
5 changed files with 113 additions and 9 deletions

View File

@ -9,6 +9,7 @@
"version": "0.0.0",
"license": "AGPL-3.0",
"dependencies": {
"crlf-normalize": "^1.0.18",
"fs-extra": "^11.1.0",
"jsdom": "^21.0.0",
"math-sum": "^2.0.0",
@ -80,8 +81,7 @@
"node_modules/@types/node": {
"version": "18.11.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
"integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==",
"dev": true
"integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA=="
},
"node_modules/@types/superagent": {
"version": "4.1.16",
@ -230,6 +230,14 @@
"resolved": "https://registry.npmjs.org/cosmokit/-/cosmokit-1.4.0.tgz",
"integrity": "sha512-9Y5epwkPxnWDSjweuWoFATY8GKg9N1/r/3wL32Cjs7FIvo0S9syyY39xmNKq7+SZjbw+9bZUSbeQSbJaqufV3Q=="
},
"node_modules/crlf-normalize": {
"version": "1.0.18",
"resolved": "https://registry.npmjs.org/crlf-normalize/-/crlf-normalize-1.0.18.tgz",
"integrity": "sha512-bBPJTekqhw/yUgHvHrOT2QBb6gJt/gNDx++GKkSYaBIepeEiLIezouV8xgDFTL3yRMpK7wOYC9a8xvY7bFQCLg==",
"dependencies": {
"ts-type": ">=2"
}
},
"node_modules/cssom": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/cssom/-/cssom-0.5.0.tgz",
@ -1298,6 +1306,25 @@
"node": ">=12"
}
},
"node_modules/ts-toolbelt": {
"version": "9.6.0",
"resolved": "https://registry.npmjs.org/ts-toolbelt/-/ts-toolbelt-9.6.0.tgz",
"integrity": "sha512-nsZd8ZeNUzukXPlJmTBwUAuABDe/9qtVDelJeT/qW0ow3ZS3BsQJtNkan1802aM9Uf68/Y8ljw86Hu0h5IUW3w==",
"peer": true
},
"node_modules/ts-type": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/ts-type/-/ts-type-3.0.1.tgz",
"integrity": "sha512-cleRydCkBGBFQ4KAvLH0ARIkciduS745prkGVVxPGvcRGhMMoSJUB7gNR1ByKhFTEYrYRg2CsMRGYnqp+6op+g==",
"dependencies": {
"@types/node": "*",
"tslib": ">=2",
"typedarray-dts": "^1.0.0"
},
"peerDependencies": {
"ts-toolbelt": "^9.6.0"
}
},
"node_modules/tslib": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz",
@ -1314,6 +1341,11 @@
"node": ">= 0.8.0"
}
},
"node_modules/typedarray-dts": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/typedarray-dts/-/typedarray-dts-1.0.0.tgz",
"integrity": "sha512-Ka0DBegjuV9IPYFT1h0Qqk5U4pccebNIJCGl8C5uU7xtOs+jpJvKGAY4fHGK25hTmXZOEUl9Cnsg5cS6K/b5DA=="
},
"node_modules/typescript": {
"version": "4.9.4",
"dev": true,
@ -1538,8 +1570,7 @@
"@types/node": {
"version": "18.11.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
"integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==",
"dev": true
"integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA=="
},
"@types/superagent": {
"version": "4.1.16",
@ -1664,6 +1695,14 @@
"resolved": "https://registry.npmjs.org/cosmokit/-/cosmokit-1.4.0.tgz",
"integrity": "sha512-9Y5epwkPxnWDSjweuWoFATY8GKg9N1/r/3wL32Cjs7FIvo0S9syyY39xmNKq7+SZjbw+9bZUSbeQSbJaqufV3Q=="
},
"crlf-normalize": {
"version": "1.0.18",
"resolved": "https://registry.npmjs.org/crlf-normalize/-/crlf-normalize-1.0.18.tgz",
"integrity": "sha512-bBPJTekqhw/yUgHvHrOT2QBb6gJt/gNDx++GKkSYaBIepeEiLIezouV8xgDFTL3yRMpK7wOYC9a8xvY7bFQCLg==",
"requires": {
"ts-type": ">=2"
}
},
"cssom": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/cssom/-/cssom-0.5.0.tgz",
@ -2470,6 +2509,22 @@
"punycode": "^2.1.1"
}
},
"ts-toolbelt": {
"version": "9.6.0",
"resolved": "https://registry.npmjs.org/ts-toolbelt/-/ts-toolbelt-9.6.0.tgz",
"integrity": "sha512-nsZd8ZeNUzukXPlJmTBwUAuABDe/9qtVDelJeT/qW0ow3ZS3BsQJtNkan1802aM9Uf68/Y8ljw86Hu0h5IUW3w==",
"peer": true
},
"ts-type": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/ts-type/-/ts-type-3.0.1.tgz",
"integrity": "sha512-cleRydCkBGBFQ4KAvLH0ARIkciduS745prkGVVxPGvcRGhMMoSJUB7gNR1ByKhFTEYrYRg2CsMRGYnqp+6op+g==",
"requires": {
"@types/node": "*",
"tslib": ">=2",
"typedarray-dts": "^1.0.0"
}
},
"tslib": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz",
@ -2483,6 +2538,11 @@
"prelude-ls": "~1.1.2"
}
},
"typedarray-dts": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/typedarray-dts/-/typedarray-dts-1.0.0.tgz",
"integrity": "sha512-Ka0DBegjuV9IPYFT1h0Qqk5U4pccebNIJCGl8C5uU7xtOs+jpJvKGAY4fHGK25hTmXZOEUl9Cnsg5cS6K/b5DA=="
},
"typescript": {
"version": "4.9.4",
"dev": true

View File

@ -12,6 +12,7 @@
"license": "AGPL-3.0",
"private": true,
"dependencies": {
"crlf-normalize": "^1.0.18",
"fs-extra": "^11.1.0",
"jsdom": "^21.0.0",
"math-sum": "^2.0.0",

View File

@ -1,6 +1,7 @@
import { JSDOM } from 'jsdom';
import superagent from 'superagent';
import proxy from 'superagent-proxy';
import { crlf, LF } from 'crlf-normalize';
import sleep from '../utils/sleep';
import mathSum from 'math-sum';
import { IBasicProvider, RemoteAccount, USER_AGENT } from '../interface';
@ -313,9 +314,9 @@ export default class CodeforcesProvider implements IBasicProvider {
if (body.compilationError === 'true') {
return await end({
id,
error: 1,
error: true,
status: 'Compile Error',
message: body['checkerStdoutAndStderr#1'],
message: crlf(body['checkerStdoutAndStderr#1'], LF),
});
}
const time = mathSum(
@ -331,16 +332,52 @@ export default class CodeforcesProvider implements IBasicProvider {
) / 1024;
await next({ test_id: body.testCount });
if (body.waiting === 'true') continue;
const testCount = +body.testCount;
const status =
VERDICT[
Object.keys(VERDICT).find(k => normalize(body.verdict).includes(k))
];
let tests: string[] = [];
for (let i = 1; i <= testCount; i++) {
let test_info = '';
let info_text =
VERDICT[
Object.keys(VERDICT).find(k =>
normalize(body[`verdict#${i}`]).includes(k)
)
];
test_info += `<test num="${i}" info="${info_text}" time="${
body[`timeConsumed#${i}`]
}" memory="${body[`memoryConsumed#${i}`]}">`;
const parse = (id: string) => crlf(body[id], LF);
test_info += `<in>${parse(`input#${i}`)}</in>\n`;
test_info += `<out>${parse(`output#${i}`)}</out>\n`;
test_info += `<ans>${parse(`answer#${i}`)}</ans>\n`;
test_info += `<res>${parse(`checkerStdoutAndStderr#${i}`)}</res>\n`;
test_info += '</test>';
tests.push(test_info);
}
const details =
'<div>' +
`<info-block>REMOTE_SUBMISSION_ID = ${id}\nVERDICT = ${status}</info-block>` +
`<tests>${tests.join('\n')}</tests>` +
'</div>';
return await end({
id,
status,
score: status === 'Accepted' ? 100 : 0,
time,
memory,
details,
});
}
}

View File

@ -67,10 +67,11 @@ class AccountService {
time: payload.time,
memory: payload.memory,
details:
payload.details ||
'<div>' +
`<info-block>ID = ${payload.id || 'None'}</info-block>` +
`<info-block>VERDICT = ${payload.status}</info-block>` +
'</div>',
`<info-block>ID = ${payload.id || 'None'}</info-block>` +
`<info-block>VERDICT = ${payload.status}</info-block>` +
'</div>',
}),
judge_time,
});

View File

@ -664,6 +664,11 @@ class JudgmentDetailsPrinter {
echo '<pre class="bg-light p-3 rounded">', "\n";
$this->_print_c($node);
echo "\n</pre>";
} elseif ($node->nodeName == 'ans') {
echo '<h4 class="fs-6"><span>answer: </span></h4>';
echo '<pre class="bg-light p-3 rounded">', "\n";
$this->_print_c($node);
echo "\n</pre>";
} elseif ($node->nodeName == 'res') {
echo '<h4 class="fs-6"><span>result: </span></h4>';
echo '<pre class="bg-light p-3 rounded">', "\n";