How it works

How this serviceworks

A decision aid for schools: is outdoor practice a good idea near this monitoring station, today and over the next days? It shows two separate signals and never mixes them.

Open the dashboard

Two signals, kept apart

  • Right now

    The official air-quality index published for the station, refreshed every hour. A reading that is more than a few hours old is shown as no current reading.

  • The next days

    An estimate of each day's mean concentration, graded on the official category scale. Below the health-threshold category a day reads Go, at that category Caution, and above it Not recommended.

  • No data is never a clearance

    When a forecast is missing, old or incomplete, the page says so in grey. Silence is never shown as Go.

From sensor to verdict

One path, run every hour. Each step hands the next only what it has checked.

  1. Sources

    3 feeds

    Hourly sensor readings, the official index feed, and weather data.

    • OpenAQ · hourly readings
    • CPCB · official index
    • ERA5, Open-Meteo · weather
  2. Collect

    Airflow · every hour

    Pulled on a schedule with retries and rate limiting. Units are converted on the way in; a unit that cannot be trusted is skipped, not guessed.

  3. Store

    PostgreSQL + TimescaleDB

    Raw rows are kept as they arrived. Duplicate stations are merged and impossible values are dropped when read, so every later step sees the same hour.

  4. Estimate

    per region

    Each of the next days is estimated from the station's last 24 hours and the day-to-day spread in a year of that region's history: a low, an expected and a high value.

  5. Grade

    official category scale

    A day gets the worst category its mean reaches with at least a 40% chance. The verdict follows from that category.

  6. Serve

    FastAPI

    One API feeds this site and a daily email. The site decides nothing: every category and verdict it shows was computed on the server.

    • This site
    • Daily email

every hour and every night

Check

A watchdog looks at every region each hour and raises an alert when data stops arriving or coverage drops. Every night, past estimates are scored against what was measured.

One hour of the pipeline

The jobs start at fixed minutes past every hour (UTC), each after the one it depends on.

:10:30:40:45:55
  1. :10Collect readingssensor hours from OpenAQ
  2. :30Build featuresthe last-24-hour mean per station
  3. :40Official indexcurrent AQI from the CPCB feed
  4. :45Estimate and gradefive days per station
  5. :55Watchdogper region: stale data, low coverage

Slower cycles

  • Every nightScore past estimates against measurements
  • Every nightSwitch off stations that went dark, and back on when they return
  • Every eveningSend the daily email
  • Every weekRefit each region's day-to-day spread

How one verdict is made

A worked example with made-up numbers. The station's mean over the last 24 hours was 80.

  1. Start from the last 24 hours

    Nothing beat this in backtests: the next days look more like the last one than like any model's guess.

  2. Widen it day by day

    A year of the region's history says how far a day's mean usually lands from the previous 24 hours. That gives a low, an expected and a high value, and the range grows with each day ahead.

  3. Grade the 40% point

    If the day's mean has at least a 40% chance of reaching a worse category, the day takes that category. In this example that happens from day four.

24 h80
  • Day 1Go
  • Day 2Go
  • Day 3Go
  • Day 4Caution
  • Day 5Caution

Line: low to high · diamond: expected · tick: the 40% point

The worst day decides the overall verdict.

What is never shown as safe

Each of these ends in a neutral answer, and none of them can read as Go.

  • The newest official reading is more than 6 hours oldNo current reading
  • The newest sensor hour is more than 24 hours oldNo outlook
  • One of the forecast days is missingNo overall verdict
  • A region has under 180 days of history from 3 stationsNo outlook, never another city's numbers
  • A sensor reports a physically impossible valueThat hour counts as missing
  • A reading's unit cannot be verifiedSkipped, not converted by guess

How good is it?

Each region is backtested on held-out periods of past data: the grade the estimate gave is compared with the grade that was measured. The figures below are one row per region that has been checked.

The estimate follows the air about a day behind, so it cannot foresee a sudden change. Several machine-learning models (gradient-boosted trees per station and pooled, with and without weather) were backtested against this simple rule. None did better, so the simpler and better-calibrated rule is the one in service.

Nightly evaluation results

Found in production, and fixed

Four problems that only real data showed.

  • 2,938,322

    µg/m³ in one reading

    A sensor fault was stored as a measurement and became training data; one forecast reached 8,243. Readings outside a plausible range are now dropped wherever they are read.

  • 1.88×

    too much NO₂ for five days

    A provider's unit label was trusted and the values converted. A second, independent source exposed it. A unit is now verified per region before it is used.

  • 64 of 68

    stations read Not recommended

    The first rule flagged a day when a single hour was high, while the air was Moderate. Days are now graded by their mean, as the official scale defines them.

  • 7 → 73

    stations with a forecast

    Official data arrives about twelve hours late, and a six-hour freshness limit rejected nearly all of it. The limit now matches how the data really arrives.

Built with

  • Python
  • Apache Airflow
  • PostgreSQL + TimescaleDB
  • FastAPI
  • LightGBM (backtests)
  • Docker Compose
  • Caddy
  • TypeScript
  • React + TanStack Start
  • Tailwind CSS
  • Cloudflare Workers

Source code