Inspiration

Every Pakistani summer tells the same story: the mercury pushes past 48 °C, millions switch on their ACs between 6 and 10 PM, and the grid buckles under a peak it never saw coming. Load-shedding follows, then the bill shock from NEPRA's steep tiered slabs. The painful part is that most of this is predictable — demand tracks temperature, and temperature is forecastable. But the people who could act on it (dispatchers, households, regulators) are either flying blind or drowning in raw numbers and policy PDFs nobody reads. We wanted to turn Pakistan's weather and tariff data into decisions: how hot will it get, how confident are we, and what does the official policy actually say you should do about it.

What it does

Bijli-Insight Pakistan is an end-to-end energy-intelligence platform for the three major grid zones — Karachi (K-Electric), Lahore (LESCO), and Islamabad (IESCO). It:

  • Forecasts hourly temperature (a cooling-demand proxy) for the next 7 days with calibrated uncertainty — not a single guess, but a q10/q50/q90 band so a dispatcher sees the realistic worst case, not just the average.
  • Proves it's actually good: our model hits MAE 0.4023 °C vs a t-168 persistence baseline's 1.8795 °C — a 78.6% improvement — and reports error separately for peak hours, weekends, and heatwave days so the accuracy isn't hiding a blind spot.
  • Guards its own data: an autonomous Data Quality Agent audits every incoming reading with a deterministic FIX / FILL / FLAG protocol and logs every remediation.
  • Answers policy questions without hallucinating: a RAG agent grounded in official NEECA ECBC-2023 and NEPRA tariff documents cites its sources and says "I don't know" rather than inventing a clause or a price.
  • Estimates your bill against real NEPRA 2024 slabs and shows the savings from NEECA's 26 °C AC rule.
  • Runs itself: an hourly Prefect flow fetches live data, audits it, appends to the warehouse, and re-runs inference — all surfaced on a live HTML dashboard backed by a FastAPI service.

How we built it

A clean, reproducible pipeline, each stage verifiable:

  • Ingestion & provenance — ~52,632 hourly rows (3 cities, 2024–2026) from Open-Meteo, each raw CSV SHA-256 checksummed into an immutable manifest.csv so any tampering is caught before load.
  • Warehouse — a local, zero-setup 3-layer DuckDB (raw → cleaned_weather → gold_weather_features), with lag features (t-1, t-24, t-168), a 24-hour rolling mean, and leak-free window functions. Deterministic md5 row IDs anchor everything downstream.
  • Modeling — three LightGBM quantile boosters trained with pinball loss, post-processed to be non-crossing (q10 ≤ q50 ≤ q90), on a chronological 80/20 split to avoid future leakage.
  • Evaluation — a fairness/baseline evaluator comparing against t-168 persistence and checking empirical ~80% interval coverage.
  • RAG — NEECA/NEPRA PDFs indexed in ChromaDB with a hard relevance-threshold fallback.
  • Serving — a FastAPI backend (6 real-data endpoints) on Render, a static HTML/CSS/JS dashboard on Vercel as the primary frontend, and a legacy 5-tab Streamlit app for local exploration. The whole thing is backed by a 7-test suite.

Challenges we ran into

  • Quantile crossing — raw quantile models occasionally produced q10 > q50 from gradient noise, which is nonsensical for a confidence band; we enforced monotonic post-processing.
  • Not destroying real signal — naively dropping bad rows breaks time-series continuity, and clamping extreme readings erases the exact heatwave peaks the grid cares about. The Tri-Action protocol had to fill small gaps but flag (never alter) physical outliers.
  • Preventing leakage — getting lag/rolling features right with partitioned window queries so the model never peeks at the future.
  • A trustworthy RAG — making the agent refuse out-of-scope questions instead of confidently fabricating tariff numbers.
  • Deployment reality — splitting a Python backend (Render) from a static frontend (Vercel) meant wrestling CORS and a graceful demo-curve fallback so the dashboard still shows something if the backend is cold.
  • Encoding gremlins — degree signs, emojis, and Urdu subtitles turned into mojibake across tools and had to be cleaned repeatedly.

Accomplishments that we're proud of

  • A 78.6% MAE improvement over a real, declared baseline — with honest per-slice breakdowns instead of a single flattering number.
  • Calibrated uncertainty, not just a point forecast — the output a grid operator can actually plan against.
  • A RAG assistant that cites official sources and admits ignorance — no hallucinated policy.
  • A fully reproducible, verifiable pipeline: checksummed data, a 3-layer warehouse, an auditable quality log, and a passing test suite — the kind of provenance a jury or a regulator can trust.
  • Real data end-to-end — every chart, number, and answer traces back to a verified source, not a hardcoded demo.

What we learned

  • For critical infrastructure, uncertainty bounds matter more than point accuracy — a dispatcher needs the q90, not the average.
  • A simple honest baseline (t-168) is the single most persuasive thing you can show; "better than nothing" has to be measured.
  • Grounding beats fluency — an LLM that says "I don't know" is worth more than an eloquent one that invents a tariff.
  • Data quality is a first-class system, not a preprocessing afterthought — and how you handle bad data (fill vs. flag) changes what the model learns.
  • Boring, local tools (DuckDB, LightGBM) go a very long way before you need anything heavier.

What's next for Bijli-Insight Pakistan

  • Forecast actual load (MW/kWh), not just temperature, by partnering for DISCO consumption data — temperature is the proxy; demand is the goal.
  • Real-time grid alerts — push warnings to dispatchers when the q90 band signals an imminent peak-hour surge.
  • More zones — extend beyond Karachi/Lahore/Islamabad to the full set of DISCOs.
  • Solar & rooftop-generation signals to model net demand as distributed solar grows.
  • Urdu-language policy assistant so the RAG guidance reaches households directly, not just operators.
  • Automated retraining and drift monitoring on the hourly Prefect flow, with continuous calibration checks as the climate baseline shifts.

Built With

  • autogpt
  • babyagi
  • duckdb
  • langgraph
  • lightgbm
  • numpy
  • other-prefect-(not-airflow)-agentic-ai-frameworks-crewai
  • pandas
  • prefect
  • pydantic
  • python
  • rag
  • scikit-learn
  • streamlit
Share this project:

Updates