Herramientas de usuario

Herramientas del sitio


monitor_de_clima_sqlite

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anteriorRevisión previa
monitor_de_clima_sqlite [2026/09/07 18:00] – editor externo (Fecha desconocida) 127.0.0.1monitor_de_clima_sqlite [2026/09/08 16:30] (actual) hispa
Línea 59: Línea 59:
     HumMax, HumMin,     HumMax, HumMin,
     PresMax, PresMin: Double;     PresMax, PresMin: Double;
-    LabelTempMaxMin+    TempMaxFecha, TempMinFecha
-    LabelHumMaxMin+    HumMaxFecha, HumMinFecha
-    LabelPresMaxMinTLabel;+    PresMaxFecha, PresMinFechaTDateTime;
  
     procedure BtnSeleccionarDBClick(Sender: TObject);     procedure BtnSeleccionarDBClick(Sender: TObject);
Línea 83: Línea 83:
  
     procedure FormResize(Sender: TObject);     procedure FormResize(Sender: TObject);
- 
-    procedure CrearEtiquetasMaxMin; 
     procedure ActualizarGraficosYEstadisticas;     procedure ActualizarGraficosYEstadisticas;
  
Línea 101: Línea 99:
  
 { ========================================================= } { ========================================================= }
-                   FORMULARIO                             }+                  FORMULARIO                              }
 { ========================================================= } { ========================================================= }
  
Línea 116: Línea 114:
     ConfigurarConexion;     ConfigurarConexion;
     ConfigurarGraficas;     ConfigurarGraficas;
-    CrearEtiquetasMaxMin; 
  
     { 2. Mover al monitor principal DESPUÉS de definir las dimensiones }     { 2. Mover al monitor principal DESPUÉS de definir las dimensiones }
Línea 130: Línea 127:
  
 { ========================================================= } { ========================================================= }
-                   CREAR INTERFAZ                         }+                  CREAR INTERFAZ                          }
 { ========================================================= } { ========================================================= }
  
Línea 136: Línea 133:
 begin begin
   Self.Caption := 'Monitor de Clima';   Self.Caption := 'Monitor de Clima';
-  Self.SetBounds(100, 100, 900750);+  Self.SetBounds(100, 100, 950780);
  
-  { Botón seleccionar BD (las coordenadas X e Y se calculan en FormResize) }+  { Botón seleccionar BD }
   BtnSeleccionarDB := TButton.Create(Self);   BtnSeleccionarDB := TButton.Create(Self);
   BtnSeleccionarDB.Parent := Self;   BtnSeleccionarDB.Parent := Self;
Línea 207: Línea 204:
     Exit;     Exit;
  
-  { Limpiar series actuales } 
   SerieTemp.Clear;   SerieTemp.Clear;
   SerieHum.Clear;   SerieHum.Clear;
Línea 216: Línea 212:
   HayPres := False;   HayPres := False;
  
-  { Determinar límite de fecha si se eligen las últimas 24h } 
   if RadioOpciones.ItemIndex = 1 then   if RadioOpciones.ItemIndex = 1 then
     FiltroFechaMin := MaxFechaDataset - 1.0     FiltroFechaMin := MaxFechaDataset - 1.0
   else   else
-    FiltroFechaMin := 0; // Sin límite inferior+    FiltroFechaMin := 0;
  
-  { Recorrer datos y filtrar según la opción seleccionada } 
   for i := 0 to High(DatosMediciones) do   for i := 0 to High(DatosMediciones) do
   begin   begin
Línea 237: Línea 231:
       SeriePresion.AddXY(FechaVal, PVal);       SeriePresion.AddXY(FechaVal, PVal);
  
-      { Calcular Máx y Mín para el conjunto filtrado }+      { Temperatura Máx y Mín }
       if not HayTemp then       if not HayTemp then
       begin       begin
-        TempMax := TVal; +        TempMax := TVal; TempMin := TVal
-        TempMin := TVal;+        TempMaxFecha := FechaVal; TempMinFecha := FechaVal;
         HayTemp := True;         HayTemp := True;
       end       end
       else       else
       begin       begin
-        if TVal > TempMax then TempMax := TVal; +        if TVal > TempMax then begin TempMax := TVal; TempMaxFecha := FechaVal; end
-        if TVal < TempMin then TempMin := TVal;+        if TVal < TempMin then begin TempMin := TVal; TempMinFecha := FechaVal; end;
       end;       end;
  
 +      { Humedad Máx y Mín }
       if not HayHum then       if not HayHum then
       begin       begin
-        HumMax := HVal; +        HumMax := HVal; HumMin := HVal
-        HumMin := HVal;+        HumMaxFecha := FechaVal; HumMinFecha := FechaVal;
         HayHum := True;         HayHum := True;
       end       end
       else       else
       begin       begin
-        if HVal > HumMax then HumMax := HVal; +        if HVal > HumMax then begin HumMax := HVal; HumMaxFecha := FechaVal; end
-        if HVal < HumMin then HumMin := HVal;+        if HVal < HumMin then begin HumMin := HVal; HumMinFecha := FechaVal; end;
       end;       end;
  
 +      { Presión Máx y Mín }
       if not HayPres then       if not HayPres then
       begin       begin
-        PresMax := PVal; +        PresMax := PVal; PresMin := PVal
-        PresMin := PVal;+        PresMaxFecha := FechaVal; PresMinFecha := FechaVal;
         HayPres := True;         HayPres := True;
       end       end
       else       else
       begin       begin
-        if PVal > PresMax then PresMax := PVal; +        if PVal > PresMax then begin PresMax := PVal; PresMaxFecha := FechaVal; end
-        if PVal < PresMin then PresMin := PVal;+        if PVal < PresMin then begin PresMin := PVal; PresMinFecha := FechaVal; end;
       end;       end;
     end;     end;
   end;   end;
  
-  { Actualizar etiquetas de texto con los valores correspondientes }+  { 
 +    FORMATO ESTANDARIZADO DE LEYENDA (Uso de %% para imprimir el carácter % en Format) 
 +    Línea 1: Titular igualado a 20 caracteres visibles exactos. 
 +    Línea 2 y 3: Mismo formato de ancho fijo (%7.2f). 
 +  }
   if HayTemp then   if HayTemp then
-    LabelTempMaxMin.Caption := Format('Máx: %.2f °C' + LineEnding + 'Mín: %.2f °C', [TempMax, TempMin])+    SerieTemp.Title := Format('Temperatura (°C)    ' + LineEnding + 
 +                              ' Máx: %7.2f (%s)' + LineEnding + 
 +                              ' Mín: %7.2f (%s)', 
 +                              [TempMax, FormatDateTime('dd-mm hh:nn', TempMaxFecha), 
 +                               TempMin, FormatDateTime('dd-mm hh:nn', TempMinFecha)])
   else   else
-    LabelTempMaxMin.Caption := '';+    SerieTemp.Title := 'Temperatura (°C)    ';
  
   if HayHum then   if HayHum then
-    LabelHumMaxMin.Caption := Format('Máx: %.2f %%' + LineEnding + 'Mín: %.2f %%', [HumMax, HumMin])+    SerieHum.Title := Format('Humedad (%%)          ' + LineEnding + 
 +                             ' Máx: %7.2f (%s)' + LineEnding + 
 +                             ' Mín: %7.2f (%s)', 
 +                             [HumMax, FormatDateTime('dd-mm hh:nn', HumMaxFecha), 
 +                              HumMin, FormatDateTime('dd-mm hh:nn', HumMinFecha)])
   else   else
-    LabelHumMaxMin.Caption := '';+    SerieHum.Title := 'Humedad (%%)          ';
  
   if HayPres then   if HayPres then
-    LabelPresMaxMin.Caption := Format('Máx: %.2f hPa' + LineEnding + 'Mín: %.2f hPa', [PresMax, PresMin])+    SeriePresion.Title := Format('Presión (hPa)       ' + LineEnding + 
 +                              ' Máx: %7.2f (%s)' + LineEnding + 
 +                              ' Mín: %7.2f (%s)', 
 +                              [PresMax, FormatDateTime('dd-mm hh:nn', PresMaxFecha), 
 +                               PresMin, FormatDateTime('dd-mm hh:nn', PresMinFecha)])
   else   else
-    LabelPresMaxMin.Caption := ''+    SeriePresion.Title := 'Presión (hPa)       ';
- +
-  LabelTempMaxMin.BringToFront; +
-  LabelHumMaxMin.BringToFront; +
-  LabelPresMaxMin.BringToFront;+
  
   ChartTemp.Invalidate;   ChartTemp.Invalidate;
Línea 302: Línea 310:
  
 { ========================================================= } { ========================================================= }
-                CREAR ETIQUETAS MAX/MIN                   } +                      REDIMENSIONAR                       }
-{ ========================================================= } +
- +
-procedure TForm1.CrearEtiquetasMaxMin; +
-begin +
-  LabelTempMaxMin := TLabel.Create(ChartTemp); +
-  LabelTempMaxMin.Parent := ChartTemp; +
-  LabelTempMaxMin.AutoSize := True; +
-  LabelTempMaxMin.Color := clForm; +
-  LabelTempMaxMin.ParentColor := True; +
- +
-  LabelHumMaxMin := TLabel.Create(ChartHum); +
-  LabelHumMaxMin.Parent := ChartHum; +
-  LabelHumMaxMin.AutoSize := True; +
-  LabelHumMaxMin.Color := clForm; +
-  LabelHumMaxMin.ParentColor := True; +
- +
-  LabelPresMaxMin := TLabel.Create(ChartPres); +
-  LabelPresMaxMin.Parent := ChartPres; +
-  LabelPresMaxMin.AutoSize := True; +
-  LabelPresMaxMin.Color := clForm; +
-  LabelPresMaxMin.ParentColor := True; +
-end; +
- +
-{ ========================================================= } +
-{                      REDIMENSIONAR                        }+
 { ========================================================= } { ========================================================= }
  
 procedure TForm1.FormResize(Sender: TObject); procedure TForm1.FormResize(Sender: TObject);
 var var
-  AltoDisponible, AltoGrafico, MargenTop, AnchoGrafica, PosIzquierdaEtiqueta: Integer;+  AltoDisponible, AltoGrafico, MargenTop, AnchoGrafica: Integer;
   AnchoTotalPanel, PosInicioPanel, EspacioEntreControles: Integer;   AnchoTotalPanel, PosInicioPanel, EspacioEntreControles: Integer;
 begin begin
-  MargenTop := 65; // Aumentado ligeramente para dar espacio a los controles centrados+  MargenTop := 65;
  
   { 1. Centrar Botón y RadioGroup en la parte superior }   { 1. Centrar Botón y RadioGroup en la parte superior }
Línea 366: Línea 349:
   ChartHum.SetBounds(10, MargenTop + AltoGrafico, AnchoGrafica, AltoGrafico - 10);   ChartHum.SetBounds(10, MargenTop + AltoGrafico, AnchoGrafica, AltoGrafico - 10);
   ChartPres.SetBounds(10, MargenTop + (AltoGrafico * 2), AnchoGrafica, AltoGrafico - 10);   ChartPres.SetBounds(10, MargenTop + (AltoGrafico * 2), AnchoGrafica, AltoGrafico - 10);
- 
-  PosIzquierdaEtiqueta := AnchoGrafica - 130; 
- 
-  if Assigned(LabelTempMaxMin) then 
-  begin 
-    LabelTempMaxMin.Left := PosIzquierdaEtiqueta; 
-    LabelTempMaxMin.Top := 62; 
-    LabelTempMaxMin.BringToFront; 
-  end; 
- 
-  if Assigned(LabelHumMaxMin) then 
-  begin 
-    LabelHumMaxMin.Left := PosIzquierdaEtiqueta; 
-    LabelHumMaxMin.Top := 62; 
-    LabelHumMaxMin.BringToFront; 
-  end; 
- 
-  if Assigned(LabelPresMaxMin) then 
-  begin 
-    LabelPresMaxMin.Left := PosIzquierdaEtiqueta; 
-    LabelPresMaxMin.Top := 62; 
-    LabelPresMaxMin.BringToFront; 
-  end; 
 end; end;
  
 { ========================================================= } { ========================================================= }
-                   CONFIGURAR SQLITE                      }+                    CONFIGURAR SQLITE                     }
 { ========================================================= } { ========================================================= }
  
Línea 403: Línea 363:
  
 { ========================================================= } { ========================================================= }
-                   FORMATO DE HORA                        }+                    FORMATO DE HORA                       }
 { ========================================================= } { ========================================================= }
  
Línea 416: Línea 376:
  
 { ========================================================= } { ========================================================= }
-                   EJE DE TIEMPO                          }+                    EJE DE TIEMPO                         }
 { ========================================================= } { ========================================================= }
  
Línea 435: Línea 395:
  
 { ========================================================= } { ========================================================= }
-                  CONFIGURAR GRÁFICAS                     }+                   CONFIGURAR GRÁFICAS                    }
 { ========================================================= } { ========================================================= }
  
Línea 454: Línea 414:
  
   SerieTemp := TLineSeries.Create(ChartTemp);   SerieTemp := TLineSeries.Create(ChartTemp);
-  SerieTemp.Title := 'Temperatura (°C)    '; 
   SerieTemp.SeriesColor := clRed;   SerieTemp.SeriesColor := clRed;
   SerieTemp.LinePen.Width := 3;   SerieTemp.LinePen.Width := 3;
Línea 469: Línea 428:
  
   SerieHum := TLineSeries.Create(ChartHum);   SerieHum := TLineSeries.Create(ChartHum);
-  SerieHum.Title := 'Humedad (%)         '; 
   SerieHum.SeriesColor := clBlue;   SerieHum.SeriesColor := clBlue;
   SerieHum.LinePen.Width := 3;   SerieHum.LinePen.Width := 3;
Línea 484: Línea 442:
  
   SeriePresion := TLineSeries.Create(ChartPres);   SeriePresion := TLineSeries.Create(ChartPres);
-  SeriePresion.Title := 'Presión (hPa)       '; 
   SeriePresion.SeriesColor := clGreen;   SeriePresion.SeriesColor := clGreen;
   SeriePresion.LinePen.Width := 3;   SeriePresion.LinePen.Width := 3;
Línea 491: Línea 448:
  
 { ========================================================= } { ========================================================= }
-               SELECCIONAR BASE DE DATOS                  }+                SELECCIONAR BASE DE DATOS                 }
 { ========================================================= } { ========================================================= }
  
Línea 504: Línea 461:
  
 { ========================================================= } { ========================================================= }
-                CARGAR Y GRAFICAR DATOS                   }+                 CARGAR Y GRAFICAR DATOS                  }
 { ========================================================= } { ========================================================= }
  
Línea 569: Línea 526:
     SQLite3Connection1.Connected := False;     SQLite3Connection1.Connected := False;
  
-    { Rellenar gráficos y calcular estadísticas de manera automática } 
     ActualizarGraficosYEstadisticas;     ActualizarGraficosYEstadisticas;
  
monitor_de_clima_sqlite.txt · Última modificación: por hispa

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki