From 18a81ae0308ee048e22d8ef20980c5177fff781e Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Thu, 26 Mar 2026 09:47:25 +0800 Subject: [PATCH] fix(ui): improve execution time extraction in report analysis dialog Enhanced value extraction with multi-pattern regex approach to handle various markdown table formats. Improved parseDurationToSeconds error handling for edge cases. Added debug logging for failed extractions. Co-Authored-By: Claude Sonnet 4.6 --- .../src/components/ReportAnalysisDialog.tsx | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/components/ReportAnalysisDialog.tsx b/src/renderer/src/components/ReportAnalysisDialog.tsx index 6ee64b7..7a7b07e 100644 --- a/src/renderer/src/components/ReportAnalysisDialog.tsx +++ b/src/renderer/src/components/ReportAnalysisDialog.tsx @@ -82,16 +82,24 @@ export const ReportAnalysisDialog: React.FC = ({ ) const parseDurationToSeconds = (durationStr: string): number => { - // Expected format: "X分Y秒" or similar + // Handle empty or zero case + if (!durationStr || durationStr === '0秒' || durationStr === '0分0秒') { + return 0 + } + + // Remove any remaining backticks + const cleanStr = durationStr.replace(/\`/g, '').trim() + let totalSeconds = 0 - const minutesMatch = durationStr.match(/(\d+)分/) + const minutesMatch = cleanStr.match(/(\d+)分/) if (minutesMatch) { totalSeconds += parseInt(minutesMatch[1], 10) * 60 } - const secondsMatch = durationStr.match(/(\d+)秒/) + const secondsMatch = cleanStr.match(/(\d+)秒/) if (secondsMatch) { totalSeconds += parseInt(secondsMatch[1], 10) } + return totalSeconds } @@ -136,9 +144,26 @@ export const ReportAnalysisDialog: React.FC = ({ // Regex to extract values from the markdown table const extractValue = (key: string): string | null => { - const regex = new RegExp(`\\|\\s*\\*\\*${key}\\*\\*\\s*\\|\\s*\`([^\`]+)\`\\s*\\|`) - const match = content.match(regex) - return match ? match[1].trim() : null + // Try multiple patterns in order of specificity + const patterns = [ + // Pattern 1: Standard format with backticks + new RegExp(`\\|\\s*\\*\\*${key}\\*\\*\\s*\\|\\s*\`([^\`]+)\`\\s*\\|`), + // Pattern 2: Without backticks (fallback for older formats) + new RegExp(`\\|\\s*\\*\\*${key}\\*\\*\\s*\\|\\s*([^\\|\\s]+(?:\\s+[^\\|\\s]+)*)\\s*\\|`), + // Pattern 3: More relaxed - any content between pipes + new RegExp(`\\|\\s*\\*\\*${key}\\*\\*\\s*\\|\\s*(.+?)\\s*\\|`) + ] + + for (const pattern of patterns) { + const match = content.match(pattern) + if (match && match[1]) { + const value = match[1].trim() + // Remove backticks if they're still present + return value.replace(/\`/g, '') + } + } + + return null } const execTimeStr = extractValue('执行时间') @@ -150,6 +175,9 @@ export const ReportAnalysisDialog: React.FC = ({ const retriedOrders = parseInt(extractValue('重试订单数') || '0', 10) const successfulRetries = parseInt(extractValue('成功重试数') || '0', 10) const executionTimeStr = extractValue('执行耗时') || '0秒' + if (executionTimeStr === '0秒') { + console.warn('Failed to extract execution time from report:', report.key) + } const executionTimeSecs = parseDurationToSeconds(executionTimeStr)