A comprehensive web application for monitoring and analyzing heavy metal contamination in groundwater using the Heavy Metal Pollution Index (HMPI) methodology.
- Interactive Geospatial Map: Leaflet.js-based map with contamination heatmap
- Data Analysis Dashboard: Upload CSV/Excel files for automatic HMPI calculation
- Timeline Analysis: Track contamination trends over time
- Health Impact Assessment: Population health metrics and risk analysis
- Alert System: Real-time contamination alerts and notifications
- Remediation Suggestions: Treatment methods and implementation strategies
- Automated HMPI Calculation: Standard WHO/BIS methodology
- File Upload Support: CSV and Excel file processing
- Health Metrics: Hazard Quotient (HQ) and Hazard Index (HI)
- Risk Assessment: Categorize water quality based on HMPI values
- Data Visualization: Generate charts and graphs
- CORS Support: Configured for React frontend integration
- Node.js 18+ and npm
- Python 3.8+
- Git
git clone <repository-url>
cd hmpicd backend
python setup.pyOr manually:
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtcd backend
python main.pyThe API will be available at http://localhost:8000
# In the root directory
npm install
npm run devThe frontend will be available at http://localhost:3000
The system uses the standard HMPI formula:
Qi = (Mi / Si) ร 100
HMPI = (ฮฃ WiยทQi) / (ฮฃ Wi)
HQ = Mi / Si
HI = ฮฃ HQ
Where:
- Mi: Measured concentration of metal i
- Si: Standard permissible limit for metal i
- Wi: Unit weight for metal i
- Qi: Quality index for metal i
- HQ: Hazard Quotient
- HI: Hazard Index
| Metal | Standard Limit (mg/L) | Unit Weight |
|---|---|---|
| Lead (Pb) | 0.01 | 0.15 |
| Cadmium (Cd) | 0.003 | 0.20 |
| Mercury (Hg) | 0.001 | 0.25 |
| Arsenic (As) | 0.01 | 0.18 |
| Chromium (Cr) | 0.05 | 0.12 |
| Nickel (Ni) | 0.02 | 0.10 |
| Zinc (Zn) | 3.0 | 0.05 |
| Copper (Cu) | 2.0 | 0.08 |
| Iron (Fe) | 0.3 | 0.03 |
| Manganese (Mn) | 0.1 | 0.04 |
| Aluminum (Al) | 0.2 | 0.02 |
| Category | HMPI Range | Description |
|---|---|---|
| Safe | 0-25 | Excellent water quality |
| Moderate | 25-50 | Good water quality |
| Risky | 50-75 | Requires attention |
| High Risk | 75-100 | Poor water quality |
| Critical | 100+ | Extremely poor quality |
- GET
/- API information - GET
/health- Health check - GET
/standards- Standard limits and unit weights - POST
/calculate- Upload file for HMPI calculation - POST
/calculate-direct- Direct calculation from concentration values
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
hmpi/
โโโ backend/ # FastAPI backend
โ โโโ main.py # Main API application
โ โโโ requirements.txt # Python dependencies
โ โโโ setup.py # Setup script
โ โโโ test_api.py # API test suite
โ โโโ sample_data.csv # Sample data file
โ โโโ README.md # Backend documentation
โโโ src/ # React frontend
โ โโโ components/ # React components
โ โ โโโ DataAnalysis.tsx
โ โ โโโ GeospatialMap.tsx
โ โ โโโ LeafletMap.tsx
โ โ โโโ ui/ # UI components
โ โโโ App.tsx # Main application
โ โโโ main.tsx # Entry point
โโโ package.json # Frontend dependencies
โโโ README.md # This file
cd backend
python test_api.pynpm run dev
# Open http://localhost:3000Sample_ID,Lead (Pb),Cadmium (Cd),Mercury (Hg),Arsenic (As),Chromium (Cr)
Sample_001,0.008,0.002,0.0008,0.007,0.03
Sample_002,0.015,0.004,0.0012,0.012,0.08Same structure as CSV, but in Excel format (.xlsx or .xls)
The React frontend automatically connects to the FastAPI backend:
// API calls are handled in DataAnalysis.tsx
const response = await fetch('http://localhost:8000/calculate', {
method: 'POST',
body: formData
});The backend is configured to accept requests from:
http://localhost:3000http://localhost:3001http://localhost:3002http://localhost:3003
cd backend
uvicorn main:app --reload --host 0.0.0.0 --port 8000npm run dev- Upload CSV/Excel files with metal concentration data
- Automatic HMPI calculation using standard methodology
- Health metrics calculation (HQ, HI)
- Risk categorization and assessment
- Interactive visualizations
- Interactive Leaflet.js map
- Contamination heatmap overlay
- Location-based HMPI visualization
- Zoom and pan functionality
- Detailed location reports
- Population health risk analysis
- Chronic disease risk assessment
- Community impact evaluation
- Treatment recommendations
- Historical contamination trends
- Predictive analysis
- Seasonal variation tracking
- Long-term monitoring
# Using uvicorn
uvicorn main:app --host 0.0.0.0 --port 8000
# Using gunicorn (production)
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorkernpm run build
# Deploy the 'dist' folder to your hosting service- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.
For support and questions:
- Check the documentation at
/docsendpoint - Review the test suite in
backend/test_api.py - Check the sample data format in
backend/sample_data.csv
- Database integration for data persistence
- Real-time data streaming
- Machine learning predictions
- Mobile app development
- Advanced visualization options
- Multi-language support
- User authentication and authorization
- Data export functionality
- Integration with IoT sensors
- Automated report generation