import { useState } from 'react'; import { BarChart, Bar, PieChart, Pie, Cell, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts'; import { TrendingUp, Users, Award, MapPin, AlertTriangle, Lightbulb, Target, X, HelpCircle, Book } from 'lucide-react'; function AnalysisDashboard({ data }) { const { analysis, executiveSummary } = data; const [selectedTheme, setSelectedTheme] = useState(null); const [showModal, setShowModal] = useState(false); const [showDocs, setShowDocs] = useState(false); // Prepare chart data const themeData = Object.entries(analysis.themeDistribution || {}).map(([name, value]) => ({ name, value })); const stateData = Object.entries(analysis.stateWiseCoverage || {}) .map(([name, value]) => ({ name, value })) .sort((a, b) => b.value - a.value) .slice(0, 8); const COLORS = ['#667eea', '#764ba2', '#f093fb', '#4facfe', '#43e97b', '#fa709a', '#fee140', '#30cfd0']; // Get states for selected theme from analysis data const getThemeDetails = (themeName) => { const themeStates = analysis.themeStateMapping?.[themeName] || {}; const statesWithCounts = Object.entries(themeStates) .map(([state, count]) => ({ state, count })) .sort((a, b) => b.count - a.count); return { theme: themeName, count: analysis.themeDistribution[themeName], states: statesWithCounts }; }; const handlePieClick = (data) => { const themeDetails = getThemeDetails(data.name); setSelectedTheme(themeDetails); setShowModal(true); }; return (
{/* Floating Help Button */} {/* Documentation Modal */} {showDocs && (
setShowDocs(false)} >
e.stopPropagation()} > {/* Close Button */} {/* Documentation Content */}

📚 System Documentation

Complete guide on how the RAG Document Analysis System works

{/* Quick Links */}

🚀 Quick Start

  1. Upload CSV/Excel file with training data
  2. Wait for analysis (automatic, 100% FREE)
  3. View dashboard with insights and charts
  4. Click pie chart to see theme details
  5. Download PDF report for official use
{/* System Overview */}

📋 System Overview

This is an AI-powered Training Data Analysis System designed for disaster management training programs. It analyzes CSV/Excel files containing training records and generates comprehensive insights, gap analysis, and professional PDF reports.

{/* Key Features */}

✨ Key Features

{[ { icon: '📊', title: 'Interactive Charts', desc: 'Click pie chart to see theme-wise state details' }, { icon: '📈', title: 'Real-time Analysis', desc: 'Instant insights from your training data' }, { icon: '📄', title: 'PDF Reports', desc: 'Government-format professional reports' }, { icon: '🆓', title: '100% FREE', desc: 'No API keys or subscriptions needed' }, { icon: '⚡', title: 'Fast Processing', desc: 'Analyze thousands of records in seconds' }, { icon: '🎯', title: 'Gap Analysis', desc: 'Identify underserved states and themes' } ].map((feature, idx) => (
{feature.icon}

{feature.title}

{feature.desc}

))}
{/* How It Works */}

🔄 How It Works

{[ { step: '1', title: 'File Upload', desc: 'Drag & drop or select CSV/Excel file' }, { step: '2', title: 'Data Parsing', desc: 'System extracts training records from file' }, { step: '3', title: 'AI Analysis', desc: 'Local analysis calculates metrics and insights' }, { step: '4', title: 'Dashboard Display', desc: 'Interactive charts and insights shown' }, { step: '5', title: 'PDF Generation', desc: 'Professional report created automatically' } ].map((item, idx) => (
{item.step}

{item.title}

{item.desc}

))}
{/* Dashboard Guide */}

🎯 Dashboard Guide

📊 Interactive Pie Chart

  • Click any theme to see detailed breakdown
  • Popup shows states covered for that disaster type
  • Each state displays training count badge
  • Data is theme-specific (Flood shows only flood-affected states)

📍 State Coverage Chart

  • Shows top 8 states by training count
  • Sorted from highest to lowest
  • Hover to see exact numbers

⚠️ Gap Analysis

  • Underserved States: States with less than 5 trainings
  • Underserved Themes: Disaster types needing more coverage
  • Critical Gaps: Important areas requiring immediate attention
{/* Technical Details */}

⚙️ Technical Details

Frontend

  • React 18
  • Vite
  • Recharts
  • Lucide Icons

Backend

  • Node.js
  • Express
  • PDFKit
  • CSV Parser
{/* Support */}

💡 Need Help?

Check the HOW_IT_WORKS.md file in the project root for detailed technical documentation.

)} {/* Theme Details Modal */} {showModal && selectedTheme && (
setShowModal(false)} >
e.stopPropagation()} >

🌊 {selectedTheme.theme}

Total Trainings: {selectedTheme.count}

📍 States Covered ({selectedTheme.states.length}):

{selectedTheme.states.length > 0 ? (
{selectedTheme.states.map((item, idx) => (
{item.state} {item.count}
))}
) : (

No state data available for this theme.

)}

💡 Insight: This disaster theme has been covered across multiple states, indicating comprehensive training coverage for {selectedTheme.theme.toLowerCase()} preparedness.

)} {/* Rest of the dashboard content remains the same... */} {/* Top Stats - Horizontal */}

Total Trainings

{analysis.totalTrainings || 0}

Participants

{analysis.totalParticipants?.toLocaleString() || 0}

Completion

{analysis.averageCompletionRate || 'N/A'}

States

{Object.keys(analysis.stateWiseCoverage || {}).length}

{/* Main Layout: Left (Charts) + Right (Business Insights) */}
{/* Left Side - Charts & Gap Analysis */}
{/* Charts Grid */}
{/* Theme Distribution - INTERACTIVE */} {themeData.length > 0 && (

📊 Theme Distribution

Click on any theme to see details

`${name.substring(0, 8)} ${(percent * 100).toFixed(0)}%`} outerRadius={80} fill="#8884d8" dataKey="value" onClick={handlePieClick} style={{ cursor: 'pointer' }} > {themeData.map((entry, index) => ( ))}
)} {/* State Coverage */} {stateData.length > 0 && (

📍 Top States

)}
{/* Gap Analysis */} {analysis.gapAnalysis && (

Gap Analysis

{analysis.gapAnalysis.underservedStates && analysis.gapAnalysis.underservedStates.length > 0 && (

Underserved States

{analysis.gapAnalysis.underservedStates.slice(0, 6).map((state, idx) => ( {state} ))}
)} {analysis.gapAnalysis.underservedThemes && analysis.gapAnalysis.underservedThemes.length > 0 && (

Underserved Themes

{analysis.gapAnalysis.underservedThemes.map((theme, idx) => ( {theme} ))}
)} {analysis.gapAnalysis.criticalGaps && analysis.gapAnalysis.criticalGaps.length > 0 && (

Critical Gaps

    {analysis.gapAnalysis.criticalGaps.slice(0, 3).map((gap, idx) => (
  • {gap}
  • ))}
)}
)}
{/* Right Side - Business Insights */}
{analysis.keyInsights && analysis.keyInsights.length > 0 && (

Business Insights

{analysis.keyInsights.map((insight, idx) => (
{insight}
))}
)}
{/* Recommendations - Full Width */} {analysis.recommendations && analysis.recommendations.length > 0 && (

Recommendations

{analysis.recommendations.map((recommendation, idx) => (
{ e.currentTarget.style.transform = 'translateY(-4px)'; e.currentTarget.style.boxShadow = '0 4px 12px rgba(67, 233, 123, 0.2)'; }} onMouseLeave={(e) => { e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = 'none'; }} > {recommendation}
))}
)}
); } export default AnalysisDashboard;