Download script.js from SamAPS/radio-ad-performance-visualizer: direct link, hf CLI and curl.
- Browser
- Download file 8.31 kB
-
https://huggingface.co/spaces/SamAPS/radio-ad-performance-visualizer/resolve/main/script.js
- Command line
-
hf download hf://spaces/SamAPS/radio-ad-performance-visualizer/script.js
-
curl -L -o script.js https://huggingface.co/spaces/SamAPS/radio-ad-performance-visualizer/resolve/main/script.js
8.31 kB
| document.addEventListener('DOMContentLoaded', function() { | |
| // Data from the provided table | |
| const campaignData = [ | |
| { | |
| period: "July 16 β Aug 21", | |
| duration: 37, | |
| totalSpend: 14427.76, | |
| installs: 10524, | |
| avgCPI: 1.37, | |
| installsPerDay: 285, | |
| spendPerDay: 390 | |
| }, | |
| { | |
| period: "Aug 22 β Sept 22", | |
| duration: 32, | |
| totalSpend: 43367.81, | |
| installs: 50887, | |
| avgCPI: 0.85, | |
| installsPerDay: 1590, | |
| spendPerDay: 1355 | |
| }, | |
| { | |
| period: "Sept 24 β Oct 6", | |
| duration: 12, | |
| totalSpend: 35931.32, | |
| installs: 68994, | |
| avgCPI: 0.52, | |
| installsPerDay: 5750, | |
| spendPerDay: 2994 | |
| }, | |
| { | |
| period: "Oct 7 - Oct 27", | |
| duration: 21, | |
| totalSpend: 122436.10, | |
| installs: 423612, | |
| avgCPI: 0.29, | |
| installsPerDay: 20170, | |
| spendPerDay: 5830 | |
| }, | |
| { | |
| period: "Oct 28 - Nov 03", | |
| duration: 7, | |
| totalSpend: 68447.60, | |
| installs: 281859, | |
| avgCPI: 0.24, | |
| installsPerDay: 40270, | |
| spendPerDay: 9780 | |
| }, | |
| { | |
| period: "Nov 04 - Nov 12", | |
| duration: 14, | |
| totalSpend: 75875.47, | |
| installs: 339909, | |
| avgCPI: 0.22, | |
| installsPerDay: 24280, | |
| spendPerDay: 5420 | |
| } | |
| ]; | |
| // Populate data table | |
| const tableBody = document.getElementById('dataTableBody'); | |
| campaignData.forEach(data => { | |
| const row = document.createElement('tr'); | |
| row.innerHTML = ` | |
| <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${data.period}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${data.duration} days</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">$${data.totalSpend.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2})}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${data.installs.toLocaleString()}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">$${data.avgCPI.toFixed(2)}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${data.installsPerDay.toLocaleString()}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">$${data.spendPerDay.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2})}</td> | |
| `; | |
| tableBody.appendChild(row); | |
| }); | |
| // Extract labels and data for charts | |
| const labels = campaignData.map(item => item.period); | |
| const installsData = campaignData.map(item => item.installs); | |
| const spendData = campaignData.map(item => item.totalSpend); | |
| const installsPerDayData = campaignData.map(item => item.installsPerDay); | |
| const spendPerDayData = campaignData.map(item => item.spendPerDay); | |
| // Create Installs Chart | |
| const installsCtx = document.getElementById('installsChart').getContext('2d'); | |
| new Chart(installsCtx, { | |
| type: 'bar', | |
| data: { | |
| labels: labels, | |
| datasets: [{ | |
| label: 'Installs', | |
| data: installsData, | |
| backgroundColor: '#6366F1', | |
| borderColor: '#4F46E5', | |
| borderWidth: 1 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| ticks: { | |
| callback: function(value) { | |
| return value.toLocaleString(); | |
| } | |
| } | |
| } | |
| }, | |
| plugins: { | |
| tooltip: { | |
| callbacks: { | |
| label: function(context) { | |
| return context.dataset.label + ': ' + context.raw.toLocaleString(); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| // Create Spend Chart | |
| const spendCtx = document.getElementById('spendChart').getContext('2d'); | |
| new Chart(spendCtx, { | |
| type: 'line', | |
| data: { | |
| labels: labels, | |
| datasets: [{ | |
| label: 'Spend ($)', | |
| data: spendData, | |
| backgroundColor: '#8B5CF6', | |
| borderColor: '#7C3AED', | |
| borderWidth: 2, | |
| tension: 0.1, | |
| fill: false | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| ticks: { | |
| callback: function(value) { | |
| return ' + value.toLocaleString(); | |
| } | |
| } | |
| } | |
| }, | |
| plugins: { | |
| tooltip: { | |
| callbacks: { | |
| label: function(context) { | |
| return context.dataset.label + ': + context.raw.toLocaleString('en-US', {minimumFractionDigits: 2}); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| // Create Combined Chart | |
| const combinedCtx = document.getElementById('combinedChart').getContext('2d'); | |
| new Chart(combinedCtx, { | |
| type: 'bar', | |
| data: { | |
| labels: labels, | |
| datasets: [ | |
| { | |
| label: 'Installs', | |
| data: installsData, | |
| backgroundColor: '#6366F1', | |
| borderColor: '#4F46E5', | |
| borderWidth: 1, | |
| yAxisID: 'y' | |
| }, | |
| { | |
| label: 'Spend ($)', | |
| data: spendData, | |
| backgroundColor: '#8B5CF6', | |
| borderColor: '#7C3AED', | |
| borderWidth: 2, | |
| type: 'line', | |
| yAxisID: 'y1' | |
| } | |
| ] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| scales: { | |
| y: { | |
| type: 'linear', | |
| display: true, | |
| position: 'left', | |
| title: { | |
| display: true, | |
| text: 'Installs' | |
| }, | |
| ticks: { | |
| callback: function(value) { | |
| return value.toLocaleString(); | |
| } | |
| } | |
| }, | |
| y1: { | |
| type: 'linear', | |
| display: true, | |
| position: 'right', | |
| title: { | |
| display: true, | |
| text: 'Spend ($)' | |
| }, | |
| grid: { | |
| drawOnChartArea: false | |
| }, | |
| ticks: { | |
| callback: function(value) { | |
| return ' + value.toLocaleString(); | |
| } | |
| } | |
| } | |
| }, | |
| plugins: { | |
| tooltip: { | |
| callbacks: { | |
| label: function(context) { | |
| let label = context.dataset.label || ''; | |
| if (label) { | |
| label += ': '; | |
| } | |
| if (context.datasetIndex === 0) { | |
| label += context.raw.toLocaleString(); | |
| } else { | |
| label += ' + context.raw.toLocaleString('en-US', {minimumFractionDigits: 2}); | |
| } | |
| return label; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }); | |