From d71708ec5b2d820e9517c2c2afea202d1fabe6e8 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 3 Feb 2023 13:53:36 +0800 Subject: [PATCH] feat(remote_judger/luogu): judge details --- remote_judger/src/providers/luogu.ts | 55 +++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/remote_judger/src/providers/luogu.ts b/remote_judger/src/providers/luogu.ts index 237b291..11902cb 100644 --- a/remote_judger/src/providers/luogu.ts +++ b/remote_judger/src/providers/luogu.ts @@ -5,6 +5,7 @@ import Logger from '../utils/logger'; import { IBasicProvider, RemoteAccount, USER_AGENT } from '../interface'; import sleep from '../utils/sleep'; import flattenDeep from 'lodash.flattendeep'; +import htmlspecialchars from '../utils/htmlspecialchars'; proxy(superagent); const logger = new Logger('remote/luogu'); @@ -75,6 +76,18 @@ const LANGS_MAP = { }, }; +function buildLuoguTestCaseInfoBlock(test) { + let res = ''; + + res += ``; + res += `${htmlspecialchars(test.description || '')}`; + res += ''; + + return res; +} + export default class LuoguProvider implements IBasicProvider { constructor(public account: RemoteAccount) { if (account.cookie) this.cookie = account.cookie; @@ -255,7 +268,7 @@ export default class LuoguProvider implements IBasicProvider { ) { return await end({ error: true, - id: 'R' + id, + id: `R${id}`, status: 'Compile Error', message: data.detail.compileResult.message, }); @@ -278,15 +291,47 @@ export default class LuoguProvider implements IBasicProvider { logger.info('RecordID:', id, 'done'); + const status = STATUS_MAP[data.status]; + let details = ''; + + details += `REMOTE_SUBMISSION_ID = ${id}\nVERDICT = ${status}`; + + if (data.detail.judgeResult.subtasks.length === 1) { + details += Object.entries( + data.detail.judgeResult.subtasks[0].testCases + ) + .map(o => o[1]) + .map(buildLuoguTestCaseInfoBlock) + .join('\n'); + } else { + details += Object.entries(data.detail.judgeResult.subtasks) + .map(o => o[1]) + .map( + (subtask: any, index) => + `${Object.entries( + subtask.testCases + ) + .map(o => o[1]) + .map(buildLuoguTestCaseInfoBlock) + .join('\n')}` + ) + .join('\n'); + } + return await end({ - id: 'R' + id, - status: STATUS_MAP[data.status], + id: `R${id}`, + status, score: - STATUS_MAP[data.status] === 'Accepted' + status === 'Accepted' ? 100 : (data.score / data.problem.fullScore) * 100, time: data.time, memory: data.memory, + details: `
${details}
`, }); } catch (e) { logger.error(e); @@ -297,7 +342,7 @@ export default class LuoguProvider implements IBasicProvider { return await end({ error: true, - id: 'R' + id, + id: `R${id}`, status: 'Judgment Failed', message: 'Failed to fetch submission details.', });