Customer Preference-Based Product Recommender

Customer Preference-Based Product Recommender

Find the perfect products for your customers based on their needs.

Total Products Analyzed

0

Top Match Score

0

Best Match

N/A

Top 5 Recommended Products

Match Score Comparison

Product Recommendation Report

Report Date:

For Customer:

Top Recommendations

RankProductBrandPrice ($)Match Score

Score Comparison

Score Comparison Chart

Match Score

`); }); renderScoreChart(recommendations.slice(0, 5)); } function renderScoreChart(recommendations) { const ctx = document.getElementById('score-chart').getContext('2d'); if (scoreChart) scoreChart.destroy(); scoreChart = new Chart(ctx, { type: 'bar', data: { labels: recommendations.map(r => r.name), datasets: [{ label: 'Match Score', data: recommendations.map(r => r.finalScore), backgroundColor: '#3b82f6', borderColor: '#2563eb', borderWidth: 1 }] }, options: { responsive: true, plugins: { legend: { display: false } }, scales: { y: { beginAtZero: true, max: 100 } } } }); } function renderConfig() { // Weights weightsForm.innerHTML = ''; Object.keys(metricKeys).forEach(key => { weightsForm.insertAdjacentHTML('beforeend', `
${weights[key]}%
`); }); weightsForm.insertAdjacentHTML('beforeend', `
Total: 100%
`); // Lists document.getElementById('customer-list').innerHTML = customers.map(c => `
${c.name}
`).join(''); document.getElementById('product-list').innerHTML = products.map(p => `
${p.name}
`).join(''); // Customer Select Dropdown customerSelect.innerHTML = customers.map(c => ``).join(''); } // --- EVENT HANDLERS --- customerSelect.addEventListener('change', renderDashboard); weightsForm.addEventListener('input', (e) => { if (e.target.classList.contains('weight-input')) { const key = e.target.dataset.key; weights[key] = parseInt(e.target.value); e.target.nextElementSibling.textContent = `${weights[key]}%`; const total = Object.values(weights).reduce((a, b) => a + b, 0); const totalEl = document.getElementById('total-weight'); totalEl.textContent = `${total}%`; totalEl.style.color = total !== 100 ? '#ef4444' : '#16a34a'; renderDashboard(); } }); downloadPdfBtn.addEventListener('click', generatePdf); // --- TABS & NAVIGATION --- window.switchTab = (tabName) => { currentTab = tabName; Object.values(tabBtns).forEach(b=>b.classList.replace('tab-active', 'tab-inactive')); Object.values(tabContents).forEach(c=>c.style.display='none'); tabBtns[tabName].classList.replace('tab-inactive', 'tab-active'); tabContents[tabName].style.display = 'block'; }; window.navigateTabs = (dir) => { if (dir==='next' && currentTab==='dashboard') switchTab('config'); else if (dir==='prev' && currentTab==='config') switchTab('dashboard'); }; // --- PDF GENERATION --- async function generatePdf() { const { jsPDF } = window.jspdf; const pdfReportElement = document.getElementById('pdf-report'); const recommendations = generateRecommendations(); const customer = customers.find(c => c.id === parseInt(customerSelect.value)); document.getElementById('pdf-date').textContent = new Date().toLocaleDateString('en-US'); document.getElementById('pdf-customer-name').textContent = customer.name; document.getElementById('pdf-preferences-summary').innerHTML = `

Preferences: Target Price: ${formatUSD(customer.targetPrice)}, Max Price: ${formatUSD(customer.maxPrice)}, Essential Features: ${customer.essentialFeatures.join(', ')}

`; const pdfTableBody = document.getElementById('pdf-table-body'); pdfTableBody.innerHTML = ''; recommendations.slice(0, 5).forEach((rec, index) => { pdfTableBody.insertAdjacentHTML('beforeend', `${index+1}${rec.name}${rec.brand}${rec.price.toFixed(2)}${rec.finalScore}`); }); document.getElementById('pdf-chart-image').src = scoreChart.toBase64Image(); const canvas = await html2canvas(pdfReportElement, { scale: 2 }); const imgData = canvas.toDataURL('image/jpeg', 0.85); const pdf = new jsPDF('p', 'mm', 'a4'); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'JPEG', 0, 0, pdfWidth, pdfHeight); pdf.save(`Recommendations-${customer.name}.pdf`); } // --- INITIALIZATION --- function init() { weights = { price: 40, features: 50, brand: 10 }; const masterFeatures = ['4K Display', 'Long Battery Life', 'Lightweight', 'Premium Build', 'Budget Friendly']; customers = [ { id: 1, name: 'Tech Enthusiast', targetPrice: 1500, maxPrice: 2000, essentialFeatures: ['4K Display', 'Premium Build'], preferredBrands: ['InnovateX', 'Quantum'] }, { id: 2, name: 'Student on a Budget', targetPrice: 500, maxPrice: 700, essentialFeatures: ['Long Battery Life', 'Budget Friendly'], preferredBrands: ['Acer', 'Lenovo'] } ]; products = [ { id: 101, name: 'InnovateX ProBook', brand: 'InnovateX', price: 1800, features: ['4K Display', 'Long Battery Life', 'Premium Build'] }, { id: 102, name: 'Quantum Ultralight', brand: 'Quantum', price: 1600, features: ['Long Battery Life', 'Lightweight', 'Premium Build'] }, { id: 103, name: 'Lenovo StudyPad', brand: 'Lenovo', price: 650, features: ['Long Battery Life', 'Lightweight', 'Budget Friendly'] }, { id: 104, name: 'Acer Aspire Go', brand: 'Acer', price: 550, features: ['Long Battery Life', 'Budget Friendly'] } ]; renderAll(); } init(); });
Scroll to Top