Features: - Real-time water level monitoring for Ping River Basin (16 stations) - Coverage from Chiang Dao to Nakhon Sawan in Northern Thailand - FastAPI web interface with interactive dashboard and station management - Multi-database support (SQLite, MySQL, PostgreSQL, InfluxDB, VictoriaMetrics) - Comprehensive monitoring with health checks and metrics collection - Docker deployment with Grafana integration - Production-ready architecture with enterprise-grade observability CI/CD & Automation: - Complete Gitea Actions workflows for CI/CD, security, and releases - Multi-Python version testing (3.9-3.12) - Multi-architecture Docker builds (amd64, arm64) - Daily security scanning and dependency monitoring - Automated documentation generation - Performance testing and validation Production Ready: - Type safety with Pydantic models and comprehensive type hints - Data validation layer with range checking and error handling - Rate limiting and request tracking for API protection - Enhanced logging with rotation, colors, and performance metrics - Station management API for dynamic CRUD operations - Comprehensive documentation and deployment guides Technical Stack: - Python 3.9+ with FastAPI and Pydantic - Multi-database architecture with adapter pattern - Docker containerization with multi-stage builds - Grafana dashboards for visualization - Gitea Actions for CI/CD automation - Enterprise monitoring and alerting Ready for deployment to B4L infrastructure!
6.7 KiB
🏔️ Station Management Guide - Northern Thailand Ping River Monitor
🎯 Overview
The Northern Thailand Ping River Monitor now includes comprehensive station management capabilities, allowing you to dynamically add, update, and remove monitoring stations through the web API.
🌊 Current Coverage
The system currently monitors 16 water stations along the Ping River Basin:
Upper Ping River (Chiang Mai Province)
- P.20 - Ban Chiang Dao (บ้านเชียงดาว)
- P.75 - Ban Chai Lat (บ้านช่อแล)
- P.92 - Ban Muang Aut (บ้านเมืองกึ๊ด)
- P.4A - Ban Mae Taeng (บ้านแม่แตง)
- P.67 - Ban Tae (บ้านแม่แต)
- P.21 - Ban Rim Tai (บ้านริมใต้)
- P.103 - Ring Bridge 3 (สะพานวงแหวนรอบ 3)
Middle Ping River
- P.1 - Nawarat Bridge (สะพานนวรัฐ) - Main reference station
- P.82 - Ban Sob win (บ้านสบวิน)
- P.84 - Ban Panton (บ้านพันตน)
- P.81 - Ban Pong (บ้านโป่ง)
- P.5 - Tha Nang Bridge (สะพานท่านาง)
Lower Ping River
- P.77 - Baan Sop Mae Sapuord (บ้านสบแม่สะป๊วด)
- P.87 - Ban Pa Sang (บ้านป่าซาง)
- P.76 - Banb Mae I Hai (บ้านแม่อีไฮ)
- P.85 - Baan Lai Kaew (บ้านหล่ายแก้ว)
🔧 Station Management API
List All Stations
GET /stations
Response:
[
{
"station_id": 1,
"station_code": "P.20",
"thai_name": "บ้านเชียงดาว",
"english_name": "Ban Chiang Dao",
"latitude": 19.36731448032191,
"longitude": 98.9688487015384,
"geohash": null,
"status": "active"
}
]
Get Specific Station
GET /stations/{station_id}
Add New Station
POST /stations
Content-Type: application/json
{
"station_code": "P.NEW",
"thai_name": "สถานีใหม่",
"english_name": "New Station",
"latitude": 18.7875,
"longitude": 99.0045,
"geohash": "w5q6uuhvfcfp25",
"status": "active"
}
Update Station Information
PUT /stations/{station_id}
Content-Type: application/json
{
"thai_name": "ชื่อใหม่",
"english_name": "Updated Name",
"latitude": 18.8000,
"longitude": 99.0100
}
Delete Station
DELETE /stations/{station_id}
🧪 Testing Station Management
Use the provided test script to verify station management functionality:
# Test all station management endpoints
python test_station_management.py
This will:
- List existing stations
- Create a test station
- Retrieve station details
- Update station information
- Verify changes
- Delete the test station
- Confirm deletion
📊 Station Data Model
Required Fields
station_code
: Unique identifier (e.g., "P.1", "P.20")thai_name
: Thai language nameenglish_name
: English language name
Optional Fields
latitude
: GPS latitude coordinate (-90 to 90)longitude
: GPS longitude coordinate (-180 to 180)geohash
: Geohash string for locationstatus
: Station status ("active", "inactive", "maintenance", "error")
Validation Rules
- Station codes must be unique
- Latitude must be between -90 and 90
- Longitude must be between -180 and 180
- Names cannot be empty
- Status must be valid enum value
🌐 Web Interface
Access the station management interface through the web dashboard:
-
Start the API server:
python run.py --web-api
-
Open your browser:
- Dashboard: http://localhost:8000
- API Documentation: http://localhost:8000/docs
-
Use the interactive API docs to test station management endpoints
🔄 Integration with Data Collection
- Dynamic Station Discovery: New stations are automatically included in data collection
- Real-time Updates: Station information changes are reflected immediately
- Data Continuity: Historical data is preserved when updating station details
- Error Handling: Invalid stations are skipped during data collection
📍 Geographic Coverage
The Ping River Basin monitoring network covers:
- Total Distance: ~400 km from Chiang Dao to Nakhon Sawan
- Elevation Range: 300m to 1,200m above sea level
- Catchment Area: ~25,000 km²
- Major Cities: Chiang Mai, Lamphun, Tak, Nakhon Sawan
🚀 Usage Examples
Add a New Upstream Station
curl -X POST "http://localhost:8000/stations" \
-H "Content-Type: application/json" \
-d '{
"station_code": "P.UPSTREAM",
"thai_name": "สถานีต้นน้ำ",
"english_name": "Upstream Station",
"latitude": 19.5000,
"longitude": 98.9000,
"status": "active"
}'
Update Station Coordinates
curl -X PUT "http://localhost:8000/stations/1" \
-H "Content-Type: application/json" \
-d '{
"latitude": 19.3700,
"longitude": 98.9700
}'
Mark Station for Maintenance
curl -X PUT "http://localhost:8000/stations/5" \
-H "Content-Type: application/json" \
-d '{
"status": "maintenance"
}'
🔒 Best Practices
Station Naming
- Use consistent code format (P.XX)
- Include both Thai and English names
- Use descriptive location names
Coordinate Accuracy
- Use high-precision GPS coordinates (6+ decimal places)
- Verify coordinates match actual station location
- Include geohash for efficient spatial queries
Status Management
- Set status to "maintenance" during repairs
- Use "inactive" for temporarily offline stations
- Use "error" for stations with data quality issues
Data Integrity
- Test new stations before adding to production
- Backup station configuration before major changes
- Monitor data quality after station updates
🎯 Future Enhancements
Planned improvements for station management:
- Bulk Operations - Import/export multiple stations
- Station Groups - Organize stations by river section
- Automated Validation - GPS coordinate verification
- Historical Tracking - Track station configuration changes
- Alert Integration - Notifications for station status changes
- Map Interface - Visual station management on interactive map
📞 Support
For station management issues:
- Check the API documentation at
/docs
- Run the test script:
python test_station_management.py
- Review logs for error details
- Verify station data format and validation rules
The station management system provides flexible control over your monitoring network while maintaining data integrity and system reliability.