Auto commit: 2026-02-17T17:13:55.696Z

This commit is contained in:
Flatlogic Bot 2026-02-17 17:13:55 +00:00
parent 3b91c65794
commit 4326c4f960
2 changed files with 90 additions and 1 deletions

View File

@ -96,6 +96,25 @@ $locations = $stmt->fetchAll();
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-md-6">
<div class="card p-4 h-100">
<h5><i class="bi bi-person-heart text-success"></i> Top 5 Artistas Más Pedidos</h5>
<div id="top-artists" class="mt-3">
<p class="text-secondary text-center">Cargando estadísticas...</p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card p-4 h-100">
<h5><i class="bi bi-star-fill text-success"></i> Top 5 Canciones Más Pedidas</h5>
<div id="top-songs" class="mt-3">
<p class="text-secondary text-center">Cargando estadísticas...</p>
</div>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-md-12">
<div class="card p-4">
@ -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 = '<p class="text-secondary text-center">Sin datos aún</p>';
} else {
artistsDiv.innerHTML = '<div class="list-group list-group-flush bg-transparent">' +
data.top_artists.map((item, index) => `
<div class="list-group-item bg-transparent text-white border-secondary d-flex justify-content-between align-items-center">
<span>${index + 1}. ${item.artist}</span>
<span class="badge bg-success rounded-pill">${item.count} peticiones</span>
</div>
`).join('') + '</div>';
}
if (data.top_songs.length === 0) {
songsDiv.innerHTML = '<p class="text-secondary text-center">Sin datos aún</p>';
} else {
songsDiv.innerHTML = '<div class="list-group list-group-flush bg-transparent">' +
data.top_songs.map((item, index) => `
<div class="list-group-item bg-transparent text-white border-secondary d-flex justify-content-between align-items-center">
<div>
<span>${index + 1}. ${item.song}</span><br>
<small class="text-secondary">${item.artist}</small>
</div>
<span class="badge bg-success rounded-pill">${item.count} peticiones</span>
</div>
`).join('') + '</div>';
}
}
} 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);
</script>
</body>
</html>

View File

@ -53,7 +53,33 @@ if ($method === 'POST') {
}
if ($method === 'GET') {
$action = $_GET['action'] ?? 'list';
if ($action === 'stats') {
try {
// Top artists
$stmt = $db->query("SELECT artist, COUNT(*) as count FROM song_requests GROUP BY artist ORDER BY count DESC LIMIT 5");
$top_artists = $stmt->fetchAll();
// Top songs
$stmt = $db->query("SELECT artist, song, COUNT(*) as count FROM song_requests GROUP BY artist, song ORDER BY count DESC LIMIT 5");
$top_songs = $stmt->fetchAll();
echo json_encode([
'success' => true,
'top_artists' => $top_artists,
'top_songs' => $top_songs
]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
try {
// Auto-archive requests older than 2 hours (7200 seconds)
$db->query("UPDATE song_requests SET status = 'played' WHERE status = 'pending' AND created_at < (NOW() - INTERVAL 2 HOUR)");
$status = $_GET['status'] ?? 'pending';
$limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 10;