Spaces:
Running
Running
File size: 40,614 Bytes
d5f9597 5da0ec4 d5f9597 a841e63 d5f9597 a841e63 d5f9597 a841e63 d5f9597 5da0ec4 d5f9597 5da0ec4 d5f9597 5da0ec4 d5f9597 a841e63 d5f9597 a841e63 d5f9597 a841e63 d5f9597 71845a4 d5f9597 71845a4 d5f9597 71845a4 d5f9597 71845a4 d5f9597 71845a4 a841e63 71845a4 d5f9597 a841e63 d5f9597 71845a4 d5f9597 71845a4 d5f9597 71845a4 4073c26 71845a4 4073c26 71845a4 4073c26 71845a4 4073c26 71845a4 4073c26 5da0ec4 4073c26 71845a4 4073c26 71845a4 4073c26 71845a4 5da0ec4 71845a4 4073c26 71845a4 4073c26 71845a4 4073c26 71845a4 5da0ec4 71845a4 4073c26 71845a4 4073c26 71845a4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 71845a4 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 5da0ec4 4073c26 71845a4 d5f9597 71845a4 d5f9597 5da0ec4 71845a4 d5f9597 5da0ec4 71845a4 d5f9597 5da0ec4 71845a4 d5f9597 5da0ec4 71845a4 d5f9597 71845a4 4073c26 d5f9597 770984b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Excel Wizard Analyzer</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/xlsx/dist/xlsx.full.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<style>
.dropzone {
border: 2px dashed #94a3b8;
border-radius: 0.5rem;
transition: all 0.3s ease;
}
.dropzone-active {
border-color: #6366f1;
background-color: #e0e7ff;
}
#dataTable {
overflow-x: auto;
}
.error-message {
animation: shake 0.5s;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
20%, 60% { transform: translateX(-5px); }
40%, 80% { transform: translateX(5px); }
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-12">
<!-- Header -->
<header class="text-center mb-12">
<h1 class="text-4xl font-bold text-indigo-700 mb-2">Excel Wizard Analyzer <span class="text-purple-500">🔮</span></h1>
<p class="text-lg text-gray-600">Upload your Excel file and let the magic happen!</p>
</header>
<!-- Main Content -->
<div class="max-w-4xl mx-auto bg-white rounded-xl shadow-md overflow-hidden p-6">
<!-- File Drop Zone -->
<div id="dropzone" class="dropzone p-8 text-center cursor-pointer mb-8">
<div class="flex flex-col items-center justify-center">
<i data-feather="upload" class="w-12 h-12 text-indigo-500 mb-4"></i>
<h2 class="text-xl font-semibold text-gray-700 mb-2">Drag & Drop your Excel file here</h2>
<p class="text-gray-500 mb-4">or click to browse files</p>
<input type="file" id="fileInput" accept=".xlsx, .xls, .csv" class="hidden" />
<button id="browseBtn" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition">
Browse Files
</button>
</div>
</div>
<!-- Error Message -->
<div id="errorMessage" class="hidden bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-8">
<strong class="font-bold">Oops!</strong>
<span id="errorText" class="block sm:inline">Something went wrong.</span>
<span class="absolute top-0 bottom-0 right-0 px-4 py-3">
<i data-feather="x" class="cursor-pointer" onclick="document.getElementById('errorMessage').classList.add('hidden')"></i>
</span>
</div>
<!-- File Info -->
<div id="fileInfo" class="hidden mb-8 p-4 bg-blue-50 rounded-lg">
<div class="flex items-center">
<div class="flex-shrink-0">
<i data-feather="file-text" class="w-6 h-6 text-blue-600"></i>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-blue-800" id="fileName">File: example.xlsx</h3>
<div class="mt-1 text-sm text-blue-700">
<p id="fileDetails">Size: 2.5MB • Sheets: 3</p>
</div>
</div>
<div class="ml-auto">
<button onclick="resetFile()" class="text-blue-600 hover:text-blue-800 text-sm font-medium">
Change File
</button>
</div>
</div>
</div>
<!-- Analysis Options -->
<div id="analysisOptions" class="hidden mb-8">
<h3 class="text-lg font-medium text-gray-700 mb-4">Analysis Options</h3>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<button id="analyzeBtn" class="px-4 py-3 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition flex items-center justify-center">
<i data-feather="activity" class="mr-2"></i> Analyze Data
</button>
<button id="previewBtn" class="px-4 py-3 bg-white border border-indigo-600 text-indigo-600 rounded-lg hover:bg-indigo-50 transition flex items-center justify-center">
<i data-feather="eye" class="mr-2"></i> Preview Data
</button>
<button id="visualizeBtn" class="px-4 py-3 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition flex items-center justify-center">
<i data-feather="image" class="mr-2"></i> Visualize Data
</button>
</div>
</div>
<!-- Loading Indicator -->
<div id="loadingIndicator" class="hidden flex flex-col items-center justify-center py-8">
<div class="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-indigo-500 mb-4"></div>
<p class="text-gray-600">Analyzing your file...</p>
</div>
<!-- Results Section -->
<div id="resultsSection" class="hidden">
<h3 class="text-lg font-medium text-gray-700 mb-4">Analysis Results</h3>
<div class="mb-6">
<div class="flex items-center mb-2">
<i data-feather="info" class="w-5 h-5 text-indigo-500 mr-2"></i>
<h4 class="font-medium">File Summary</h4>
</div>
<div id="fileSummary" class="bg-gray-50 p-4 rounded-lg">
<!-- Summary will be inserted here -->
</div>
</div>
<div class="mb-6">
<div class="flex items-center justify-between mb-4">
<div class="flex items-center">
<i data-feather="bar-chart-2" class="w-5 h-5 text-indigo-500 mr-2"></i>
<h4 class="font-medium">Data Visualizations</h4>
</div>
<div class="flex space-x-2">
<select id="chartType" class="text-sm border rounded px-2 py-1">
<option value="bar">Bar Chart</option>
<option value="pie">Pie Chart</option>
<option value="line">Line Chart</option>
</select>
<select id="filterField" class="text-sm border rounded px-2 py-1">
<option value="age">Age</option>
<option value="gender">Gender</option>
<option value="booth">Booth</option>
</select>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="bg-white p-4 rounded-lg shadow-sm">
<h5 class="text-sm font-medium mb-3">Distribution by Selected Field</h5>
<div id="mainChart" class="h-64"></div>
</div>
<div class="bg-white p-4 rounded-lg shadow-sm">
<h5 class="text-sm font-medium mb-3">Gender Distribution</h5>
<div id="genderChart" class="h-64"></div>
</div>
</div>
<div class="mt-6 grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="bg-white p-4 rounded-lg shadow-sm">
<h5 class="text-sm font-medium mb-3">Age Groups</h5>
<div id="ageChart" class="h-48"></div>
</div>
<div class="bg-white p-4 rounded-lg shadow-sm">
<h5 class="text-sm font-medium mb-3">Booth Analysis</h5>
<div id="boothChart" class="h-48"></div>
</div>
<div class="bg-white p-4 rounded-lg shadow-sm">
<h5 class="text-sm font-medium mb-3">Other Metrics</h5>
<div id="otherChart" class="h-48"></div>
</div>
</div>
</div>
<div>
<div class="flex items-center mb-2">
<i data-feather="alert-triangle" class="w-5 h-5 text-indigo-500 mr-2"></i>
<h4 class="font-medium">Potential Issues</h4>
</div>
<div id="dataIssues" class="bg-gray-50 p-4 rounded-lg">
<!-- Issues will be inserted here -->
</div>
</div>
</div>
<!-- Data Visualization -->
<div id="dataVisualization" class="hidden bg-white p-6 rounded-xl shadow-sm mb-8">
<div class="flex items-center justify-between mb-6">
<h3 class="text-xl font-semibold text-gray-800">Data Visualizations</h3>
<div class="flex space-x-2">
<select id="visualizationType" class="border rounded-md px-3 py-2 text-sm">
<option value="bar">Bar Chart</option>
<option value="line">Line Chart</option>
<option value="pie">Pie Chart</option>
<option value="scatter">Scatter Plot</option>
</select>
<button onclick="generateVisualization()" class="px-4 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 text-sm">
Generate
</button>
<button onclick="closeVisualization()" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 text-sm">
Close
</button>
</div>
</div>
<div id="visualizationContainer" class="w-full h-96 bg-gray-50 rounded-lg flex items-center justify-center">
<p class="text-gray-500">Select visualization options and click Generate</p>
</div>
</div>
<!-- Data Preview -->
<div id="dataPreview" class="hidden">
<div class="flex items-center justify-between mb-4">
<h3 class="text-lg font-medium text-gray-700">Data Preview</h3>
<div class="flex space-x-2">
<button id="exportBtn" class="px-3 py-1 bg-green-600 text-white rounded-lg hover:bg-green-700 transition text-sm flex items-center">
<i data-feather="download" class="w-4 h-4 mr-1"></i> Export
</button>
<button onclick="closePreview()" class="px-3 py-1 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition text-sm flex items-center">
<i data-feather="x" class="w-4 h-4 mr-1"></i> Close
</button>
</div>
</div>
<div id="dataTable" class="border rounded-lg overflow-auto">
<!-- Table will be inserted here -->
</div>
</div>
</div>
</div>
<script>
// Initialize feather icons
document.addEventListener('DOMContentLoaded', function() {
feather.replace();
window.visualizationGenerated = false;
// Setup dropzone
const dropzone = document.getElementById('dropzone');
const fileInput = document.getElementById('fileInput');
const browseBtn = document.getElementById('browseBtn');
browseBtn.addEventListener('click', function() {
fileInput.click();
});
fileInput.addEventListener('change', function(e) {
if (e.target.files.length) {
handleFile(e.target.files[0]);
}
});
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropzone.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
['dragenter', 'dragover'].forEach(eventName => {
dropzone.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropzone.addEventListener(eventName, unhighlight, false);
});
function highlight() {
dropzone.classList.add('dropzone-active');
}
function unhighlight() {
dropzone.classList.remove('dropzone-active');
}
dropzone.addEventListener('drop', function(e) {
const dt = e.dataTransfer;
const file = dt.files[0];
handleFile(file);
});
});
function handleFile(file) {
const errorMessage = document.getElementById('errorMessage');
const errorText = document.getElementById('errorText');
// Check file type
if (!file.name.match(/\.(xlsx|xls|csv)$/i)) {
errorText.textContent = 'Please upload an Excel file (.xlsx, .xls) or CSV file.';
errorMessage.classList.remove('hidden');
return;
}
// Update file info
document.getElementById('fileName').textContent = 'File: ' + file.name;
document.getElementById('fileDetails').textContent = 'Size: ' + formatFileSize(file.size);
document.getElementById('fileInfo').classList.remove('hidden');
document.getElementById('analysisOptions').classList.remove('hidden');
// Parse and store file for analysis
const reader = new FileReader();
reader.onload = function(e) {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
window.workbook = workbook;
window.sheetData = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]);
};
reader.readAsArrayBuffer(file);
}
function formatFileSize(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function resetFile() {
document.getElementById('fileInput').value = '';
document.getElementById('fileInfo').classList.add('hidden');
document.getElementById('analysisOptions').classList.add('hidden');
document.getElementById('resultsSection').classList.add('hidden');
document.getElementById('dataPreview').classList.add('hidden');
delete window.currentFile;
}
function closePreview() {
document.getElementById('dataPreview').classList.add('hidden');
}
document.getElementById('analyzeBtn').addEventListener('click', function() {
if (!window.sheetData || window.sheetData.length === 0) return;
const loadingIndicator = document.getElementById('loadingIndicator');
const resultsSection = document.getElementById('resultsSection');
loadingIndicator.classList.remove('hidden');
resultsSection.classList.add('hidden');
// Process data in background to prevent UI freeze
setTimeout(() => {
try {
const analysis = analyzeData(window.sheetData);
loadingIndicator.classList.add('hidden');
showAnalysisResults(analysis);
} catch (error) {
loadingIndicator.classList.add('hidden');
const errorMessage = document.getElementById('errorMessage');
document.getElementById('errorText').textContent = 'Error analyzing data: ' + error.message;
errorMessage.classList.remove('hidden');
}
}, 100);
});
function analyzeData(data) {
if (!data || data.length === 0) throw new Error('No data to analyze');
const numericColumns = [];
const textColumns = [];
const dateColumns = [];
const emptyCells = { count: 0, columns: {} };
const columnStats = {};
// First pass - determine column types and collect basic stats
Object.keys(data[0]).forEach(col => {
let isNumeric = true;
let isDate = true;
let hasValues = false;
for (let row of data) {
const val = row[col];
if (val === undefined || val === null || val === '') {
emptyCells.count++;
emptyCells.columns[col] = (emptyCells.columns[col] || 0) + 1;
continue;
}
hasValues = true;
if (isNumeric && isNaN(Number(val))) isNumeric = false;
if (isDate && isNaN(Date.parse(val))) isDate = false;
}
if (hasValues) {
if (isNumeric) numericColumns.push(col);
else if (isDate) dateColumns.push(col);
else textColumns.push(col);
}
columnStats[col] = { type: isNumeric ? 'numeric' : isDate ? 'date' : 'text', empty: emptyCells.columns[col] || 0 };
});
// Second pass - calculate actual statistics
const analysis = {
recordCount: data.length,
columnCount: Object.keys(data[0]).length,
numericColumns,
textColumns,
dateColumns,
emptyCells,
columnStats,
columnUniqueness: calculateUniqueness(data),
potentialIssues: findPotentialIssues(data, columnStats)
};
return analysis;
}
function calculateUniqueness(data) {
const uniqueness = {};
Object.keys(data[0]).forEach(col => {
const uniqueValues = new Set();
data.forEach(row => uniqueValues.add(row[col]));
uniqueness[col] = {
uniqueCount: uniqueValues.size,
uniquenessRatio: uniqueValues.size / data.length
};
});
return uniqueness;
}
function findPotentialIssues(data, columnStats) {
const issues = [];
// Check for empty columns
Object.entries(columnStats).forEach(([col, stats]) => {
if (stats.empty / data.length > 0.5) {
issues.push({
type: 'missing_data',
column: col,
severity: 'high',
message: `Column "${col}" has more than 50% empty values`
});
}
});
// Check for duplicate rows
const rowHashes = data.map(row => JSON.stringify(row));
const uniqueHashes = new Set(rowHashes);
if (uniqueHashes.size < data.length) {
const duplicateCount = data.length - uniqueHashes.size;
issues.push({
type: 'duplicates',
severity: 'medium',
message: `${duplicateCount} potential duplicate rows found`
});
}
return issues;
}
// Visualization functions
function generateVisualization() {
if (!window.sheetData || window.sheetData.length === 0) return;
const type = document.getElementById('visualizationType').value;
const container = document.getElementById('visualizationContainer');
container.innerHTML = '<canvas id="dynamicChart"></canvas>';
const ctx = container.querySelector('canvas').getContext('2d');
const firstColumn = Object.keys(window.sheetData[0])[0];
const secondColumn = Object.keys(window.sheetData[0])[1] || firstColumn;
// Prepare data
const labels = window.sheetData.map(row => row[firstColumn] || 'N/A').slice(0, 20);
const values = window.sheetData.map(row => {
const val = row[secondColumn];
return isNaN(val) ? 0 : Number(val);
}).slice(0, 20);
new Chart(ctx, {
type: type,
data: {
labels: labels,
datasets: [{
label: secondColumn,
data: values,
backgroundColor: type === 'pie' || type === 'doughnut'
? generatePieColors(values.length)
: 'rgba(99, 102, 241, 0.8)',
borderColor: '#4f46e5',
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: true,
text: `${firstColumn} vs ${secondColumn}`,
font: { size: 16 }
},
legend: {
position: type === 'pie' || type === 'doughnut' ? 'right' : 'top'
}
},
scales: type !== 'pie' && type !== 'doughnut' ? {
y: { beginAtZero: true }
} : {}
}
});
}
function generatePieColors(count) {
const colors = [];
for (let i = 0; i < count; i++) {
const hue = (i * 360 / count) % 360;
colors.push(`hsla(${hue}, 70%, 60%, 0.8)`);
}
return colors;
}
function closeVisualization() {
document.getElementById('dataVisualization').classList.add('hidden');
}
document.getElementById('visualizeBtn').addEventListener('click', function() {
document.getElementById('dataVisualization').classList.remove('hidden');
if (!window.visualizationGenerated) {
generateVisualization();
window.visualizationGenerated = true;
}
});
document.getElementById('previewBtn').addEventListener('click', function() {
if (!window.sheetData || window.sheetData.length === 0) return;
const dataPreview = document.getElementById('dataPreview');
const dataTable = document.getElementById('dataTable');
// Display first 50 rows of actual data
const previewData = window.sheetData.slice(0, 50);
const columns = Object.keys(window.sheetData[0]);
// Build header
let tableHTML = `<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>`;
columns.forEach(col => {
tableHTML += `<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">${col}</th>`;
});
tableHTML += `</tr></thead><tbody class="bg-white divide-y divide-gray-200">`;
// Build rows
previewData.forEach(row => {
tableHTML += '<tr>';
columns.forEach(col => {
const val = row[col];
tableHTML += `<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${val !== undefined ? val : ''}</td>`;
});
tableHTML += '</tr>';
});
tableHTML += '</tbody></table>';
dataTable.innerHTML = tableHTML;
dataPreview.classList.remove('hidden');
});
function initializeCharts(analysis) {
// Find columns suitable for visualization
const chartableColumns = analysis.textColumns.filter(col =>
analysis.columnUniqueness[col].uniqueCount > 1 &&
analysis.columnUniqueness[col].uniqueCount < 20
);
// Generate chart data for all suitable columns
const chartData = {};
chartableColumns.forEach(col => {
const counts = {};
window.sheetData.forEach(row => {
const val = row[col] || 'Unknown';
counts[val] = (counts[val] || 0) + 1;
});
chartData[col] = counts;
});
// Clear previous charts
['mainChart', 'genderChart', 'ageChart', 'boothChart'].forEach(id => {
if (window[id]) window[id].destroy();
});
// Main interactive chart
const mainChartCtx = document.getElementById('mainChart').getContext('2d');
const firstChartCol = chartableColumns.length > 0 ? chartableColumns[0] : null;
if (firstChartCol) {
const labels = Object.keys(chartData[firstChartCol]);
const values = Object.values(chartData[firstChartCol]);
window.mainChart = new Chart(mainChartCtx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Count',
data: values,
backgroundColor: createGradient(mainChartCtx, '#6366f1', '#a855f7'),
borderColor: '#4f46e5',
borderWidth: 2,
borderRadius: 6,
hoverBackgroundColor: '#ec4899'
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false },
tooltip: {
backgroundColor: '#1e293b',
titleFont: { size: 14, weight: 'bold' },
bodyFont: { size: 12 },
padding: 12,
cornerRadius: 8,
displayColors: false
}
},
scales: {
y: {
beginAtZero: true,
grid: { color: '#e2e8f0' }
},
x: {
grid: { display: false }
}
},
animation: {
duration: 1000,
easing: 'easeOutQuart'
}
}
});
// Update filter dropdown
const filterField = document.getElementById('filterField');
filterField.innerHTML = '';
chartableColumns.forEach(col => {
const option = document.createElement('option');
option.value = col;
option.textContent = col;
filterField.appendChild(option);
});
filterField.value = firstChartCol;
}
// Create animated donut chart
const genderChartCtx = document.getElementById('genderChart').getContext('2d');
const genderData = chartableColumns.length > 0 ? chartData[chartableColumns[0]] : { 'Data': 1 };
window.genderChart = new Chart(genderChartCtx, {
type: 'doughnut',
data: {
labels: Object.keys(genderData),
datasets: [{
data: Object.values(genderData),
backgroundColor: generateColors(Object.keys(genderData).length),
borderWidth: 0,
hoverOffset: 20
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
cutout: '70%',
plugins: {
legend: {
position: 'bottom',
labels: {
padding: 20,
usePointStyle: true,
pointStyle: 'circle'
}
},
tooltip: {
backgroundColor: '#1e293b',
titleFont: { size: 14, weight: 'bold' },
bodyFont: { size: 12 },
padding: 12,
cornerRadius: 8
}
},
animation: {
animateScale: true,
animateRotate: true
}
}
});
// Create bubble chart for numeric data
const ageChartCtx = document.getElementById('ageChart').getContext('2d');
if (analysis.numericColumns.length > 0) {
const numericCol = analysis.numericColumns[0];
const values = window.sheetData.map(row => row[numericCol]).filter(val => !isNaN(val));
window.ageChart = new Chart(ageChartCtx, {
type: 'bubble',
data: {
datasets: [{
label: numericCol,
data: values.map(val => ({
x: Math.random() * 100,
y: Math.random() * 100,
r: Math.min(20, val / (Math.max(...values) / 20))
})),
backgroundColor: createGradient(ageChartCtx, '#6366f1', '#ec4899'),
borderColor: '#4f46e5',
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false },
tooltip: {
callbacks: {
label: ctx => `${numericCol}: ${values[ctx.dataIndex]}`
}
}
},
scales: {
x: { display: false },
y: { display: false }
}
}
});
}
// Create radar chart for categorical data
const boothChartCtx = document.getElementById('boothChart').getContext('2d');
if (chartableColumns.length > 1) {
const col1 = chartableColumns[0];
const col2 = chartableColumns[1];
const combinedData = {};
window.sheetData.forEach(row => {
const val1 = row[col1] || 'Unknown';
const val2 = row[col2] || 'Unknown';
const key = `${val1} x ${val2}`;
combinedData[key] = (combinedData[key] || 0) + 1;
});
const topCombinations = Object.entries(combinedData)
.sort((a, b) => b[1] - a[1])
.slice(0, 6);
window.boothChart = new Chart(boothChartCtx, {
type: 'radar',
data: {
labels: topCombinations.map(c => c[0]),
datasets: [{
label: 'Combination Frequency',
data: topCombinations.map(c => c[1]),
backgroundColor: 'rgba(99, 102, 241, 0.2)',
borderColor: '#6366f1',
borderWidth: 2,
pointBackgroundColor: '#6366f1',
pointRadius: 4,
pointHoverRadius: 6
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false }
},
scales: {
r: {
angleLines: { color: '#e2e8f0' },
grid: { color: '#e2e8f0' },
pointLabels: {
font: { size: 10 },
padding: 10
},
ticks: {
display: false,
stepSize: Math.ceil(Math.max(...topCombinations.map(c => c[1])) / 5)
}
}
}
}
});
}
// Helper functions
function createGradient(ctx, color1, color2) {
const gradient = ctx.createLinearGradient(0, 0, 0, 400);
gradient.addColorStop(0, color1);
gradient.addColorStop(1, color2);
return gradient;
}
function generateColors(count) {
const colors = [];
const hueStep = 360 / count;
for (let i = 0; i < count; i++) {
colors.push(`hsl(${i * hueStep}, 70%, 60%)`);
}
return colors;
}
// Interactive chart updates
document.getElementById('filterField').addEventListener('change', function() {
const field = this.value;
const counts = {};
window.sheetData.forEach(row => {
const val = row[field] || 'Unknown';
counts[val] = (counts[val] || 0) + 1;
});
// Animate update
anime({
targets: window.mainChart.data.datasets[0],
data: Object.values(counts),
easing: 'easeOutQuart',
duration: 800,
update: function() {
window.mainChart.data.labels = Object.keys(counts);
window.mainChart.update();
}
});
});
document.getElementById('chartType').addEventListener('change', function() {
anime({
targets: window.mainChart,
opacity: [1, 0],
duration: 300,
easing: 'linear',
complete: () => {
window.mainChart.config.type = this.value;
window.mainChart.update();
anime({
targets: window.mainChart,
opacity: [0, 1],
duration: 300,
easing: 'linear'
});
}
});
});
}
function showAnalysisResults(analysis) {
const fileSummary = document.getElementById('fileSummary');
const dataIssues = document.getElementById('dataIssues');
const resultsSection = document.getElementById('resultsSection');
// Show file summary
fileSummary.innerHTML = `
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="p-3 bg-white rounded-lg shadow-sm">
<p class="text-sm text-gray-500">Total Records</p>
<p class="text-xl font-bold text-indigo-600">${analysis.recordCount}</p>
</div>
<div class="p-3 bg-white rounded-lg shadow-sm">
<p class="text-sm text-gray-500">Columns</p>
<p class="text-xl font-bold text-indigo-600">${analysis.columnCount}</p>
</div>
<div class="p-3 bg-white rounded-lg shadow-sm">
<p class="text-sm text-gray-500">Numeric Columns</p>
<p class="text-xl font-bold text-indigo-600">${analysis.numericColumns.length}</p>
</div>
<div class="p-3 bg-white rounded-lg shadow-sm">
<p class="text-sm text-gray-500">Empty Cells</p>
<p class="text-xl font-bold text-indigo-600">${analysis.emptyCells.count}</p>
</div>
</div>
`;
// Show data issues
if (analysis.potentialIssues.length > 0) {
let issuesHTML = '<div class="space-y-3">';
analysis.potentialIssues.forEach(issue => {
issuesHTML += `
<div class="flex items-start">
<i data-feather="alert-circle" class="w-4 h-4 ${issue.severity === 'high' ? 'text-red-500' : 'text-yellow-500'} mt-1 mr-2"></i>
<div>
<p class="font-medium">${issue.message}</p>
${issue.column ? `<p class="text-sm text-gray-600">Column: ${issue.column}</p>` : ''}
</div>
</div>
`;
});
issuesHTML += '</div>';
dataIssues.innerHTML = issuesHTML;
} else {
dataIssues.innerHTML = '<p class="text-gray-600">No significant issues found in the data.</p>';
}
// Initialize charts with real data
initializeCharts(analysis);
resultsSection.classList.remove('hidden');
feather.replace();
}
document.getElementById('exportBtn').addEventListener('click', function() {
alert('In a real application, this would export the data to CSV or Excel format.');
});
</script>
</body>
</html>
|