import type { AnalysisReport } from './types'; export function formatMarkdown(report: AnalysisReport): string { let md = '# Data Analysis Report\n\n'; md += `**Generated**: ${report.overview.timestamp} \n`; md += `**Processing Time**: ${report.overview.processingTime}ms\n\n`; // Overview md += '## Dataset Overview\n\n'; md += `- **File**: ${report.overview.fileName}\n`; md += `- **Size**: ${report.overview.fileSize}\n`; md += `- **Type**: ${report.overview.fileType}\n`; md += `- **Rows**: ${report.overview.rowCount.toLocaleString()}\n`; md += `- **Columns**: ${report.overview.columnCount}\n`; md += `- **Memory Usage**: ${report.overview.memoryUsage}\n\n`; // Column Analysis md += '## Column Analysis\n\n'; report.columns.forEach(col => { md += `### ${col.name}\n\n`; md += `- **Type**: ${col.dataType}\n`; md += `- **Count**: ${col.count.toLocaleString()}\n`; md += `- **Null**: ${col.nullCount} (${col.nullPercentage}%)\n`; md += `- **Unique**: ${col.uniqueCount} (${col.uniquePercentage}%)\n`; md += `- **Sample**: ${col.sampleValues.join(', ')}\n`; if (col.dataType === 'numeric') { md += '\n**Statistics**:\n\n'; md += `| Metric | Value |\n`; md += `|--------|-------|\n`; md += `| Mean | ${col.mean} |\n`; md += `| Median | ${col.median} |\n`; md += `| Std Dev | ${col.stdDev} |\n`; md += `| Min | ${col.min} |\n`; md += `| Max | ${col.max} |\n`; md += `| Q1 | ${col.q1} |\n`; md += `| Q3 | ${col.q3} |\n`; if (col.outliers && col.outliers.length > 0) { md += `\n**Outliers**: ${col.outliers.length} detected\n`; } } if (col.topValues && col.topValues.length > 0) { md += '\n**Top Values**:\n\n'; md += `| Value | Count | Percentage |\n`; md += `|-------|-------|------------|\n`; col.topValues.forEach(tv => { md += `| ${tv.value} | ${tv.count} | ${tv.percentage}% |\n`; }); } md += '\n'; }); // Correlations if (report.correlationPairs && report.correlationPairs.length > 0) { md += '## Correlation Analysis\n\n'; md += '**Strong Correlations** (|r| > 0.5):\n\n'; md += `| Column 1 | Column 2 | Correlation |\n`; md += `|----------|----------|-------------|\n`; report.correlationPairs.forEach(pair => { md += `| ${pair.col1} | ${pair.col2} | ${pair.correlation} |\n`; }); md += '\n'; } // Data Quality md += '## Data Quality\n\n'; md += `- **Quality Score**: ${report.quality.dataQualityScore}/100\n`; md += `- **Missing Cells**: ${report.quality.missingCells} (${report.quality.missingPercentage}%)\n`; md += `- **Duplicate Rows**: ${report.quality.duplicateRows} (${report.quality.duplicatePercentage}%)\n\n`; if (report.quality.issues.length > 0) { md += '**Issues Found**:\n\n'; report.quality.issues.forEach(issue => { md += `- ${issue}\n`; }); md += '\n'; } // Visualization Recommendations if (report.visualizationRecommendations.length > 0) { md += '## Visualization Recommendations\n\n'; md += `| Column | Chart Type | Reason |\n`; md += `|--------|------------|--------|\n`; report.visualizationRecommendations.forEach(rec => { md += `| ${rec.column} | ${rec.chartType} | ${rec.reason} |\n`; }); md += '\n'; } // Insights if (report.insights.length > 0) { md += '## Key Insights\n\n'; report.insights.forEach((insight, idx) => { md += `${idx + 1}. ${insight}\n`; }); md += '\n'; } md += '---\n\n'; md += '*Generated by skills.md/analyze-data*\n'; return md; } export function formatHTML(report: AnalysisReport): string { return ` Data Analysis Report - ${report.overview.fileName}

📊 Data Analysis Report

Generated: ${report.overview.timestamp} | Processing Time: ${report.overview.processingTime}ms

Dataset Overview

File${report.overview.fileName}
Size${report.overview.fileSize}
Type${report.overview.fileType}
Rows${report.overview.rowCount.toLocaleString()}
Columns${report.overview.columnCount}
Memory${report.overview.memoryUsage}

Data Quality

${report.quality.dataQualityScore}/100
MetricValue
Missing Cells${report.quality.missingCells} (${report.quality.missingPercentage}%)
Duplicate Rows${report.quality.duplicateRows} (${report.quality.duplicatePercentage}%)
${report.quality.issues.length > 0 ? `

Issues Found

${report.quality.issues.map(issue => `
${issue}
`).join('')} ` : ''}

Column Analysis

${report.columns.map(col => `

${col.name} ${col.dataType}

${col.dataType === 'numeric' ? ` ` : ''}
Count${col.count.toLocaleString()}
Null${col.nullCount} (${col.nullPercentage}%)
Unique${col.uniqueCount} (${col.uniquePercentage}%)
Mean${col.mean}
Median${col.median}
Std Dev${col.stdDev}
Min / Max${col.min} / ${col.max}
Q1 / Q3${col.q1} / ${col.q3}
`).join('')} ${report.correlationPairs && report.correlationPairs.length > 0 ? `

Correlation Analysis

${report.correlationPairs.map(pair => ` `).join('')}
Column 1Column 2Correlation
${pair.col1}${pair.col2}${pair.correlation}
` : ''} ${report.visualizationRecommendations.length > 0 ? `

Visualization Recommendations

${report.visualizationRecommendations.map(rec => ` `).join('')}
ColumnChart TypeReason
${rec.column}${rec.chartType}${rec.reason}
` : ''} ${report.insights.length > 0 ? `

Key Insights

${report.insights.map(insight => `
${insight}
`).join('')} ` : ''}
`; } // ============================================================================