@@ -186,6 +205,46 @@ $locations = $stmt->fetchAll();
}
}
+ async function fetchStats() {
+ const artistsDiv = document.getElementById('top-artists');
+ const songsDiv = document.getElementById('top-songs');
+ try {
+ const response = await fetch('api/song_requests.php?action=stats');
+ const data = await response.json();
+
+ if (data.success) {
+ if (data.top_artists.length === 0) {
+ artistsDiv.innerHTML = '
Sin datos aún
';
+ } else {
+ artistsDiv.innerHTML = '
' +
+ data.top_artists.map((item, index) => `
+
+ ${index + 1}. ${item.artist}
+ ${item.count} peticiones
+
+ `).join('') + '
';
+ }
+
+ if (data.top_songs.length === 0) {
+ songsDiv.innerHTML = '
Sin datos aún
';
+ } else {
+ songsDiv.innerHTML = '
' +
+ data.top_songs.map((item, index) => `
+
+
+ ${index + 1}. ${item.song}
+ ${item.artist}
+
+
${item.count} peticiones
+
+ `).join('') + '
';
+ }
+ }
+ } catch (error) {
+ console.error('Error fetching stats:', error);
+ }
+ }
+
async function updateStatus(id, action) {
if (action === 'delete' && !confirm('¿Estás seguro de eliminar esta petición?')) return;
@@ -210,7 +269,11 @@ $locations = $stmt->fetchAll();
}
fetchRequests();
- setInterval(fetchRequests, 15000);
+ fetchStats();
+ setInterval(() => {
+ fetchRequests();
+ fetchStats();
+ }, 15000);