From 170638a5fad456d924f3f5287e8f3b8636ac838b Mon Sep 17 00:00:00 2001 From: overcuriousity Date: Sun, 17 Aug 2025 10:52:48 +0200 Subject: [PATCH] update audit trail detail level --- src/components/AIQueryInterface.astro | 144 +++++++++++++++++++++++--- 1 file changed, 130 insertions(+), 14 deletions(-) diff --git a/src/components/AIQueryInterface.astro b/src/components/AIQueryInterface.astro index 01a934b..5e3f1b2 100644 --- a/src/components/AIQueryInterface.astro +++ b/src/components/AIQueryInterface.astro @@ -979,7 +979,7 @@ class AIQueryInterface { -
+
- ${stats.qualityMetrics.aiTransparency >= 80 ? ` -
✅ Hohe Transparenz
+ ${stats.keyInsights && stats.keyInsights.length > 0 ? ` +
✅ Erkenntnisse
+
    + ${stats.keyInsights.map(insight => `
  • ${insight}
  • `).join('')} +
+ ` : ''} + + ${stats.potentialIssues && stats.potentialIssues.length > 0 ? ` +
⚠️ Hinweise
+
    + ${stats.potentialIssues.map(issue => `
  • ${issue}
  • `).join('')} +
+ ` : ''} + + ${(!stats.keyInsights || stats.keyInsights.length === 0) && (!stats.potentialIssues || stats.potentialIssues.length === 0) ? ` +
📊 Analyse-Details
  • ${stats.qualityMetrics.aiTransparency}% der Entscheidungen mit nachvollziehbarer Begründung
  • -
  • Durchschnittliche Verarbeitungszeit: ${formatDuration(stats.qualityMetrics.avgProcessingTime)}
  • +
  • Analysequalität: ${this.getQualityDisplayText(stats.analysisQuality)}
- ` : ` -
⚠️ Transparenz-Hinweise
-
    -
  • Nur ${stats.qualityMetrics.aiTransparency}% der Entscheidungen vollständig dokumentiert
  • -
  • Einige KI-Entscheidungen ohne detaillierte Begründung
  • -
- `} + ` : ''}
@@ -1068,6 +1076,17 @@ class AIQueryInterface { } } + getQualityDisplayText(analysisQuality) { + const qualityMap = { + 'excellent': 'Ausgezeichnet', + 'good': 'Gut', + 'fair': 'Zufriedenstellend', + 'poor': 'Verbesserungswürdig', + 'unknown': 'Unbekannt' + }; + return qualityMap[analysisQuality] || 'Unbekannt'; + } + setupUnifiedUploadSystem() { const previousUploadInput = document.getElementById('upload-previous-analysis'); if (previousUploadInput) { @@ -1113,13 +1132,20 @@ class AIQueryInterface { totalTime: 0, avgConfidence: 0, stepCount: 0, + highConfidenceSteps: 0, + lowConfidenceSteps: 0, + phaseBreakdown: {}, aiDecisionCount: 0, embeddingsUsageCount: 0, toolSelectionCount: 0, qualityMetrics: { avgProcessingTime: 0, + confidenceDistribution: { high: 0, medium: 0, low: 0 }, aiTransparency: 0 - } + }, + analysisQuality: 'unknown', + keyInsights: [], + potentialIssues: [] }; } @@ -1129,25 +1155,115 @@ class AIQueryInterface { ? Math.round(validConfidenceEntries.reduce((sum, entry) => sum + entry.confidence, 0) / validConfidenceEntries.length) : 0; + const highConfidenceSteps = auditTrail.filter(entry => (entry.confidence || 0) >= 80).length; + const lowConfidenceSteps = auditTrail.filter(entry => (entry.confidence || 0) < 60).length; + const mediumConfidenceSteps = auditTrail.length - highConfidenceSteps - lowConfidenceSteps; + + // Enhanced metrics const aiDecisionCount = auditTrail.filter(entry => entry.action === 'ai-decision').length; const embeddingsUsageCount = auditTrail.filter(entry => entry.metadata?.embeddingsUsed).length; const toolSelectionCount = auditTrail.filter(entry => entry.action === 'selection-decision').length; - + + // Phase breakdown + const phaseBreakdown = {}; + auditTrail.forEach(entry => { + const phase = entry.phase || 'unknown'; + if (!phaseBreakdown[phase]) { + phaseBreakdown[phase] = { count: 0, avgConfidence: 0, totalTime: 0 }; + } + + phaseBreakdown[phase].count++; + phaseBreakdown[phase].totalTime += entry.processingTimeMs || 0; + }); + + // Calculate average confidence per phase + Object.keys(phaseBreakdown).forEach(phase => { + const phaseEntries = auditTrail.filter(entry => entry.phase === phase); + const validEntries = phaseEntries.filter(entry => typeof entry.confidence === 'number'); + + if (validEntries.length > 0) { + phaseBreakdown[phase].avgConfidence = Math.round( + validEntries.reduce((sum, entry) => sum + entry.confidence, 0) / validEntries.length + ); + } + }); + const avgProcessingTime = auditTrail.length > 0 ? totalTime / auditTrail.length : 0; const aiTransparency = auditTrail.length > 0 ? (auditTrail.filter(entry => entry.metadata?.aiPrompt || entry.metadata?.reasoning).length / auditTrail.length) * 100 : 0; + // RESTORED: Intelligent Analysis Quality Assessment + let analysisQuality; + if (avgConfidence >= 85 && lowConfidenceSteps === 0) { + analysisQuality = 'excellent'; + } else if (avgConfidence >= 70 && lowConfidenceSteps <= 1) { + analysisQuality = 'good'; + } else if (avgConfidence >= 60 && lowConfidenceSteps <= 3) { + analysisQuality = 'fair'; + } else { + analysisQuality = 'poor'; + } + + // RESTORED: Intelligent Insights Generation + const keyInsights = []; + const embeddingsUsed = auditTrail.some(e => e.metadata?.embeddingsUsed); + if (embeddingsUsed) { + keyInsights.push('Semantische Suche wurde erfolgreich eingesetzt'); + } + + const toolSelectionEntries = auditTrail.filter(e => e.action === 'selection-decision'); + if (toolSelectionEntries.length > 0) { + const avgSelectionConfidence = toolSelectionEntries.reduce((sum, e) => sum + (e.confidence || 0), 0) / toolSelectionEntries.length; + if (avgSelectionConfidence >= 80) { + keyInsights.push('Hohe Konfidenz bei der Tool-Auswahl'); + } + } + + if (aiTransparency >= 90) { + keyInsights.push('Sehr hohe Transparenz der KI-Entscheidungen'); + } + + if (highConfidenceSteps > auditTrail.length * 0.7) { + keyInsights.push('Mehrheit der Analyseschritte mit hoher Sicherheit'); + } + + // RESTORED: Automatic Issue Detection (excluding processing time warnings) + const potentialIssues = []; + if (lowConfidenceSteps > 2) { + potentialIssues.push(`${lowConfidenceSteps} Analyseschritte mit niedriger Konfidenz`); + } + + if (aiTransparency < 50) { + potentialIssues.push('Geringe Transparenz der KI-Entscheidungsfindung'); + } + + const failedAiDecisions = auditTrail.filter(e => e.action === 'ai-decision' && e.confidence < 50).length; + if (failedAiDecisions > 0) { + potentialIssues.push(`${failedAiDecisions} KI-Entscheidungen mit sehr niedriger Konfidenz`); + } + return { totalTime, avgConfidence, stepCount: auditTrail.length, + highConfidenceSteps, + lowConfidenceSteps, + phaseBreakdown, aiDecisionCount, embeddingsUsageCount, toolSelectionCount, qualityMetrics: { avgProcessingTime, + confidenceDistribution: { + high: highConfidenceSteps, + medium: mediumConfidenceSteps, + low: lowConfidenceSteps + }, aiTransparency: Math.round(aiTransparency) - } + }, + analysisQuality, + keyInsights, + potentialIssues }; }