Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💧 WQI Calculator™

Water Quality Index Calculator — Weighted Arithmetic Method

Python Flask Bootstrap Chart.js License Deploy

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.


🌐 Live Demo

🔗 wqi-calculator.onrender.com


✨ Features

  • Manual Entry — Add any number of water quality parameters dynamically
  • Batch Upload — Upload .xlsx, .xls, or .csv files for bulk calculation
  • Exact Precision — Uses Python Decimal library 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

📐 WQI Formula

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), qi is treated as 0.
Custom weights can be provided to override the unit-weight formula.

WQI Classification

Range Status
0 – 25 🟢 Excellent
26 – 50 🟡 Good
51 – 75 🟠 Poor
76 – 100 🔴 Very Poor
> 100 ⛔ Unsuitable for Drinking

🗂️ Project Structure

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

🚀 Getting Started

Prerequisites

  • Python 3.10+
  • pip

Installation

# 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.py

Open your browser at http://localhost:5000


📊 Excel / CSV Upload Format

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 name
  • ci — Observed / measured value
  • si — Standard permissible value (0 is allowed)
  • weight — Custom weight (leave blank for auto unit-weight 1/Si)

Accepted formats: .xlsx .xls .csv


🔌 API Reference

POST /calculate

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
    }
  ]
}

POST /upload

Upload an Excel or CSV file.

  • Body: multipart/form-data with field file
  • Returns: Same schema as /calculate + filename

GET /sample

Returns 8 pre-filled sample parameters as JSON.


🛠️ Tech Stack

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)

☁️ Deployment (Render)

  1. Push code to GitHub
  2. Go to render.comNew Web Service
  3. Connect your GitHub repository
  4. Set:
    • Build Command: pip install -r requirements.txt
    • Start Command: gunicorn app:app
  5. Click Deploy

Your app will be live at:

https://your-app-name.onrender.com

🐛 Known Issues & Fixes

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

📄 License

This project is licensed under the MIT License — see LICENSE for details.


👨‍💻 Author

Aditya Kumar
Built with ❤️ using Flask + Python


© 2025 WQI Calculator™ — All Rights Reserved

About

WQI Calculator – A Flask-based web application to compute Water Quality Index with high precision (7 decimal accuracy), featuring data processing with Pandas and interactive visualizations using Chart.js.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages