A full-stack web application to compute the Water Quality Index (WQI) using the standard Weighted Arithmetic Method. Supports manual parameter entry, batch Excel/CSV upload, real-time visualization, and PDF report generation.
- Manual Entry — Add any number of water quality parameters dynamically
- Batch Upload — Upload
.xlsx,.xls, or.csvfiles for bulk calculation - Exact Precision — Uses Python
Decimallibrary for 7-decimal accurate WQI - Real-time Charts — Dual-axis bar + line chart (Sub-index & Contribution)
- PDF Report — Download a formatted water quality report with one click
- Load Sample — Pre-loaded with 8 standard WHO/BIS parameters
- Responsive Design — Works on desktop and mobile
- Dark Theme — Professional scientific dashboard aesthetic
The application uses the Brown et al. (1972) Weighted Arithmetic Method:
| Symbol | Description | Formula |
|---|---|---|
Ci |
Observed concentration | — |
Si |
Standard permissible value (WHO/BIS) | — |
qi |
Sub-index | (Ci / Si) × 100 |
Wi |
Unit weight | 1 / Si |
wi |
Normalised weight | Wi / ΣWi |
| WQI | Final Index | Σ (wi × qi) |
Note: If
Si = 0(e.g. Total Coliform, Faecal Coliform),qiis treated as0.
Custom weights can be provided to override the unit-weight formula.
| Range | Status |
|---|---|
| 0 – 25 | 🟢 Excellent |
| 26 – 50 | 🟡 Good |
| 51 – 75 | 🟠 Poor |
| 76 – 100 | 🔴 Very Poor |
| > 100 | ⛔ Unsuitable for Drinking |
WQI App/
├── app.py ← Flask backend + WQI calculation engine
├── requirements.txt ← Python dependencies
├── render.yaml ← Render deployment config
├── README.md
├── uploads/ ← Temporary upload storage
├── templates/
│ └── index.html ← HTML structure
└── static/
├── css/
│ └── style.css ← Dark theme styling
└── js/
└── main.js ← AJAX, chart, PDF logic
- Python 3.10+
- pip
# 1. Clone the repository
git clone https://github.com/yourusername/wqi-calculator.git
cd wqi-calculator
# 2. Create virtual environment
python3 -m venv venv
source venv/bin/activate # macOS / Linux
venv\Scripts\activate # Windows
# 3. Install dependencies
pip install -r requirements.txt
# 4. Run the app
python3 app.pyOpen your browser at http://localhost:5000
Your file must contain these columns:
| name | ci | si | weight (optional) |
|---|---|---|---|
| pH | 7.8 | 7.5 | 4 |
| Conductivity | 239.5 | 300 | 1 |
| DO | 7.4 | 5 | 2 |
| BOD | 1.5 | 5 | 2 |
| Total Coliform | 4100 | 0 | 3 |
| Faecal Coliform | 3430 | 0 | 3 |
name— Parameter nameci— Observed / measured valuesi— Standard permissible value (0is allowed)weight— Custom weight (leave blank for auto unit-weight1/Si)
Accepted formats: .xlsx .xls .csv
Calculate WQI from JSON input.
Request:
{
"parameters": [
{ "name": "pH", "ci": 7.8, "si": 7.5, "weight": 4 },
{ "name": "DO", "ci": 7.4, "si": 5.0, "weight": 2 }
]
}Response:
{
"wqi": 56.7888889,
"status": "Poor",
"color": "#f59e0b",
"parameters": [
{
"name": "pH",
"ci": 7.8,
"si": 7.5,
"qi": 104.0,
"wi_norm": 0.266667,
"contribution": 27.7333
}
]
}Upload an Excel or CSV file.
- Body:
multipart/form-datawith fieldfile - Returns: Same schema as
/calculate+filename
Returns 8 pre-filled sample parameters as JSON.
| Layer | Technology |
|---|---|
| Backend | Python 3, Flask 3 |
| Precision | Python decimal.Decimal |
| Data Processing | Pandas, OpenPyXL |
| Frontend | HTML5, Bootstrap 5.3 |
| Charts | Chart.js 4.4 |
| Icons | Bootstrap Icons 1.11 |
| Fonts | Space Mono, DM Sans |
| Deployment | Render (Gunicorn) |
- Push code to GitHub
- Go to render.com → New Web Service
- Connect your GitHub repository
- Set:
- Build Command:
pip install -r requirements.txt - Start Command:
gunicorn app:app
- Build Command:
- Click Deploy
Your app will be live at:
https://your-app-name.onrender.com
| Issue | Root Cause | Fix Applied |
|---|---|---|
Si = 0 crash |
Division by zero | qi = 0 when si == 0 |
0 value skipped |
JS: 0 == false |
Changed to ci !== "" check |
| Float rounding error | Binary float precision | Used decimal.Decimal |
| Excel column crash | Integer headers | str(c).strip().lower() |
| Upload fails on Render | No uploads/ directory |
tempfile + makedirs on startup |
This project is licensed under the MIT License — see LICENSE for details.
Aditya Kumar
Built with ❤️ using Flask + Python
© 2025 WQI Calculator™ — All Rights Reserved