arreglando datos del tiempo

This commit is contained in:
Tatiana Villa Ema 2026-02-17 18:54:46 +01:00
parent 051fb104af
commit ed8138782f
7 changed files with 37 additions and 4 deletions

View File

@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Estadísticas | El Tiempo</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/estilos.css">
</head>

View File

@ -21,7 +21,11 @@ function buildApiUrl({ ciudad, fecha = null, desde = null, hasta = null }) {
if (desde) params.append("desde", desde);
if (hasta) params.append("hasta", hasta);
console.log("24 - Construyendo URL con parámetros:", { ciudad, fecha, desde, hasta });
console.log("URL API:", `${BASE_API}?${params.toString()}`);
return `${BASE_API}?${params.toString()}`;
}
// ====================
@ -135,6 +139,8 @@ function renderMonthStats(data) {
function renderTrend(data) {
const byYear = {};
console.log("Datos recibidos para tendencia histórica:", data);
// Agrupar datos por año para el mes seleccionado
data.forEach(d => {
const date = new Date(d.dia);
@ -149,6 +155,8 @@ function renderTrend(data) {
const container = $("trend-container");
console.log("Datos agrupados por año para tendencia:", byYear);
if (Object.keys(byYear).length === 0) {
container.innerHTML = "<p>No hay datos históricos para este mes.</p>";
return;
@ -179,11 +187,33 @@ function renderTrend(data) {
// Cargar mes actual según selectedMonth
// ====================
function loadCurrentMonth() {
const year = new Date().getFullYear();
const ahora = new Date();
const currentYear = ahora.getFullYear();
const currentMonth = ahora.getMonth();
// 1. Calculamos el año objetivo (si selectedMonth es mayor al actual, asumimos año anterior o lógica de negocio)
// Para simplificar tu oposición, usaremos el año actual.
const year = currentYear;
const month = selectedMonth + 1;
// 2. Primer día del mes
const firstDay = `${year}-${String(month).padStart(2, "0")}-01`;
const lastDay = new Date(year, month, 0).toISOString().split("T")[0];
// 3. Cálculo del último día (evitando el desfase de toISOString)
let ultimoDiaObj = new Date(year, month, 0);
// LÓGICA DE SEGURIDAD: Si es el mes/año actual, el último día es HOY, no el fin de mes.
if (selectedMonth === currentMonth && year === currentYear) {
ultimoDiaObj = ahora;
}
// Formateo manual para evitar el error de -1 día por zona horaria (UTC)
const y = ultimoDiaObj.getFullYear();
const m = String(ultimoDiaObj.getMonth() + 1).padStart(2, "0");
const d = String(ultimoDiaObj.getDate()).padStart(2, "0");
const lastDay = `${y}-${m}-${d}`;
console.log("Cargando datos para:", monthNames[selectedMonth], `(${firstDay} a ${lastDay})`);
loadStats({ desde: firstDay, hasta: lastDay });
}

View File

@ -114,6 +114,8 @@ $sql .= "
ORDER BY DATE(fecha);
";
console_log("SQL: $sql");
console_log("Params: " . implode(", ", $params));
// ============================
// 6. PREPARAR Y EJECUTAR
// ============================

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 KiB

BIN
img/tatianalogo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

View File

@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tatiana Villa - Sobre mí</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<!-- Estilos -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;700&display=swap" rel="stylesheet">