Sistema completo para monitoreo y gestion de flotas de vehiculos con: - Backend FastAPI con PostgreSQL/TimescaleDB - Frontend React con TypeScript y TailwindCSS - App movil React Native con Expo - Soporte para dispositivos GPS, Meshtastic y celulares - Video streaming en vivo con MediaMTX - Geocercas, alertas, viajes y reportes - Autenticacion JWT y WebSockets en tiempo real Documentacion completa y guias de usuario incluidas.
137 lines
3.9 KiB
Python
137 lines
3.9 KiB
Python
"""
|
|
Schemas Pydantic para Carga de Combustible.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from typing import List, Optional
|
|
|
|
from pydantic import Field
|
|
|
|
from app.schemas.base import BaseSchema, TimestampSchema
|
|
|
|
|
|
class CargaCombustibleBase(BaseSchema):
|
|
"""Schema base de carga de combustible."""
|
|
|
|
vehiculo_id: int
|
|
fecha: datetime
|
|
litros: float = Field(..., gt=0)
|
|
precio_litro: Optional[float] = Field(None, ge=0)
|
|
tipo_combustible: Optional[str] = Field(None, max_length=20)
|
|
|
|
|
|
class CargaCombustibleCreate(CargaCombustibleBase):
|
|
"""Schema para crear carga de combustible."""
|
|
|
|
conductor_id: Optional[int] = None
|
|
total: Optional[float] = Field(None, ge=0)
|
|
odometro: Optional[float] = Field(None, ge=0)
|
|
estacion: Optional[str] = Field(None, max_length=100)
|
|
estacion_direccion: Optional[str] = Field(None, max_length=255)
|
|
lat: Optional[float] = Field(None, ge=-90, le=90)
|
|
lng: Optional[float] = Field(None, ge=-180, le=180)
|
|
tanque_lleno: bool = True
|
|
metodo_pago: Optional[str] = Field(None, max_length=50)
|
|
numero_factura: Optional[str] = Field(None, max_length=50)
|
|
notas: Optional[str] = None
|
|
|
|
|
|
class CargaCombustibleUpdate(BaseSchema):
|
|
"""Schema para actualizar carga de combustible."""
|
|
|
|
fecha: Optional[datetime] = None
|
|
litros: Optional[float] = Field(None, gt=0)
|
|
precio_litro: Optional[float] = Field(None, ge=0)
|
|
total: Optional[float] = Field(None, ge=0)
|
|
tipo_combustible: Optional[str] = Field(None, max_length=20)
|
|
odometro: Optional[float] = Field(None, ge=0)
|
|
estacion: Optional[str] = Field(None, max_length=100)
|
|
estacion_direccion: Optional[str] = Field(None, max_length=255)
|
|
tanque_lleno: Optional[bool] = None
|
|
metodo_pago: Optional[str] = Field(None, max_length=50)
|
|
numero_factura: Optional[str] = Field(None, max_length=50)
|
|
notas: Optional[str] = None
|
|
|
|
|
|
class CargaCombustibleResponse(CargaCombustibleBase, TimestampSchema):
|
|
"""Schema de respuesta de carga de combustible."""
|
|
|
|
id: int
|
|
conductor_id: Optional[int] = None
|
|
total: Optional[float] = None
|
|
odometro: Optional[float] = None
|
|
estacion: Optional[str] = None
|
|
estacion_direccion: Optional[str] = None
|
|
lat: Optional[float] = None
|
|
lng: Optional[float] = None
|
|
tanque_lleno: bool
|
|
metodo_pago: Optional[str] = None
|
|
numero_factura: Optional[str] = None
|
|
notas: Optional[str] = None
|
|
|
|
|
|
class CargaCombustibleConRelaciones(CargaCombustibleResponse):
|
|
"""Schema con información del vehículo y conductor."""
|
|
|
|
vehiculo_nombre: Optional[str] = None
|
|
vehiculo_placa: Optional[str] = None
|
|
conductor_nombre: Optional[str] = None
|
|
|
|
|
|
class RendimientoCombustible(BaseSchema):
|
|
"""Schema para rendimiento de combustible entre cargas."""
|
|
|
|
carga_id: int
|
|
fecha: datetime
|
|
litros: float
|
|
distancia_km: float
|
|
rendimiento_km_litro: float
|
|
costo_por_km: Optional[float] = None
|
|
|
|
|
|
class ReporteConsumoVehiculo(BaseSchema):
|
|
"""Schema para reporte de consumo de un vehículo."""
|
|
|
|
vehiculo_id: int
|
|
vehiculo_nombre: str
|
|
vehiculo_placa: str
|
|
periodo_inicio: datetime
|
|
periodo_fin: datetime
|
|
|
|
# Totales
|
|
total_litros: float
|
|
total_cargas: int
|
|
total_costo: float
|
|
distancia_recorrida_km: float
|
|
|
|
# Promedios
|
|
rendimiento_promedio: float # km/litro
|
|
costo_promedio_litro: float
|
|
costo_por_km: float
|
|
|
|
# Detalle de cargas
|
|
cargas: List[CargaCombustibleResponse]
|
|
|
|
|
|
class ReporteConsumoFlota(BaseSchema):
|
|
"""Schema para reporte de consumo de toda la flota."""
|
|
|
|
periodo_inicio: datetime
|
|
periodo_fin: datetime
|
|
|
|
# Totales flota
|
|
total_litros: float
|
|
total_cargas: int
|
|
total_costo: float
|
|
total_vehiculos: int
|
|
|
|
# Promedios flota
|
|
rendimiento_promedio_flota: float
|
|
costo_promedio_flota: float
|
|
|
|
# Por vehículo
|
|
por_vehiculo: List[dict] # [{vehiculo_id, nombre, placa, litros, costo, rendimiento}]
|
|
|
|
# Por tipo de combustible
|
|
por_tipo_combustible: List[dict] # [{tipo, litros, costo}]
|