Full-stack HMPI tool for uploading water quality heavy metal data, computing HMPI, visualizing charts and hotspot maps, and exporting results.
- Frontend: React (Vite), Tailwind CSS, Framer Motion, Recharts, React-Leaflet
- Backend: Node.js, Express.js
- Database: PostgreSQL
backend/– Express API, HMPI logic, CSV/XLSX parsing, exportsfrontend/– React app with dark UI, charts, maps
- PostgreSQL
- Ensure Postgres is running and a database named
hmpiexists (or setPGDATABASEin.env).
- Backend setup
# In backend/
copy .env.example .env # Windows PowerShell: copy .env.example .env
npm install
npm run db:init
npm run db:seed
npm run devBackend runs at http://localhost:5000, health at /api/health.
- Frontend setup
# In frontend/
npm install
npm run devFrontend (Vite) runs at http://localhost:5173 and proxies /api to the backend.
PORT– API port, default 5000- Either
DATABASE_URLor discrete paramsPGHOST,PGPORT,PGUSER,PGPASSWORD,PGDATABASE PGSSL–falsefor local
See backend/.env.example for a template.
POST /api/data– Create a record{ metal_type, concentration, latitude, longitude, timestamp }POST /api/data/upload– Upload CSV/XLSX (field:file)GET /api/data– List all rowsGET /api/data/:id– Get row by idGET /api/hmpi/:id– Compute HMPI for the group (same lat/lng/timestamp as:id)GET /api/export/csv?latitude=..&longitude=..×tamp=..– Export CSV for a groupGET /api/export/pdf?latitude=..&longitude=..×tamp=..– Export PDF for a group
We use the sub-index method in backend/src/services/hmpiService.js:
Qi = (Mi / Si) * 100Wi = 1 / SiHMPI = Σ(Qi * Wi) / Σ(Wi)- Limits
Si(µg/L): Pb=10, Cd=3, As=10, Hg=6, Cr=50 - Categories: Safe (<50), Moderate (50–100), Hazardous (>100)
You can adjust limits and thresholds in hmpiService.js.
A sample CSV is provided at backend/sample_data/sample.csv. You can upload this from the Upload page or seed using npm run db:seed.
CSV Expected Columns: metal_type, concentration, latitude, longitude, timestamp
- Home: hero with quick links
- Upload: form + file upload with validations
- Dashboard: table, charts, and map of hotspots
- About: method and thresholds
- CSV: tabular export of group with computed HMPI/category
- PDF: succinct report with summary and measurements
- Animations via Framer Motion; charts via Recharts; maps via React-Leaflet + OpenStreetMap tiles
- Mobile-first, dark theme by default with toggle in navbar
backend:npm run db:init,npm run db:seed,npm run devfrontend:npm run dev,npm run build,npm run preview
MIT (add your preferred license)