File size: 2,383 Bytes
c40c447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
Health check and system info endpoints.

Responsabilidad: Verificar el estado de la API y servicios.
"""

from fastapi import APIRouter, Depends
from typing import Dict, Any

from app.api.dependencies import get_forecast_model
from app.domain.interfaces.forecast_model import IForecastModel
from app.infrastructure.config.settings import get_settings
from app.utils.logger import setup_logger

logger = setup_logger(__name__)
settings = get_settings()

router = APIRouter(prefix="/health", tags=["Health"])


@router.get("", response_model=Dict[str, Any])
async def health_check(
    model: IForecastModel = Depends(get_forecast_model)
):
    """
    Health check endpoint.
    
    Verifica que la API est茅 funcionando y el modelo est茅 cargado.
    
    Returns:
        Estado de la API y informaci贸n del modelo
    """
    try:
        model_info = model.get_model_info()
        
        return {
            "status": "ok",
            "version": settings.api_version,
            "model": model_info,
            "message": "Chronos-2 API is running"
        }
    except Exception as e:
        logger.error(f"Health check failed: {e}")
        return {
            "status": "error",
            "version": settings.api_version,
            "error": str(e),
            "message": "API is running but model is not available"
        }


@router.get("/info", response_model=Dict[str, Any])
async def system_info():
    """
    System information endpoint.
    
    Returns:
        Informaci贸n sobre la arquitectura y configuraci贸n
    """
    return {
        "api": {
            "title": settings.api_title,
            "version": settings.api_version,
            "description": settings.api_description
        },
        "architecture": {
            "style": "Clean Architecture",
            "principles": "SOLID",
            "layers": [
                "Presentation (API)",
                "Application (Use Cases)",
                "Domain (Business Logic)",
                "Infrastructure (External Services)"
            ]
        },
        "model": {
            "id": settings.model_id,
            "device": settings.device_map
        },
        "endpoints": {
            "docs": "/docs",
            "health": "/health",
            "forecast": "/forecast",
            "anomaly": "/anomaly",
            "backtest": "/backtest"
        }
    }