diff --git a/src/static/dashboard.html b/src/static/dashboard.html new file mode 100644 index 0000000..b6561b1 --- /dev/null +++ b/src/static/dashboard.html @@ -0,0 +1,50 @@ + + + + Northern Thailand Ping River Monitor + + + +
+

🏔️ Northern Thailand Ping River Monitor API

+

Real-time water level monitoring system for the Ping River Basin in Northern Thailand

+
+ +
+

📊 Quick Status

+

API is running and monitoring 16 water stations along the Ping River

+

Coverage: From Chiang Dao to Nakhon Sawan

+

Data collection interval: Every hour

+
+ +
+

🔗 API Endpoints

+
GET /health - System health status
+
GET /metrics - Application metrics
+
GET /stations - List all monitoring stations
+
POST /stations - Add new monitoring station
+
PUT /stations/{station_id} - Update station information
+
GET /measurements/latest - Latest measurements
+
GET /measurements/station/{station_code} - Station-specific data
+
POST /scrape/trigger - Trigger manual data collection
+
GET /scraping/status - Scraping status
+
GET /docs - Interactive API documentation
+
+ +
+

📈 Monitoring

+

• Grafana dashboards available for data visualization

+

• Health checks monitor database, API, and system resources

+

• Metrics collection for performance monitoring

+
+ + diff --git a/src/web_api.py b/src/web_api.py index 7e22128..7cf9569 100644 --- a/src/web_api.py +++ b/src/web_api.py @@ -4,6 +4,7 @@ FastAPI web interface for water monitoring system """ import asyncio +import os from contextlib import asynccontextmanager from datetime import datetime, timedelta from typing import Any, Dict, List @@ -29,6 +30,15 @@ from .water_scraper_v3 import EnhancedWaterMonitorScraper logger = get_logger(__name__) +# Dashboard HTML is loaded once at import from src/static/dashboard.html. +_DASHBOARD_HTML_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static", "dashboard.html") +try: + with open(_DASHBOARD_HTML_PATH, encoding="utf-8") as _dashboard_file: + DASHBOARD_HTML = _dashboard_file.read() +except OSError as _dashboard_error: # pragma: no cover - defensive fallback + logger.error(f"Could not load dashboard HTML: {_dashboard_error}") + DASHBOARD_HTML = "

Northern Thailand Ping River Monitor API

See /docs.

" + # Global application state app_state = { @@ -176,59 +186,7 @@ async def background_scraping_task(): @app.get("/", response_class=HTMLResponse) async def root(): """Root endpoint with basic dashboard""" - html_content = """ - - - - Northern Thailand Ping River Monitor - - - -
-

🏔️ Northern Thailand Ping River Monitor API

-

Real-time water level monitoring system for the Ping River Basin in Northern Thailand

-
- -
-

📊 Quick Status

-

API is running and monitoring 16 water stations along the Ping River

-

Coverage: From Chiang Dao to Nakhon Sawan

-

Data collection interval: Every hour

-
- -
-

🔗 API Endpoints

-
GET /health - System health status
-
GET /metrics - Application metrics
-
GET /stations - List all monitoring stations
-
POST /stations - Add new monitoring station
-
PUT /stations/{station_id} - Update station information
-
GET /measurements/latest - Latest measurements
-
GET /measurements/station/{station_code} - Station-specific data
-
POST /scrape/trigger - Trigger manual data collection
-
GET /scraping/status - Scraping status
-
GET /docs - Interactive API documentation
-
- -
-

📈 Monitoring

-

• Grafana dashboards available for data visualization

-

• Health checks monitor database, API, and system resources

-

• Metrics collection for performance monitoring

-
- - - """ - return HTMLResponse(content=html_content) + return HTMLResponse(content=DASHBOARD_HTML) @app.get("/health", response_model=HealthResponse)