"""New York's air against ten other big cities', 2005-2025: the analysis behind a SparkyData article.

    py src/build_article.py air-in-big-cities

Nitrogen dioxide (NO2) and fine particles (PM2.5), annual means in micrograms per cubic metre, for New York City and
ten other big cities (card ``world_city_air``, loader ``nycdata.world_air``): New York, Cook County (Chicago) and Los
Angeles County from the EPA's yearly file of every regulatory monitor; London (Defra), Berlin (the Senate's network),
Vienna (the City), Madrid (the City), Toronto and Montréal (the federal NAPS network), Tokyo (the Metropolitan
Government) and Singapore (the NEA) from each network's own figures.

Each city is compared with itself: its first three years from 2005 (Vienna's network mean starts in 2010; London's,
Berlin's, Vienna's and Tokyo's fine particles start later) against its latest three (2023-2025, or 2022-2024 where a
network's 2025 is not out), the change read with a range from the years' own spread (``sparkylib.stats
.mean_difference``, years as draws around each period's level). Levels set side by side are an observed order of
networks that measure in different places, said so on the page; WHO's 2021 guideline levels are read from a quote. Two
dated New York measures are set against the same windows elsewhere: the heating-oil rules (No. 6 oil phased out by
2015) and congestion pricing (from January 2025), with what the citywide means can and cannot attribute. What each
city has done comes from its own documents, quoted (``RESPONSES``), never as a cause.

Writes results.json, viz.json, charts.json, data.csv and build.json into output/articles/air_in_big_cities/ and
site/public/articles/air-in-big-cities/, and copies this script there as analysis.py. Deterministic: no sampling, and
SEED is kept for any resampling.
"""

from __future__ import annotations

import math
import re
from statistics import mean

import pandas as pd

from article_kit import Article, lines, r, strip
from nycdata import world_air as W
from sparkylib.stats import mean_difference

SLUG = "air-in-big-cities"
SEED = 20261120
FROM = 2005                    # the first year of the comparison (the EPA's yearly files are read from 2005)
LAST = 2025
OIL = ((2005, 2007), (2009, 2011), (2016, 2018))   # before and after the heating-oil rules (announced 2011, No. 6 oil out by 2015)
STALL = (2015, 2017)           # chosen from the series: Cook County's level shows no clear change between then and 2023-2025
PRE_TOLL = (2022, 2024)        # the last three years before the congestion toll began (5 January 2025)
RECENT = (2017, 2019)          # the last three years before 2020, against each city's latest three
PLATEAU = (2020, 2022)         # New York's level since 2020
#: The cities, New York first: (key in world_air, label).
CITIES = [("new_york", "New York"), ("chicago", "Chicago"), ("los_angeles", "Los Angeles"), ("london", "London"),
          ("berlin", "Berlin"), ("vienna", "Vienna"), ("madrid", "Madrid"), ("toronto", "Toronto"),
          ("montreal", "Montréal"), ("tokyo", "Tokyo"), ("singapore", "Singapore")]
LABEL = dict(CITIES)
WORLD_LINES = ["new_york", "london", "madrid", "tokyo", "berlin", "singapore"]
US_LINES = ["new_york", "chicago", "los_angeles"]
POLLUTANT = {"no2": "nitrogen dioxide", "pm25": "fine particles (PM2.5)"}


def window(s: pd.Series, first: bool) -> tuple[int, int]:
    """A city's first three consecutive years from FROM, or its latest three."""
    years = [int(y) for y in s.index if y >= FROM]
    runs = [y for y in years if y + 1 in years and y + 2 in years]
    a = runs[0] if first else runs[-1]
    return a, a + 2


def values_in(s: pd.Series, a: tuple[int, int]) -> list[float]:
    x = s.loc[a[0]:a[1]]
    if len(x) != a[1] - a[0] + 1:
        raise ValueError(f"missing years in {a}: {list(x.index)}")
    return [float(v) for v in x]


def main(argv: list[str] | None = None) -> int:
    """Run the analysis and write every file (no options)."""
    A = Article(SLUG, __file__, seed=SEED)
    # every series stops at LAST, so a living file that gains a year cannot move a window
    F = {p: {k: W.annual(k, p).set_index("year").loc[:LAST] for k, _ in CITIES} for p in W.POLLUTANTS}
    S = {p: {k: F[p][k]["value"].astype(float) for k, _ in CITIES} for p in W.POLLUTANTS}

    def sites_in(k, p, a):
        n = F[p][k]["sites"].loc[a[0]:a[1]]
        return None if n.isna().all() else [int(n.min()), int(n.max())]

    # ---- each city and pollutant: its first three years against its latest three
    cities = {}
    for k, label in CITIES:
        cities[k] = {"label": label, "area": W.AREAS[k][0], "publisher": W.AREAS[k][1]}
        for p in W.POLLUTANTS:
            s = S[p][k]
            e, l_ = window(s, True), window(s, False)
            md = mean_difference(values_in(s, e), values_in(s, l_), nd=4)
            # lo_pct and hi_pct are the range of the change in micrograms as a percentage of the first years' mean: not a
            # range for the percentage change, which would also carry that mean's uncertainty (outside review, 15 November)
            cities[k][p] = {"early_years": list(e), "late_years": list(l_), "early": md["before"], "late": md["after"],
                            "change": md["change"], "lo": md["lo"], "hi": md["hi"], "direction": md["direction"],
                            "change_pct": r(100 * (md["after"] / md["before"] - 1), 2),
                            "lo_pct": r(100 * md["lo"] / md["before"], 2), "hi_pct": r(100 * md["hi"] / md["before"], 2),
                            "sites_early": sites_in(k, p, e), "sites_late": sites_in(k, p, l_),
                            "latest": {"year": int(s.index.max()), "value": r(float(s.iloc[-1]), 4)}}
    A.results["cities"] = cities
    ny_sites = {p: (cities["new_york"][p]["sites_early"], cities["new_york"][p]["sites_late"]) for p in W.POLLUTANTS}
    assert ny_sites == {"no2": ([4, 5], [3, 3]), "pm25": ([9, 11], [5, 7])}, f"the page and the chart note give these counts: {ny_sites}"
    order = {p: sorted(cities, key=lambda k: -cities[k][p]["late"]) for p in W.POLLUTANTS}
    fall = sorted(cities, key=lambda k: cities[k]["no2"]["change_pct"])
    from_2005 = [k for k in cities if cities[k]["no2"]["early_years"][0] == FROM]
    A.results["order"] = {"no2_late": order["no2"], "pm25_late": order["pm25"], "no2_fall": fall,
                          "no2_early_from_2005": sorted(from_2005, key=lambda k: -cities[k]["no2"]["early"]),
                          "new_york_no2_late_rank": order["no2"].index("new_york") + 1,
                          "new_york_no2_fall_rank": fall.index("new_york") + 1,
                          "new_york_pm25_late_rank_from_lowest": order["pm25"][::-1].index("new_york") + 1,
                          "pm25_within_half_of_new_york": [k for k in cities if abs(cities[k]["pm25"]["late"] - cities["new_york"]["pm25"]["late"]) < 0.5],
                          "no2_fell_by_more_than_a_third": [k for k in cities if cities[k]["no2"]["change_pct"] < -100 / 3],
                          "no2_no_clear_change": [k for k in cities if cities[k]["no2"]["direction"] != "down"]}
    o = A.results["order"]
    assert o["no2_early_from_2005"][0] == "new_york" and o["new_york_no2_late_rank"] == 2 and o["no2_late"][0] == "chicago", o
    assert o["no2_no_clear_change"] == ["singapore"] and len(o["no2_fell_by_more_than_a_third"]) == 10, o
    assert sorted(o["pm25_within_half_of_new_york"]) == ["london", "montreal", "new_york", "toronto"], o
    assert all(cities[k]["pm25"]["direction"] == "down" for k in ("new_york", "london", "berlin", "tokyo")), "PM2.5 falls"

    # ---- the EPA areas on a fixed panel: only the sites with a value in all six years of both windows
    panel = {}
    for k in ("new_york", "chicago", "los_angeles"):
        panel[k] = {}
        for p in W.POLLUTANTS:
            c = cities[k][p]
            e, l_ = range(c["early_years"][0], c["early_years"][1] + 1), range(c["late_years"][0], c["late_years"][1] + 1)
            piv = W.epa_sites(k, p).pivot(index="site", columns="year", values="value")
            keep = [s for s in piv.index if all(y in piv.columns and pd.notna(piv.loc[s, y]) for y in [*e, *l_])]
            if not keep:
                panel[k][p] = None
                continue
            md = mean_difference([float(piv.loc[keep, y].mean()) for y in e], [float(piv.loc[keep, y].mean()) for y in l_], nd=4)
            panel[k][p] = {"sites": keep, "n": len(keep), "early": md["before"], "late": md["after"], "lo": md["lo"],
                           "hi": md["hi"], "direction": md["direction"], "change_pct": r(100 * (md["after"] / md["before"] - 1), 2)}
    A.results["panel"] = panel
    assert panel["new_york"]["no2"]["n"] == 2 and panel["new_york"]["pm25"]["n"] == 2, panel["new_york"]
    assert panel["new_york"]["no2"]["direction"] == "down" and panel["new_york"]["pm25"]["direction"] == "down"

    # ---- since 2017-2019: every city's nitrogen dioxide, and New York's change against each other city's
    recent, versus = {}, {}
    for k in cities:
        s, l_ = S["no2"][k], cities[k]["no2"]["late_years"]
        md = mean_difference(values_in(s, RECENT), values_in(s, tuple(l_)), nd=4)
        recent[k] = {**{x: md[x] for x in ("before", "after", "change", "lo", "hi", "direction")},
                     "change_pct": r(100 * (md["after"] / md["before"] - 1), 2), "late_years": l_}
        if k != "new_york":
            ny_s = S["no2"]["new_york"]
            gap_early = [math.log(ny_s[y] / s[y]) for y in range(RECENT[0], RECENT[1] + 1)]
            gap_late = [math.log(ny_s[y] / s[y]) for y in range(l_[0], l_[1] + 1)]
            mv = mean_difference(gap_early, gap_late, nd=4)
            versus[k] = {"gap_before": mv["before"], "gap_after": mv["after"], "change": mv["change"], "lo": mv["lo"],
                         "hi": mv["hi"], "direction": mv["direction"],
                         "new_york_relative_pct": r(100 * (math.exp(mv["change"]) - 1), 3),
                         "new_york_relative_lo_pct": r(100 * (math.exp(mv["lo"]) - 1), 3),
                         "new_york_relative_hi_pct": r(100 * (math.exp(mv["hi"]) - 1), 3)}
    A.results["recent"], A.results["recent_vs_new_york"] = recent, versus
    faster = [k for k in versus if versus[k]["direction"] == "up"]
    assert recent["new_york"]["direction"] == "down" and all(k in faster for k in ("london", "berlin", "madrid")), faster
    A.results["order"]["fell_clearly_faster_than_new_york_since_2017_2019"] = faster

    # ---- the same comparison ending before the toll began in January 2025: 2017-2019 against 2022-2024, New York and the
    # three European cities the title names (outside review, 15 November 2026: the latest three years include 2025)
    pre_toll = {}
    for k in ("new_york", "london", "berlin", "madrid"):
        s = S["no2"][k]
        md = mean_difference(values_in(s, RECENT), values_in(s, PRE_TOLL), nd=4)
        pre_toll[k] = {**{x: md[x] for x in ("before", "after", "change", "lo", "hi", "direction")},
                       "change_pct": r(100 * (md["after"] / md["before"] - 1), 2)}
        if k != "new_york":
            ny_s = S["no2"]["new_york"]
            mv = mean_difference([math.log(ny_s[y] / s[y]) for y in range(RECENT[0], RECENT[1] + 1)],
                                 [math.log(ny_s[y] / s[y]) for y in range(PRE_TOLL[0], PRE_TOLL[1] + 1)], nd=4)
            pre_toll[k]["against_new_york"] = {"change": mv["change"], "lo": mv["lo"], "hi": mv["hi"], "direction": mv["direction"],
                                               "new_york_relative_pct": r(100 * (math.exp(mv["change"]) - 1), 3),
                                               "new_york_relative_lo_pct": r(100 * (math.exp(mv["lo"]) - 1), 3),
                                               "new_york_relative_hi_pct": r(100 * (math.exp(mv["hi"]) - 1), 3)}
    A.results["pre_toll"] = pre_toll
    assert all(pre_toll[k]["direction"] == "down" for k in pre_toll), "the page says all four fell before the toll"
    assert all(pre_toll[k]["against_new_york"]["direction"] == "up" and pre_toll[k]["change_pct"] < -25
               for k in ("london", "berlin", "madrid")), \
        "the page says each of the three fell by more than a quarter before the toll, each gap with New York larger than the years' spread"

    # ---- New York and the two other US areas since 2015-2017 and 2020-2022, on the same federal rules
    since = {}
    for k in US_LINES:
        since[k] = {}
        for name, a in (("2015_2017", STALL), ("2020_2022", PLATEAU)):
            md = mean_difference(values_in(S["no2"][k], a), values_in(S["no2"][k], (2023, 2025)), nd=4)
            since[k][name] = {**{x: md[x] for x in ("before", "after", "change", "lo", "hi", "direction")},
                              "change_pct": r(100 * (md["after"] / md["before"] - 1), 2)}
    chicago_to_2015 = mean(values_in(S["no2"]["chicago"], STALL))
    since["chicago"]["fall_to_2015_2017_pct"] = r(100 * (chicago_to_2015 / cities["chicago"]["no2"]["early"] - 1), 2)
    A.results["since"] = since
    # every city with a 2025 value, since 2020-2022: which kept falling while New York's held level
    since_2020 = {}
    for k in cities:
        if cities[k]["no2"]["late_years"] == [2023, 2025]:
            md = mean_difference(values_in(S["no2"][k], PLATEAU), values_in(S["no2"][k], (2023, 2025)), nd=4)
            since_2020[k] = {**{x: md[x] for x in ("before", "after", "lo", "hi", "direction")},
                             "change_pct": r(100 * (md["after"] / md["before"] - 1), 2)}
    A.results["since_2020"] = since_2020
    assert [k for k in ("london", "berlin", "vienna", "los_angeles") if since_2020[k]["direction"] != "down"] == []
    assert since_2020["new_york"]["direction"] == "unclear"
    assert since["chicago"]["2015_2017"]["direction"] == "unclear" and since["new_york"]["2015_2017"]["direction"] == "down"
    assert since["new_york"]["2020_2022"]["direction"] == "unclear" and since["los_angeles"]["2015_2017"]["direction"] == "down"

    # ---- fine particles: New York without 2023, and Berlin within its light-scattering years
    pm = S["pm25"]
    ny_late_no_2023 = mean([pm["new_york"][2024], pm["new_york"][2025]])
    bl = mean_difference(values_in(pm["berlin"], (2017, 2019)), values_in(pm["berlin"], (2023, 2025)), nd=4)
    A.results["pm25_checks"] = {
        "new_york_2023": r(float(pm["new_york"][2023]), 4), "new_york_2024_2025": r(ny_late_no_2023, 4),
        "new_york_change_without_2023_pct": r(100 * (ny_late_no_2023 / cities["new_york"]["pm25"]["early"] - 1), 2),
        "berlin_light_scattering": {**{x: bl[x] for x in ("before", "after", "lo", "hi", "direction")},
                                    "change_pct": r(100 * (bl["after"] / bl["before"] - 1), 2)}}
    assert bl["direction"] == "down"
    assert pm["new_york"][2023] > max(pm["new_york"][2022], pm["new_york"][2024]), "the page says 2023 stands out"

    # ---- the heating-oil rules (2011) as timing: New York's fine particles before and after the announcement
    oil = [mean(values_in(pm["new_york"], a)) for a in OIL]
    A.results["heating_oil"] = {"windows": [list(a) for a in OIL], "means": [r(x, 4) for x in oil],
                                "before_pct": r(100 * (oil[1] / oil[0] - 1), 2), "after_pct": r(100 * (oil[2] / oil[1] - 1), 2)}

    # ---- congestion pricing's first year, citywide, both pollutants (single years, no range)
    A.results["congestion"] = {p: {"2024": r(float(S[p]["new_york"][2024]), 4), "2025": r(float(S[p]["new_york"][2025]), 4),
                                   "change_pct": r(100 * (S[p]["new_york"][2025] / S[p]["new_york"][2024] - 1), 2)}
                               for p in W.POLLUTANTS}
    A.results["new_york_no2_2020"] = r(float(S["no2"]["new_york"][2020]), 4)

    # ---- the policies against the history (owner, 14 November 2026): the years the story sets beside each measure
    ny_no2 = S["no2"]["new_york"]
    A.results["new_york_no2_by_year"] = {str(y): r(float(ny_no2[y]), 4) for y in range(2019, LAST + 1)}
    high = max(range(2020, LAST + 1), key=lambda y: ny_no2[y])
    A.results["new_york_no2_high_since_2020"] = {"year": high, "value": r(float(ny_no2[high]), 4)}
    assert high == 2023 and ny_no2[2025] < ny_no2[2020] < ny_no2[2023], "the page says it rose to 2023 and is back where it was in 2020"
    # how many times as fast as New York the three European cities cut their nitrogen dioxide since 2017-2019
    A.results["times_as_fast"] = {k: r(recent[k]["change_pct"] / recent["new_york"]["change_pct"], 2) for k in ("london", "berlin", "madrid")}
    # the multiple is not tested (New York's own fall has a wide range), so the page prints the falls side by side and
    # the gap that is tested: London's level against New York's, before and after (the yearly log gap, mean_difference)
    lv = versus["london"]
    ln_s, ny_s = S["no2"]["london"], S["no2"]["new_york"]          # from the unrounded yearly gaps, rounded once for print
    gap = lambda a: mean([math.log(ln_s[y] / ny_s[y]) for y in range(a[0], a[1] + 1)])   # noqa: E731
    A.results["london_against_new_york"] = {"before_pct": r(100 * (math.exp(gap(RECENT)) - 1), 3),
                                            "after_pct": r(100 * (math.exp(gap((2023, 2025))) - 1), 3)}
    assert abs(A.results["london_against_new_york"]["after_pct"] - 100 * (math.exp(-lv["gap_after"]) - 1)) < 0.01
    assert A.results["london_against_new_york"]["before_pct"] > 0 > A.results["london_against_new_york"]["after_pct"], \
        "the page says London went from above New York to below it"
    assert min(recent[k]["change_pct"] for k in ("london", "berlin", "madrid")) < max(recent[k]["change_pct"] for k in ("london", "berlin", "madrid")) < -100 / 3, \
        "the title says a third or more in each of the three"
    # New York's two lowest years of the whole series are its latest two, which the page says beside "no clear change"
    lowest = sorted(int(y) for y in ny_no2.nsmallest(2).index)
    A.results["new_york_no2_lowest_years"] = lowest
    assert lowest == [2024, 2025], f"the page says 2024 and 2025 are New York's two lowest years: {lowest}"
    # London year by year: the single largest step of its fall was 2019 to 2020, the pandemic year
    ln = S["no2"]["london"]
    steps = {y: float(ln[y] - ln[y - 1]) for y in range(2018, LAST + 1)}
    A.results["london_path"] = {"by_year": {str(y): r(float(ln[y]), 4) for y in range(2017, LAST + 1)},
                                "largest_step_year": min(steps, key=steps.get)}
    assert A.results["london_path"]["largest_step_year"] == 2020, "the page says London's largest single step was 2019 to 2020"
    A.results["london_path"]["share_of_fall_in_2020"] = r(-steps[2020] / (recent["london"]["before"] - recent["london"]["after"]), 4)
    assert A.results["london_path"]["share_of_fall_in_2020"] > 0.5 and all(ln[y] < ln[2019] for y in range(2020, LAST + 1)), \
        "the page says more than half of London's fall came in 2020 and did not reverse"
    # Berlin after its diesel street bans were lifted (June 2021 and September 2022): still falling
    bn = S["no2"]["berlin"]
    A.results["berlin_path"] = {str(y): r(float(bn[y]), 4) for y in range(2019, LAST + 1)}
    assert bn[2024] < bn[2022] < bn[2021] < bn[2019], "the page says Berlin's level went on falling to 2024 after the first bans were lifted"
    # Madrid among the four European networks here: the fastest faller but one, and the highest level
    europe = {k: cities[k]["no2"]["late"] for k in ("london", "berlin", "vienna", "madrid")}
    A.results["europe_levels"] = {"late": {k: r(v, 4) for k, v in europe.items()}, "highest": max(europe, key=europe.get)}
    assert A.results["europe_levels"]["highest"] == "madrid", "the page says Madrid's level is the highest of the four European networks"
    md_ = S["no2"]["madrid"]
    A.results["madrid_no2_lowest_years"] = sorted(int(y) for y in md_.nsmallest(2).index)
    # the chart caption says Madrid's level has been below New York's since 2024
    A.results["madrid_below_new_york_since"] = min(y for y in range(2017, LAST + 1) if all(md_[z] < ny_no2[z] for z in range(y, LAST + 1)))
    assert A.results["madrid_below_new_york_since"] == 2024, A.results["madrid_below_new_york_since"]
    # North America: Toronto's fall since 2017-2019 is about New York's, and Cook County's is unclear
    assert abs(recent["toronto"]["change_pct"] - recent["new_york"]["change_pct"]) < 1 and recent["chicago"]["direction"] == "unclear",         "the page says Toronto's fall was about New York's and Cook County's shows no clear change"
    assert A.results["madrid_no2_lowest_years"] == [2024, 2025], "the page says 2024 and 2025 were Madrid's lowest years"
    falls = sorted(recent, key=lambda k: recent[k]["change_pct"])
    assert falls[:3] == ["london", "berlin", "madrid"], f"the page says London's fall is the largest and Madrid's among the fastest: {falls[:3]}"

    # ---- WHO's 2021 guideline levels, read from the sentence that states them (the GLA's ULEZ report)
    Q = A.quotes()
    who_q = Q.quote("gla_ulez_london_wide_one_year_report_2025", "gla_ulez_london_wide_one_year_report_2025.pdf",
                    "The WHO air quality guideline for NO2 is an annual mean concentration of 10 µg/m3 and for PM2.5 it is 5 µg/m3")
    m = re.search(r"NO2 is an annual mean concentration of (\d+) [µμ]g/m3 and for PM2\.5 it is (\d+) [µμ]g/m3", who_q["quote"])
    who = {"no2": int(m.group(1)), "pm25": int(m.group(2))}
    A.results["who"] = {**who, "quote": who_q,
                        "times": {p: {k: r(cities[k][p]["late"] / who[p], 2) for k in cities} for p in W.POLLUTANTS},
                        "cities_meeting": {p: [k for k in cities if cities[k][p]["late"] <= who[p]] for p in W.POLLUTANTS}}
    assert not any(A.results["who"]["cities_meeting"].values()), "the page says no city meets either guideline"

    # ---- what the documents say: the City's survey, its congestion-pricing study, London's zones, Airparif's figures
    hist = {"nyccas_no2": Q.quote("nycdoh_nyccas_report_page", "nycdoh_nyccas_report_page.html",
                                  "Citywide, annual average levels of Nitrogen Dioxide declined by 41% between 2009 and 2024"),
            "nyccas_pm25": Q.quote("nycdoh_nyccas_report_page", "nycdoh_nyccas_report_page.html",
                                   "Citywide, annual average levels of fine particulate matter declined by 36% between 2009 and 2024"),
            "nyccas_oil": Q.quote("nycdoh_nyccas_report_page", "nycdoh_nyccas_report_page.html",
                                  "Air quality improved significantly after local regulations required building owners to convert "
                                  "to cleaner heating oils by 2015"),
            "congestion": Q.quote("nycdoh_congestion_pricing_air_report_2026", "nycdoh_congestion_pricing_air_report_2026.html",
                                  "Measured pollution levels were not significantly different because of congestion pricing"),
            "congestion_start": Q.quote("nycdoh_congestion_pricing_air_report_2026", "nycdoh_congestion_pricing_air_report_2026.html",
                                        "In January 2025, MTA Bridges and Tunnels (MTABT) started charging a toll for vehicles "
                                        "entering the Congestion Relief Zone"),
            "congestion_zone": Q.quote("nycdoh_congestion_pricing_air_report_2026", "nycdoh_congestion_pricing_air_report_2026.html",
                                       "Inside the CRZ, pollution decreased slightly or stayed the same in 2025 compared to 2024"),
            "london_zones": Q.quote("gla_ulez_london_wide_one_year_report_2025", "gla_ulez_london_wide_one_year_report_2025.pdf",
                                    "the introduction of the ULEZ in central London in April 2019, the enforcement of higher "
                                    "emissions standards for the LEZ in March 2021, the expansion of the ULEZ to inner London in "
                                    "October 2021, and the London-wide expansion of the ULEZ in August 2023"),
            "airparif": Q.quote("airparif_bilan_2025_resume", "airparif_bilan_2025_resume.pdf",
                                "Les concentrations de dioxyde d'azote (NO2) ont baissé en moyenne de 45 % sur 10 ans en "
                                "Île-de-France (50 % sur 20 ans)")}

    # what is being said about the air, and what each office says its measures did: every sentence from its saved page
    for key, src, fname, needle in SAID:
        hist[key] = Q.quote(src, fname, needle)

    def num(key, pattern):
        return int(re.search(pattern, hist[key]["quote"]).group(1))
    A.results["conversion"] = W.PPB_TO_UG_NO2
    A.results["history"] = {"quotes": hist,
                            "nyccas_no2_pct": num("nyccas_no2", r"Nitrogen Dioxide declined by (\d+)%"),
                            "nyccas_pm25_pct": num("nyccas_pm25", r"fine particulate matter declined by (\d+)%"),
                            "airparif_no2_10y_pct": num("airparif", r"baissé en moyenne de (\d+) % sur 10 ans"),
                            "airparif_no2_20y_pct": num("airparif", r"\((\d+) % sur 20 ans\)"),
                            "governor_pct": num("governor_20", r"down more than (\d+) percent in one year"),
                            "cornell_zone_pct": num("cornell_22", r"dropped by (\d+)% in the Congestion Relief Zone"),
                            "gla_roadside_pct": num("gla_27", r"a record (\d+)% across the entire capital"),
                            "gla_background_central_pct": num("gla_background", r"NO2 of (\d+) per cent in central"),
                            "gla_background_inner_pct": num("gla_background", r"and (\d+) per cent in inner London"),
                            "bloomberg_pm25_pct": num("bloomberg_23", r"has dropped by (\d+) percent"),
                            "madrid_central_low_pct": num("madrid_central", r"between (\d+)-\d+% in Plaza del Carmen"),
                            "madrid_central_high_pct": num("madrid_central", r"between \d+-(\d+)% in Plaza del Carmen")}
    # the regulatory monitors over the survey's own years (single years 2009 and 2024), beside its published declines
    A.results["new_york_2009_2024"] = {p: r(100 * (S[p]["new_york"][2024] / S[p]["new_york"][2009] - 1), 2) for p in W.POLLUTANTS}

    A.long_view(FROM, LAST, "New York City's annual nitrogen dioxide and fine particles at the EPA's regulatory monitors, "
                "2005-2025; London's nitrogen dioxide from 1991 and Berlin's from 1989 in the data file",
                why_shorter="The EPA's yearly files of every monitor are read from 2005, twenty-one years, the span every "
                            "network here but Vienna's covers; London's and Berlin's longer series are in the data file")
    A.latest(str(LAST), "Annual means for 2025 from the EPA, Defra, Berlin, Vienna, Madrid and Singapore (2024 from NAPS "
             "and Tokyo's fiscal year)",
             why_older="The networks publish a year's means after it ends; 2026's are not out, so 2025 is the latest "
                       "(2024 for Toronto, Montréal and Tokyo)")

    # ---- what each city has done, from its own documents
    A.quote_responses(RESPONSES)

    # ---- the directions the prose states, held to their ranges
    for path, way in (("cities.new_york.no2", "down"), ("cities.new_york.pm25", "down"), ("panel.new_york.no2", "down"),
                      ("recent.new_york", "down"), ("recent.london", "down"), ("recent.berlin", "down"),
                      ("recent.madrid", "down"), ("recent_vs_new_york.london", "up"), ("recent_vs_new_york.berlin", "up"),
                      ("recent_vs_new_york.madrid", "up"), ("since.new_york.2015_2017", "down")):
        A.claim(path, way)

    # ---- what the prose prints
    def signed(x):
        return "0%" if round(x) == 0 else f"{x:+.0f}%".replace("-", "−")
    for k in cities:
        for p in W.POLLUTANTS:
            c = cities[k][p]
            A.printed(f"cities.{k}.{p}.early", f"{c['early']:.1f}")
            A.printed(f"cities.{k}.{p}.late", f"{c['late']:.1f}")
            A.printed(f"cities.{k}.{p}.change_pct", signed(c["change_pct"]))
            A.printed(f"cities.{k}.{p}.early_years", f"{c['early_years'][0]}-{c['early_years'][1]}")
            A.printed(f"cities.{k}.{p}.late_years", f"{c['late_years'][0]}-{c['late_years'][1]}")
            A.printed(f"cities.{k}.{p}.lo_pct", signed(c["lo_pct"]))
            A.printed(f"cities.{k}.{p}.hi_pct", signed(c["hi_pct"]))
    ny = cities["new_york"]
    A.results["new_york"] = {p: {"fall": r(abs(ny[p]["change_pct"]), 2)} for p in W.POLLUTANTS}
    for p in W.POLLUTANTS:
        A.printed(f"new_york.{p}.fall", f"{abs(ny[p]['change_pct']):.0f}%")
        A.printed(f"who.{p}", str(who[p]))
        A.printed(f"who.times.{p}.new_york", f"{A.results['who']['times'][p]['new_york']:.1f}")
        A.printed(f"panel.new_york.{p}.change_pct", f"{abs(panel['new_york'][p]['change_pct']):.0f}%")
        A.printed(f"congestion.{p}.2024", f"{A.results['congestion'][p]['2024']:.1f}")
        A.printed(f"congestion.{p}.2025", f"{A.results['congestion'][p]['2025']:.1f}")
        A.printed(f"new_york_2009_2024.{p}", f"{abs(A.results['new_york_2009_2024'][p]):.0f}%")
    A.printed("new_york_no2_2020", f"{A.results['new_york_no2_2020']:.1f}")
    A.printed("new_york_no2_high_since_2020.value", f"{A.results['new_york_no2_high_since_2020']['value']:.1f}")
    A.printed("london_against_new_york.before_pct", f"{A.results['london_against_new_york']['before_pct']:.0f}%")
    A.printed("london_against_new_york.after_pct", f"{abs(A.results['london_against_new_york']['after_pct']):.0f}%")
    A.printed("recent.vienna.change_pct", f"{abs(recent['vienna']['change_pct']):.0f}%")
    for y in ("2019", "2020"):
        A.printed(f"london_path.by_year.{y}", f"{A.results['london_path']['by_year'][y]:.1f}")
    A.printed("who.times.no2.madrid", f"{A.results['who']['times']['no2']['madrid']:.1f}")
    for k in ("new_york", "london", "berlin", "madrid"):
        A.printed(f"recent.{k}.change_pct", f"{abs(recent[k]['change_pct']):.0f}%")
    # the table behind the headline comparison (outside review, 15 November 2026): micrograms per cubic metre, the 90%
    # range of the change, and how far New York's level rose against each city's (the yearly log ratios, as a percentage)
    def num1(x):
        return f"{x:+.1f}".replace("-", "−")

    def against(node):
        return (f"{signed(node['new_york_relative_pct'])} ({signed(node['new_york_relative_lo_pct'])} to "
                f"{signed(node['new_york_relative_hi_pct'])})")

    table = []
    for k, label in CITIES:
        c = recent[k]
        years = f"{c['late_years'][0]}-{c['late_years'][1]}"
        row = {"city": label, "before": f"{c['before']:.1f}", "late_years": years, "after": f"{c['after']:.1f}",
               "change": num1(c["change"]), "range": f"{num1(c['lo'])} to {num1(c['hi'])}", "change_pct": signed(c["change_pct"]),
               "against": against(versus[k]) if k != "new_york" else "—"}
        table.append(row)
        for field in ("before", "after"):
            A.printed(f"recent.{k}.{field}", row[field])
        A.printed(f"recent.{k}.change", row["change"])
        A.printed(f"recent.{k}.lo", num1(c["lo"]))
        A.printed(f"recent.{k}.hi", num1(c["hi"]))
        if k not in ("new_york", "london", "berlin", "madrid", "vienna"):       # those five are printed above, unsigned
            A.printed(f"recent.{k}.change_pct", row["change_pct"])
        if k != "new_york":
            A.printed(f"recent_vs_new_york.{k}.new_york_relative_pct", row["against"])
    A.results["table_recent"] = table
    cells = {row["city"]: row["against"] for row in table}
    assert cells["Montréal"].startswith("+9% ") and cells["Chicago"].endswith("to +3%)"), \
        f"rounded once, from the unrounded contrast (9.47 and 2.52): {cells['Montréal']}, {cells['Chicago']}"
    table = []
    for k in ("new_york", "london", "berlin", "madrid"):
        c = A.results["pre_toll"][k]
        row = {"city": LABEL[k], "before": f"{c['before']:.1f}", "after": f"{c['after']:.1f}", "change": num1(c["change"]),
               "range": f"{num1(c['lo'])} to {num1(c['hi'])}", "change_pct": signed(c["change_pct"]),
               "against": against(c["against_new_york"]) if k != "new_york" else "—"}
        table.append(row)
        A.printed(f"pre_toll.{k}.after", row["after"])
        A.printed(f"pre_toll.{k}.change", row["change"])
        A.printed(f"pre_toll.{k}.lo", num1(c["lo"]))
        A.printed(f"pre_toll.{k}.hi", num1(c["hi"]))
        A.printed(f"pre_toll.{k}.change_pct", f"{abs(c['change_pct']):.0f}%")
        if k != "new_york":
            A.printed(f"pre_toll.{k}.against_new_york.new_york_relative_pct", row["against"])
    A.results["table_pre_toll"] = table
    A.printed("since.chicago.2015_2017.before", f"{since['chicago']['2015_2017']['before']:.1f}")
    A.printed("since.chicago.2015_2017.after", f"{since['chicago']['2015_2017']['after']:.1f}")
    A.printed("since.chicago.fall_to_2015_2017_pct", f"{abs(since['chicago']['fall_to_2015_2017_pct']):.0f}%")
    A.printed("since.new_york.2015_2017.change_pct", f"{abs(since['new_york']['2015_2017']['change_pct']):.0f}%")
    pc = A.results["pm25_checks"]
    A.printed("pm25_checks.new_york_2024_2025", f"{pc['new_york_2024_2025']:.1f}")
    A.printed("pm25_checks.new_york_change_without_2023_pct", f"{abs(pc['new_york_change_without_2023_pct']):.0f}%")
    A.printed("pm25_checks.berlin_light_scattering.change_pct", f"{abs(pc['berlin_light_scattering']['change_pct']):.0f}%")
    A.printed("heating_oil.before_pct", f"{abs(A.results['heating_oil']['before_pct']):.0f}%")
    A.printed("heating_oil.after_pct", f"{abs(A.results['heating_oil']['after_pct']):.0f}%")
    h = A.results["history"]
    A.printed("conversion", f"{A.results['conversion']:.2f}")
    for key in ("nyccas_no2_pct", "nyccas_pm25_pct", "airparif_no2_10y_pct", "airparif_no2_20y_pct", "cornell_zone_pct"):
        A.printed(f"history.{key}", f"{h[key]}%")
    h["madrid_central_range"] = [h["madrid_central_low_pct"], h["madrid_central_high_pct"]]
    A.printed("history.madrid_central_range", f"{h['madrid_central_low_pct']}-{h['madrid_central_high_pct']}%")
    A.printed("history.governor_pct", str(h["governor_pct"]))

    # ---- charts
    years = list(range(FROM, LAST + 1))
    A.chart("long_view", lines(
        title="New York's nitrogen dioxide has halved since 2005-2007, and its fine particles have fallen by more than two-fifths",
        subtitle="Annual mean at New York City's regulatory monitors, 2005 to 2025",
        x=[[str(t), str(t)] for t in years],
        series=[["no2", "Nitrogen dioxide", "NO2"], ["pm25", "Fine particles (PM2.5)", "PM2.5"]],
        cells={"": {p: {str(t): (r(float(S[p]["new_york"][t]), 2) if t in S[p]["new_york"].index else None) for t in years}
                    for p in W.POLLUTANTS}},
        format="dec1", axis="Micrograms per cubic metre",
        x_ticks=[str(t) for t in years if t % 5 == 0],
        note="Every regulatory monitor in the five boroughs that the EPA marks complete in a year, near-road and rural "
             "ones left out, the mean over a site's monitors first: for nitrogen dioxide five sites in 2005 and three since "
             "2013, for fine particles nine to eleven in 2005-2007 and five to seven in 2023-2025. Nitrogen dioxide "
             "converted from parts per billion at 1.91 micrograms per ppb; fine particles by the filter method, which no "
             "monitor completed in 2020; days flagged as exceptional events are included.",
        provenance="U.S. EPA, Air Quality System annual summaries"))

    def strip_chart(p, title, note):
        return strip(
            title=title,
            subtitle=f"Annual mean of {POLLUTANT[p]}, each city's first three years from 2005 against its latest three",
            x=[["early", "First three years"], ["late", "Latest three years"]],
            series=[[k, label, label] for k, label in CITIES],
            cells={"": {k: {"early": r(cities[k][p]["early"], 2), "late": r(cities[k][p]["late"], 2)} for k in cities}},
            format="dec1", axis="Micrograms per cubic metre", note=note,
            provenance="EPA; Defra; Berlin Senate; Stadt Wien; Ayuntamiento de Madrid; ECCC (NAPS); Tokyo Metropolitan "
                       "Government; NEA Singapore")

    A.chart("then_and_now", strip_chart(
        "no2", "In ten of eleven big cities nitrogen dioxide fell by more than a third from 2005-2007, and New York "
               "started highest",
        "First years 2005-2007 (Vienna's 2010-2012); latest 2023-2025 (Toronto's, Montréal's and Tokyo's 2022-2024). Each "
        "city's own network, so levels are an observed order: London's and Berlin's are urban background stations, "
        "Vienna's every station, New York's, Chicago's (Cook County) and Los Angeles's (the county) every regulatory monitor "
        "but the near-road ones."))
    A.chart("pm25", strip_chart(
        "pm25", "Every city here is above WHO's guideline for fine particles, and New York is among the lowest",
        "First years 2005-2007 (London 2009-2011, Berlin 2008-2010, Vienna 2010-2012, Tokyo fiscal 2011-2013); latest "
        "2023-2025 (Toronto's, Montréal's and Tokyo's 2022-2024). WHO's 2021 guideline for the annual mean is 5 micrograms "
        "per cubic metre."))

    A.chart("world_lines", lines(
        title="Since 2017-2019 London's, Berlin's and Madrid's nitrogen dioxide has fallen far faster than New York's",
        subtitle="Annual mean of nitrogen dioxide, 2005 to 2025 (Tokyo by fiscal year, to 2024)",
        x=[[str(t), str(t)] for t in years],
        series=[[k, LABEL[k], LABEL[k]] for k in WORLD_LINES],
        cells={"": {k: {str(t): (r(float(S["no2"][k][t]), 2) if t in S["no2"][k].index else None) for t in years}
                    for k in WORLD_LINES}},
        format="dec1", axis="Micrograms per cubic metre",
        x_ticks=[str(t) for t in years if t % 5 == 0],
        note="Each city's own network: New York's regulatory monitors, London's and Berlin's urban background stations, "
             "Madrid's urban background stations, Tokyo's ambient stations, Singapore's national mean. Chicago, Los Angeles, "
             "Vienna, Toronto and Montréal are in the data file.",
        provenance="EPA; Defra; Berlin Senate; Ayuntamiento de Madrid; Tokyo Metropolitan Government; NEA Singapore"))

    A.chart("us_cities", lines(
        title="Chicago's nitrogen dioxide shows no clear change since 2015-2017, nor New York's since 2020",
        subtitle="Annual mean of nitrogen dioxide, New York City, Cook County and Los Angeles County, 2005 to 2025",
        x=[[str(t), str(t)] for t in years],
        series=[[k, LABEL[k], LABEL[k]] for k in US_LINES],
        cells={"": {k: {str(t): (r(float(S["no2"][k][t]), 2) if t in S["no2"][k].index else None) for t in years}
                    for k in US_LINES}},
        format="dec1", axis="Micrograms per cubic metre",
        x_ticks=[str(t) for t in years if t % 5 == 0],
        note="All three from the EPA's yearly file, the same rules for each: every complete regulatory monitor in the county "
             "but the near-road and rural ones.",
        provenance="U.S. EPA, Air Quality System annual summaries"))

    rows = []
    for k, label in CITIES:
        for p in W.POLLUTANTS:
            d = W.annual(k, p)
            for _, x in d.iterrows():
                rows.append({"city": label, "area": W.AREAS[k][0], "pollutant": POLLUTANT[p], "year": int(x["year"]),
                             "annual_mean_ug_m3": r(float(x["value"]), 3),
                             "sites": (int(x["sites"]) if "sites" in d.columns and pd.notna(x["sites"]) else None),
                             "publisher": W.AREAS[k][1], "source": x["source_id"]})
    A.write(data=pd.DataFrame(rows))
    print(f"{SLUG}: wrote {A.out}")
    return 0


#: What each city has done about its air, from its own documents: city -> [(source id, saved file, needle, what it
#: establishes)]. Every sentence the page prints about a measure rests on one of these quotes.
RESPONSES = {
    "new_york": [("nyc_dep_heating_oil_press_2011", "nyc_dep_heating_oil_press_2011.html",
                  "By 2015, the burning of No. 6 heating oil will be phased out, followed by the phase out of No. 4 oil by 2030",
                  "heating oil: No. 6 out by 2015, No. 4 by 2030 (2011)"),
                 ("nycdoh_congestion_pricing_air_report_2026", "nycdoh_congestion_pricing_air_report_2026.html",
                  "Inside the CRZ, pollution decreased slightly or stayed the same in 2025 compared to 2024",
                  "congestion pricing, January 2025: the City's study")],
    "chicago": [("chicago_coal_plants_retire_press_2012", "chicago_coal_plants_retire_press_2012.html",
                 "The Fisk Station at 1111 W. Cermak Road will be closed no later than the end of 2012, and the Crawford "
                 "Station at 3601 S. Pulaski Road will be closed by the end of 2014", "coal: two city power plants closed, 2012 and 2014")],
    "los_angeles": [("la_ports_clean_air_action_plan_fact_sheet_2006", "la_ports_clean_air_action_plan_fact_sheet_2006.pdf",
                     "The ports propose to eliminate", "ports: the 2006 plan"),
                    ("la_ports_clean_air_action_plan_fact_sheet_2006", "la_ports_clean_air_action_plan_fact_sheet_2006.pdf",
                     "diesel trucks from San Pedro Bay cargo terminals within", "dirty diesel trucks out of the terminals")],
    "london": [("gla_ulez_london_wide_one_year_report_2025", "gla_ulez_london_wide_one_year_report_2025.pdf",
                "the introduction of the ULEZ in central London in April 2019, the enforcement of higher emissions standards "
                "for the LEZ in March 2021, the expansion of the ULEZ to inner London in October 2021, and the London-wide "
                "expansion of the ULEZ in August 2023", "vehicles: the ULEZ from 2019, widened in 2021 and 2023")],
    "berlin": [("berlin_umweltzone_allgemeines", "berlin_umweltzone_allgemeines.html",
                "Die Umweltzone wurde am 1.1.2008 mit dem Kriterium der roten Plakette eingeführt",
                "vehicles: a low-emission zone from January 2008, the red sticker"),
               ("berlin_umweltzone_allgemeines", "berlin_umweltzone_allgemeines.html",
                "ist für die Umweltzone Berlin die grüne Plakette erforderlich", "the green sticker from January 2010")],
    "vienna": [("wien_lgbl_2005_47_ig_l_massnahmenkatalog", "wien_lgbl_2005_47_ig_l_massnahmenkatalog.html",
                "wird das gesamte Gebiet der Bundeshauptstadt Wien festgelegt", "the whole city a clean-air remediation area, 2005")],
    "toronto": [("toronto_tph_path_to_healthier_air_2014", "toronto_tph_path_to_healthier_air_2014.pdf",
                 "A key initiative that improved air quality in the Toronto region is the closure of Ontario's coal",
                 "coal: Ontario's coal plants closed")],
    "montreal": [("montreal_rsqa_air_quality_report_2025", "montreal_rsqa_air_quality_report_2025.pdf",
                  "strictly regulates the use of solid-fuel appliances", "wood heating: regulated since 2015"),
                 ("montreal_rsqa_air_quality_report_2025", "montreal_rsqa_air_quality_report_2025.pdf",
                  "Since 2015, By-law 15", "the by-law's year")],
    "tokyo": [("tmg_diesel_regulation_results_2003", "tmg_diesel_regulation_results_2003.html",
               "2003年10月1日から埼玉・千葉・東京・神奈川の全域で、国に先駆け、条例のPM排出基準を満たさないディーゼル車の走行が禁止されます",
               "diesel: non-compliant vehicles to be banned from October 2003 (September 2003)")],
    "singapore": [("nea_euro_vi_diesel_2014", "nea_euro_vi_diesel_2014.html",
                   "The Euro VI emission standard for new diesel vehicles is set to come into force in Singapore from 1 January 2018",
                   "diesel: Euro VI from 2018")],
    "paris": [("paris_zfe_etape_2021", "paris_zfe_etape_2021.html",
               "la restriction de circulation des véhicules catégorisés non classés, Crit'Air 5 et Crit'Air 4 entre en vigueur "
               "sur l'ensemble du territoire parisien", "vehicles: the low-emission zone's 2021 step"),
              ("airparif_bilan_2025_resume", "airparif_bilan_2025_resume.pdf", "baissé en moyenne de 45 % sur 10 ans",
               "the region's nitrogen dioxide over ten years"),
              ("airparif_bilan_2025_resume", "airparif_bilan_2025_resume.pdf", "(50 % sur 20 ans)",
               "and over twenty")],
}

#: What is being said about the air, and what each office or study says a measure did: (key, source id, saved file,
#: needle). Each is quoted on the page with its date; none is used as a cause.
SAID = [
    ("governor_20", "nys_governor_crz_anniversary_transcript_2026", "nys_governor_crz_anniversary_transcript_2026.html",
     "pollution is down more than 20 percent in one year"),
    ("cornell_22", "cornell_chronicle_crz_air_2025", "cornell_chronicle_crz_air_2025.html",
     "dropped by 22% in the Congestion Relief Zone"),
    ("cornell_six_months", "cornell_chronicle_crz_air_2025", "cornell_chronicle_crz_air_2025.html",
     "In the first six months of the program"),
    ("cornell_projection", "cornell_chronicle_crz_air_2025", "cornell_chronicle_crz_air_2025.html",
     "a projected average of 13.8 micrograms per cubic meter had congestion pricing not been implemented"),
    ("health_headline", "nycdoh_press_crz_air_2026", "nycdoh_press_crz_air_2026.html",
     "continuing a 20-year trend of improving air quality and declining pollution"),
    ("health_commissioner", "nycdoh_press_crz_air_2026", "nycdoh_press_crz_air_2026.html",
     "air quality across New York City was not any different because of congestion pricing"),
    ("ulez_works", "gla_press_ulez_one_year_2025", "gla_press_ulez_one_year_2025.html",
     "report shows that ULEZ works"),
    ("gla_27", "gla_press_ulez_one_year_2025", "gla_press_ulez_one_year_2025.html",
     "have decreased by a record 27% across the entire capital"),
    ("gla_background", "gla_ulez_inner_london_one_year_report_2023", "gla_ulez_inner_london_one_year_report_2023.pdf",
     "also had significant reductions in NO2 of 47 per cent in central and 45 per cent in inner London, since 2017"),
    ("bloomberg_cleanest", "nyc_mayor_press_cleanest_air_2013", "nyc_mayor_press_cleanest_air_2013.html",
     "has reached the cleanest levels in more than 50 years"),
    ("bloomberg_clean_heat", "nyc_mayor_press_cleanest_air_2013", "nyc_mayor_press_cleanest_air_2013.html",
     "The largest contributor to the reductions is the PlaNYC"),
    ("bloomberg_23", "nyc_mayor_press_cleanest_air_2013", "nyc_mayor_press_cleanest_air_2013.html",
     "since 2007 the level of soot pollution (PM2.5) has dropped by 23 percent"),
    ("cornell_measure", "cornell_chronicle_crz_air_2025", "cornell_chronicle_crz_air_2025.html",
     "average daily maximum PM2.5 concentrations"),
    ("health_stable", "nycdoh_press_crz_air_2026", "nycdoh_press_crz_air_2026.html",
     "remained stable or improved slightly in the first year of congestion pricing"),
    ("ulez_works_speaker", "gla_press_ulez_one_year_2025", "gla_press_ulez_one_year_2025.html",
     "The Mayor of London, Sadiq Khan, said"),
    ("bloomberg_so2", "nyc_mayor_press_cleanest_air_2013", "nyc_mayor_press_cleanest_air_2013.html",
     "the levels of sulfur dioxide (SOx) in the air have dropped by 69 percent"),
    ("madrid_record", "okdiario_madrid_no2_2026", "okdiario_madrid_no2_2026.html",
     "encadena dos años con los niveles de dióxido de nitrógeno más reducidos de su historia"),
    ("berlin_bans", "berlin_senat_press_luftbelastung_2022", "berlin_senat_press_luftbelastung_2022.html",
     "waren Ende 2019 für acht Straßen Dieseldurchfahrtverbote eingeführt worden"),
    ("berlin_lifted", "berlin_senat_press_luftbelastung_2022", "berlin_senat_press_luftbelastung_2022.html",
     "erlaubte im Juni 2021 die Aufhebung auf vier der acht Strecken"),
    ("airparif_split", "airparif_paris_2012_2022_press_2025", "airparif_paris_2012_2022_press_2025.pdf",
     "Half of this reduction is attributable to the modernisation of the vehicle fleet, a quarter to the decline in road traffic"),
    ("madrid_central", "uniovi_madrid_central_no2_2021", "uniovi_madrid_central_no2_2021.pdf",
     "we estimate a reduction of NO2 levels between 23-34% in Plaza del Carmen"),
    ("madrid_central_station", "uniovi_madrid_central_no2_2021", "uniovi_madrid_central_no2_2021.pdf",
     "the only monitoring station within the LEZ"),
    ("madrid_central_dates", "uniovi_madrid_central_no2_2021", "uniovi_madrid_central_no2_2021.pdf",
     "between the 1st of December 2018 and the end of May 2019"),
]


if __name__ == "__main__":
    raise SystemExit(main())
