arreglando datos del tiempo
This commit is contained in:
parent
051fb104af
commit
ed8138782f
|
|
@ -3,6 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Estadísticas | El Tiempo</title>
|
<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">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="stylesheet" href="css/estilos.css">
|
<link rel="stylesheet" href="css/estilos.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,11 @@ function buildApiUrl({ ciudad, fecha = null, desde = null, hasta = null }) {
|
||||||
if (desde) params.append("desde", desde);
|
if (desde) params.append("desde", desde);
|
||||||
if (hasta) params.append("hasta", hasta);
|
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()}`;
|
return `${BASE_API}?${params.toString()}`;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================
|
// ====================
|
||||||
|
|
@ -135,6 +139,8 @@ function renderMonthStats(data) {
|
||||||
function renderTrend(data) {
|
function renderTrend(data) {
|
||||||
const byYear = {};
|
const byYear = {};
|
||||||
|
|
||||||
|
console.log("Datos recibidos para tendencia histórica:", data);
|
||||||
|
|
||||||
// Agrupar datos por año para el mes seleccionado
|
// Agrupar datos por año para el mes seleccionado
|
||||||
data.forEach(d => {
|
data.forEach(d => {
|
||||||
const date = new Date(d.dia);
|
const date = new Date(d.dia);
|
||||||
|
|
@ -149,6 +155,8 @@ function renderTrend(data) {
|
||||||
|
|
||||||
const container = $("trend-container");
|
const container = $("trend-container");
|
||||||
|
|
||||||
|
console.log("Datos agrupados por año para tendencia:", byYear);
|
||||||
|
|
||||||
if (Object.keys(byYear).length === 0) {
|
if (Object.keys(byYear).length === 0) {
|
||||||
container.innerHTML = "<p>No hay datos históricos para este mes.</p>";
|
container.innerHTML = "<p>No hay datos históricos para este mes.</p>";
|
||||||
return;
|
return;
|
||||||
|
|
@ -179,12 +187,34 @@ function renderTrend(data) {
|
||||||
// Cargar mes actual según selectedMonth
|
// Cargar mes actual según selectedMonth
|
||||||
// ====================
|
// ====================
|
||||||
function loadCurrentMonth() {
|
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;
|
const month = selectedMonth + 1;
|
||||||
|
|
||||||
const firstDay = `${year}-${String(month).padStart(2,"0")}-01`;
|
// 2. Primer día del mes
|
||||||
const lastDay = new Date(year, month, 0).toISOString().split("T")[0];
|
const firstDay = `${year}-${String(month).padStart(2, "0")}-01`;
|
||||||
|
|
||||||
|
// 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 });
|
loadStats({ desde: firstDay, hasta: lastDay });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,8 @@ $sql .= "
|
||||||
ORDER BY DATE(fecha);
|
ORDER BY DATE(fecha);
|
||||||
";
|
";
|
||||||
|
|
||||||
|
console_log("SQL: $sql");
|
||||||
|
console_log("Params: " . implode(", ", $params));
|
||||||
// ============================
|
// ============================
|
||||||
// 6. PREPARAR Y EJECUTAR
|
// 6. PREPARAR Y EJECUTAR
|
||||||
// ============================
|
// ============================
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 163 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Tatiana Villa - Sobre mí</title>
|
<title>Tatiana Villa - Sobre mí</title>
|
||||||
|
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
|
||||||
<!-- Estilos -->
|
<!-- Estilos -->
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
<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">
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;700&display=swap" rel="stylesheet">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue