Inspiration

Delhi's air-quality dashboards always show a number, even when the monitors behind it were blank, frozen or reporting impossible values. India's official CPCB method says an AQI should not be published in those cases. I wanted to know how often a "Severe" headline is actually backed by data.

What it does

AQI Truth puts the official CPCB AQI method inside IBM Db2 and re-checks every monitor-hour of real Delhi data (OpenAQ public archive of CPCB monitors).

For each pollutant, Db2 computes the CPCB sub-index by linear interpolation within the breakpoint band that contains the concentration $C_p$:

$$ I_p = \frac{I_{HI} - I_{LO}}{B_{HI} - B_{LO}}\,\left(C_p - B_{LO}\right) + I_{LO} $$

$$ \text{AQI} = \max_{p}\; I_p $$

Under the CPCB rules, an AQI is valid only if at least 3 pollutants are available, one of them PM${2.5}$ or PM${10}$, and each 24-hour average has at least 16 valid hours. When the data cannot support a number, AQI Truth refuses to give one and explains why.

Results on 34 Delhi monitors (Sep–Dec 2025, 1.87 million readings, 4,148 station-days):

  • On 395 station-days, the CPCB rules allow no AQI at all.
  • A plain average still prints a number on 338 of them.
  • 147 of those would read Very Poor or Severe.

Every verdict comes with an append-only evidence entry and a hash-chained SHA-256 receipt that Db2 verifies against its own temporal history. If anyone edits a reading later, the receipt check fails.

How I built it

Db2 does the computing, not just the storage:

  • System-period temporal table, range-partitioned by month and loaded with MERGE, so any reading can be queried AS OF the time it was judged.
  • Window functions build the hourly layer and flag stuck sensors and impossible jumps.
  • SQL PL procedures apply the CPCB rules and write the verdicts.
  • Triggers make the evidence ledger append-only (SQLSTATE 75001 on update or delete).
  • RCAC row permission and column mask, plus a materialized query table (MQT) that the optimizer uses automatically, shown with EXPLAIN.
  • Hash-chained receipts: AQ.VERIFY_RECEIPT replays system-time history to detect tampering.
  • VECTOR + VECTOR_DISTANCE retrieve the rule text that IBM Granite cites in its explanations.
  • Least privilege: the app can only SELECT/INSERT; the question box runs as a read-only user that sees just two views.

Stack: Db2 Community Edition 12.1.5 (Docker), Python + FastAPI + ibm_db, IBM Granite on Ollama, a static web front end, pytest with CI on a fresh Db2 container.

Challenges I ran into

  • Turning the CPCB rulebook into set-based SQL PL that handles gaps, stuck sensors and partial days correctly.
  • Keeping the AI honest: Granite only explains what Db2 decided, and every number in its answer is checked against the database.
  • Running a live Db2 demo on a zero budget.

Accomplishments that I'm proud of

  • Real public data, not invented data.
  • A live engine judges can query, plus a "Try to tamper" button that shows Db2 catching an edited reading.
  • scripts/db2_evidence.py runs every Db2 claim as real SQL and records Db2's answers.

What I learned

Temporal tables, RCAC, MQTs and SQL PL together make Db2 a strong place for trust logic, because the database itself can prove what it knew and when.

What's next

  • Extend coverage to more Indian cities.
  • Run a scheduled job that checks for revisions to published data.
  • Offer a public API for journalists and researchers.

Links: Repo · Live site · Demo video · Submission PR

Built With

Share this project:

Updates

Submission history