Alternative Data API - Client Demo
Fetch Alternative Data (Mock Examples)
Important Notes:
- This is a DEMONSTRATION tool using MOCK (sample) data. It does NOT connect to any live alternative data API.
- The data displayed is pre-defined and not real-time or indicative of actual conditions.
- Alternative data is diverse and complex; this tool only shows a few simplified examples. Real alternative data APIs offer vast and varied datasets.
- Analyzing and interpreting alternative data requires specialized skills and contextual understanding.
- For actual investment decisions or research, always use reputable, verified data sources and consult with qualified professionals.
Please select a data type.
`; resultsOutputDiv.style.display = 'block'; notesContainerEl.style.display = 'none'; downloadPdfBtn.style.display = 'none'; return; } if (!identifier) { resultsOutputDiv.innerHTML = `Please enter an identifier.
`; resultsOutputDiv.style.display = 'block'; notesContainerEl.style.display = 'none'; downloadPdfBtn.style.display = 'none'; return; } const dataCategory = mockAltData[dataType]; const data = dataCategory ? dataCategory[identifier] : null; let resultsHTML = ''; if (data) { resultsHTML = `${escapeHtml(data.type)} for "${escapeHtml(data.identifier)}" (Mock Data)
`; for (const key in data) { if (data.hasOwnProperty(key) && key !== 'type' && key !== 'identifier') { let value = data[key]; let displayValue = escapeHtml(String(value)); if (key === 'sentimentScore' && typeof value === 'number') { displayValue = `${value.toFixed(2)} (${escapeHtml(data.sentimentLabel || '')})`; } else if (key === 'mentionsToday' && typeof value === 'number') { displayValue = `${value.toLocaleString()}`; } else if (key === 'trend') { const trendClass = value === 'increasing' ? 'ada-trend-increasing' : (value === 'decreasing' ? 'ada-trend-decreasing' : ''); displayValue = `${escapeHtml(value)}`; } else if (key === 'keywords' && Array.isArray(value)) { displayValue = value.map(k => escapeHtml(k)).join(', '); } else if (key === 'trafficIndex' && typeof value === 'number') { displayValue = `${value}`; } else if (key === 'changeVsPrevWeekPct' && typeof value === 'number') { const changeClass = value >= 0 ? 'ada-trend-increasing' : 'ada-trend-decreasing'; const sign = value >=0 ? '+' : ''; displayValue = `${sign}${value.toFixed(1)}% vs. previous week`; } else if (key === 'TEUsThisMonth' && typeof value === 'number') { displayValue = `${value.toLocaleString()} TEUs`; } else if (key === 'changeVsPrevMonthPct' && typeof value === 'number') { const changeClass = value >= 0 ? 'ada-trend-increasing' : 'ada-trend-decreasing'; const sign = value >=0 ? '+' : ''; displayValue = `${sign}${value.toFixed(1)}% vs. previous month`; } else if (typeof value === 'number') { displayValue = `${value.toLocaleString()}`; } // Convert camelCase key to Title Case for label const label = key.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase()); resultsHTML += `${escapeHtml(label)}: ${displayValue}
`; } } notesContainerEl.style.display = 'block'; downloadPdfBtn.style.display = 'block'; } else { resultsHTML = `No mock data found for type "${escapeHtml(dataType)}" with identifier "${escapeHtml(identifier)}". Check available identifiers in the hint.
`; notesContainerEl.style.display = 'none'; downloadPdfBtn.style.display = 'none'; } resultsOutputDiv.innerHTML = resultsHTML; resultsOutputDiv.style.display = 'block'; }); downloadPdfBtn?.addEventListener('click', function () { const { jsPDF } = window.jspdf; const pdfOutputArea = document.getElementById('adaPdfOutputArea'); if (!pdfOutputArea || resultsOutputDiv.style.display === 'none' || resultsOutputDiv.querySelector('.ada-error')) { alert('Please fetch valid mock data first before downloading PDF.'); return; } // Ensure notes are visible for PDF capture document.getElementById('adaNotesContainer').style.display = 'block'; html2canvas(pdfOutputArea, { scale: 1.5, useCORS: true, backgroundColor: '#ffffff' }) .then(canvas => { const imgData = canvas.toDataURL('image/jpeg', 0.9); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const margin = 40; const contentWidth = pdfWidth - 2 * margin; const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / canvasHeight; let imgWidth = contentWidth; let imgHeight = imgWidth / ratio; if (imgHeight > pdfHeight - 2 * margin) { imgHeight = pdfHeight - 2 * margin; imgWidth = imgHeight * ratio; } const x = (pdfWidth - imgWidth) / 2; pdf.addImage(imgData, 'JPEG', x, margin, imgWidth, imgHeight, undefined, 'MEDIUM'); pdf.save('Alternative_Data_Demo.pdf'); }) .catch(err => { console.error("Error generating PDF:", err); alert("Error generating PDF. See console for details."); }); }); function escapeHtml(unsafe) { if (typeof unsafe !== 'string') return unsafe === undefined || unsafe === null ? '' : String(unsafe); return unsafe.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); } });