Spaces:
Sleeping
Sleeping
File size: 27,434 Bytes
c061318 | 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 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lead Analysis Dashboard</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/date-fns@2.29.3/index.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
color: #333;
}
.container {
max-width: 1400px;
margin: 0 auto;
padding: 20px;
}
.header {
text-align: center;
color: white;
margin-bottom: 30px;
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
.header p {
font-size: 1.1em;
opacity: 0.9;
}
.search-section {
background: white;
border-radius: 15px;
padding: 30px;
margin-bottom: 30px;
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.search-form {
display: flex;
gap: 15px;
align-items: end;
justify-content: center;
flex-wrap: wrap;
}
.input-group {
display: flex;
flex-direction: column;
min-width: 200px;
}
.input-group label {
font-weight: 600;
margin-bottom: 5px;
color: #555;
}
.input-group input {
padding: 12px 15px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 16px;
transition: all 0.3s ease;
}
.input-group input:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.btn {
padding: 12px 25px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.loading {
text-align: center;
padding: 40px;
color: white;
font-size: 18px;
}
.error {
background: #ff6b6b;
color: white;
padding: 20px;
border-radius: 10px;
margin: 20px 0;
text-align: center;
}
.results-section {
display: none;
}
.lead-status {
background: white;
border-radius: 15px;
padding: 25px;
margin-bottom: 20px;
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.status-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 20px;
flex-wrap: wrap;
gap: 15px;
}
.status-badge {
padding: 10px 20px;
border-radius: 25px;
font-weight: bold;
font-size: 16px;
text-transform: uppercase;
letter-spacing: 1px;
}
.lead-score {
text-align: center;
}
.score-circle {
width: 120px;
height: 120px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 10px;
font-size: 24px;
font-weight: bold;
color: white;
background: conic-gradient(#667eea 0deg, #764ba2 360deg);
}
.analytics-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
gap: 20px;
margin-bottom: 20px;
}
.analytics-card {
background: white;
border-radius: 15px;
padding: 25px;
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.card-header {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.card-icon {
width: 40px;
height: 40px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
margin-right: 15px;
font-size: 20px;
color: white;
}
.card-title {
font-size: 18px;
font-weight: 600;
color: #333;
}
.metric-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 0;
border-bottom: 1px solid #f0f0f0;
}
.metric-item:last-child {
border-bottom: none;
}
.metric-label {
color: #666;
font-weight: 500;
}
.metric-value {
font-weight: 600;
color: #333;
}
.properties-section {
background: white;
border-radius: 15px;
padding: 25px;
margin-bottom: 20px;
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.properties-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 15px;
margin-top: 20px;
}
.property-card {
border: 2px solid #f0f0f0;
border-radius: 10px;
padding: 20px;
transition: all 0.3s ease;
}
.property-card:hover {
border-color: #667eea;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.property-name {
font-weight: 600;
color: #333;
margin-bottom: 10px;
}
.property-price {
font-size: 18px;
font-weight: bold;
color: #667eea;
margin-bottom: 10px;
}
.property-stats {
display: flex;
justify-content: space-between;
font-size: 14px;
color: #666;
}
.recommendations {
background: white;
border-radius: 15px;
padding: 25px;
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.recommendation-item {
background: #f8f9ff;
border-left: 4px solid #667eea;
padding: 15px;
margin-bottom: 10px;
border-radius: 5px;
}
.chart-container {
position: relative;
height: 300px;
margin-top: 20px;
}
@media (max-width: 768px) {
.search-form {
flex-direction: column;
align-items: stretch;
}
.input-group {
min-width: auto;
}
.status-header {
flex-direction: column;
text-align: center;
}
.analytics-grid {
grid-template-columns: 1fr;
}
}
.fade-in {
animation: fadeIn 0.6s ease-in-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>π― Lead Analysis Dashboard</h1>
<p>Comprehensive Customer Behavior Analytics & Lead Qualification</p>
</div>
<div class="search-section">
<form class="search-form" id="searchForm">
<div class="input-group">
<label for="customerId">Customer ID</label>
<input type="number" id="customerId" name="customerId" placeholder="Enter Customer ID" required
value="{{ customer_id if customer_id else '' }}">
</div>
<button type="submit" class="btn" id="searchBtn">
π Analyze Customer
</button>
</form>
</div>
<div id="loadingSection" class="loading" style="display: none;">
<div>π Analyzing customer data...</div>
<div style="margin-top: 10px; font-size: 14px; opacity: 0.8;">
Fetching lead qualification and property analytics
</div>
</div>
<div id="errorSection" class="error" style="display: none;"></div>
<div id="resultsSection" class="results-section">
<!-- Lead Status Section -->
<div class="lead-status fade-in">
<div class="status-header">
<div>
<h2>Lead Qualification Status</h2>
<div id="statusBadge" class="status-badge"></div>
<p id="statusDescription" style="margin-top: 10px; color: #666;"></p>
</div>
<div class="lead-score">
<div id="scoreCircle" class="score-circle"></div>
<div>Lead Score</div>
</div>
</div>
</div>
<!-- Analytics Grid -->
<div class="analytics-grid fade-in">
<!-- Engagement Analytics -->
<div class="analytics-card">
<div class="card-header">
<div class="card-icon" style="background: #667eea;">π</div>
<div class="card-title">Engagement Analytics</div>
</div>
<div id="engagementMetrics"></div>
<div class="chart-container">
<canvas id="engagementChart"></canvas>
</div>
</div>
<!-- Property Preferences -->
<div class="analytics-card">
<div class="card-header">
<div class="card-icon" style="background: #764ba2;">π </div>
<div class="card-title">Property Preferences</div>
</div>
<div id="propertyPreferences"></div>
<div class="chart-container">
<canvas id="propertyChart"></canvas>
</div>
</div>
<!-- Price Analysis -->
<div class="analytics-card">
<div class="card-header">
<div class="card-icon" style="background: #f39c12;">π°</div>
<div class="card-title">Price Analysis</div>
</div>
<div id="priceAnalysis"></div>
</div>
<!-- Conversion Probability -->
<div class="analytics-card">
<div class="card-header">
<div class="card-icon" style="background: #e74c3c;">π―</div>
<div class="card-title">Conversion Probability</div>
</div>
<div id="conversionAnalysis"></div>
<div class="chart-container">
<canvas id="conversionChart"></canvas>
</div>
</div>
</div>
<!-- Properties Section -->
<div class="properties-section fade-in">
<div class="card-header">
<div class="card-icon" style="background: #2ecc71;">ποΈ</div>
<div class="card-title">Viewed Properties</div>
</div>
<div id="propertiesGrid" class="properties-grid"></div>
</div>
<!-- Recommendations Section -->
<div class="recommendations fade-in">
<div class="card-header">
<div class="card-icon" style="background: #9b59b6;">π‘</div>
<div class="card-title">AI Recommendations</div>
</div>
<div id="recommendationsContent"></div>
</div>
</div>
</div>
<script>
// Global variables
let currentData = null;
let charts = {};
// Initialize
document.addEventListener('DOMContentLoaded', function() {
const customerId = document.getElementById('customerId').value;
if (customerId) {
fetchAnalysis(customerId);
}
});
// Form submission
document.getElementById('searchForm').addEventListener('submit', function(e) {
e.preventDefault();
const customerId = document.getElementById('customerId').value;
if (customerId) {
fetchAnalysis(customerId);
}
});
// Fetch analysis data
async function fetchAnalysis(customerId) {
showLoading();
hideError();
hideResults();
try {
const response = await fetch(`/api/customer/${customerId}`);
const data = await response.json();
if (data.success) {
currentData = data;
displayResults(data);
showResults();
} else {
showError(data.error || 'Failed to fetch analysis');
}
} catch (error) {
showError(`Error: ${error.message}`);
} finally {
hideLoading();
}
}
// Display results
function displayResults(data) {
const leadData = data.data.lead_qualification;
const analytics = data.data.analytics;
const properties = data.data.properties;
// Update lead status
updateLeadStatus(leadData);
// Update analytics cards
updateEngagementMetrics(analytics);
updatePropertyPreferences(analytics);
updatePriceAnalysis(analytics);
updateConversionAnalysis(analytics);
// Update properties
updatePropertiesGrid(properties);
// Update recommendations
updateRecommendations(analytics.recommendations);
// Create charts
createCharts(analytics);
}
// Update lead status
function updateLeadStatus(leadData) {
const statusBadge = document.getElementById('statusBadge');
const statusDescription = document.getElementById('statusDescription');
const scoreCircle = document.getElementById('scoreCircle');
statusBadge.textContent = leadData.lead_status;
statusBadge.style.backgroundColor = leadData.status_color;
statusDescription.textContent = leadData.status_description;
scoreCircle.textContent = `${Math.round(leadData.lead_score)}/100`;
}
// Update engagement metrics
function updateEngagementMetrics(analytics) {
const container = document.getElementById('engagementMetrics');
container.innerHTML = `
<div class="metric-item">
<span class="metric-label">Engagement Level</span>
<span class="metric-value">${analytics.engagement_level}</span>
</div>
<div class="metric-item">
<span class="metric-label">Total Views</span>
<span class="metric-value">${currentData.data.summary.total_views}</span>
</div>
<div class="metric-item">
<span class="metric-label">Total Duration</span>
<span class="metric-value">${formatDuration(currentData.data.summary.total_duration)}</span>
</div>
<div class="metric-item">
<span class="metric-label">Engagement Score</span>
<span class="metric-value">${Math.round(currentData.data.summary.engagement_score)}</span>
</div>
`;
}
// Update property preferences
function updatePropertyPreferences(analytics) {
const container = document.getElementById('propertyPreferences');
const preferredTypes = analytics.preferred_property_types || [];
container.innerHTML = preferredTypes.map((type, index) => `
<div class="metric-item">
<span class="metric-label">Preference ${index + 1}</span>
<span class="metric-value">${type}</span>
</div>
`).join('');
}
// Update price analysis
function updatePriceAnalysis(analytics) {
const container = document.getElementById('priceAnalysis');
const priceData = analytics.price_preferences || {};
container.innerHTML = `
<div class="metric-item">
<span class="metric-label">Average Price</span>
<span class="metric-value">${formatPrice(priceData.avg_price || 0)}</span>
</div>
<div class="metric-item">
<span class="metric-label">Min Price</span>
<span class="metric-value">${formatPrice(priceData.min_price || 0)}</span>
</div>
<div class="metric-item">
<span class="metric-label">Max Price</span>
<span class="metric-value">${formatPrice(priceData.max_price || 0)}</span>
</div>
<div class="metric-item">
<span class="metric-label">Price Range</span>
<span class="metric-value">${formatPrice(priceData.price_range || 0)}</span>
</div>
`;
}
// Update conversion analysis
function updateConversionAnalysis(analytics) {
const container = document.getElementById('conversionAnalysis');
const conversionData = analytics.conversion_probability || {};
container.innerHTML = `
<div class="metric-item">
<span class="metric-label">Conversion Probability</span>
<span class="metric-value">${Math.round(conversionData.final_probability || 0)}%</span>
</div>
<div class="metric-item">
<span class="metric-label">Confidence Level</span>
<span class="metric-value">${conversionData.confidence_level || 'Unknown'}</span>
</div>
<div class="metric-item">
<span class="metric-label">Opportunity Score</span>
<span class="metric-value">${Math.round(analytics.opportunity_score || 0)}</span>
</div>
<div class="metric-item">
<span class="metric-label">Risk Level</span>
<span class="metric-value">${analytics.risk_assessment?.risk_level || 'Unknown'}</span>
</div>
`;
}
// Update properties grid
function updatePropertiesGrid(properties) {
const container = document.getElementById('propertiesGrid');
container.innerHTML = properties.map(property => `
<div class="property-card">
<div class="property-name">${property.propertyName || 'Unknown Property'}</div>
<div class="property-price">${formatPrice(property.price || 0)}</div>
<div class="property-stats">
<span>Views: ${property.viewCount || 0}</span>
<span>Duration: ${formatDuration(property.totalDuration || 0)}</span>
<span>Type: ${property.propertyTypeName || 'Unknown'}</span>
</div>
</div>
`).join('');
}
// Update recommendations
function updateRecommendations(recommendations) {
const container = document.getElementById('recommendationsContent');
if (recommendations && recommendations.length > 0) {
container.innerHTML = recommendations.map(rec => `
<div class="recommendation-item">${rec}</div>
`).join('');
} else {
container.innerHTML = '<div class="recommendation-item">No specific recommendations available.</div>';
}
}
// Create charts
function createCharts(analytics) {
createEngagementChart(analytics);
createPropertyChart(analytics);
createConversionChart(analytics);
}
// Create engagement chart
function createEngagementChart(analytics) {
const ctx = document.getElementById('engagementChart').getContext('2d');
if (charts.engagement) {
charts.engagement.destroy();
}
charts.engagement = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['High Engagement', 'Medium Engagement', 'Low Engagement'],
datasets: [{
data: [40, 35, 25], // Sample data
backgroundColor: ['#667eea', '#764ba2', '#95a5a6']
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom'
}
}
}
});
}
// Create property chart
function createPropertyChart(analytics) {
const ctx = document.getElementById('propertyChart').getContext('2d');
if (charts.property) {
charts.property.destroy();
}
const propertyTypes = analytics.preferred_property_types || [];
const labels = propertyTypes.slice(0, 5);
const data = labels.map((_, i) => Math.max(1, 5 - i));
charts.property = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Interest Level',
data: data,
backgroundColor: '#667eea'
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
}
},
scales: {
y: {
beginAtZero: true
}
}
}
});
}
// Create conversion chart
function createConversionChart(analytics) {
const ctx = document.getElementById('conversionChart').getContext('2d');
if (charts.conversion) {
charts.conversion.destroy();
}
const conversionProb = analytics.conversion_probability?.final_probability || 0;
charts.conversion = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['Conversion Probability', 'Remaining'],
datasets: [{
data: [conversionProb, 100 - conversionProb],
backgroundColor: ['#e74c3c', '#ecf0f1'],
borderWidth: 0
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
cutout: '70%',
plugins: {
legend: {
display: false
}
}
}
});
}
// Utility functions
function formatPrice(price) {
return `βΉ${price.toLocaleString('en-IN')}`;
}
function formatDuration(seconds) {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
return `${hours}h ${minutes}m`;
}
function showLoading() {
document.getElementById('loadingSection').style.display = 'block';
document.getElementById('searchBtn').disabled = true;
document.getElementById('searchBtn').textContent = 'π Analyzing...';
}
function hideLoading() {
document.getElementById('loadingSection').style.display = 'none';
document.getElementById('searchBtn').disabled = false;
document.getElementById('searchBtn').textContent = 'π Analyze Customer';
}
function showError(message) {
const errorSection = document.getElementById('errorSection');
errorSection.textContent = message;
errorSection.style.display = 'block';
}
function hideError() {
document.getElementById('errorSection').style.display = 'none';
}
function showResults() {
document.getElementById('resultsSection').style.display = 'block';
}
function hideResults() {
document.getElementById('resultsSection').style.display = 'none';
}
</script>
</body>
</html> |