flight-delay-explorer / index.html
balselman's picture
Flight delay risk explorer (precomputed final-test results)
9b046ba verified
Raw History Blame Contribute Delete
10.7 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Flight delay risk explorer</title>
<style>
:root {
--bg: #f6f7f9; --card: #ffffff; --ink: #14202b; --muted: #5a6876; --line: #d6dde4;
--accent: #1f6feb; --late: #c2410c; --ok: #94a3b8;
color-scheme: light;
}
@media (prefers-color-scheme: dark) {
:root { --bg: #0f151c; --card: #17212b; --ink: #e6edf3; --muted: #94a3b3; --line: #2a3a49;
--accent: #58a6ff; --late: #fb923c; --ok: #4b5d70; color-scheme: dark; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink);
font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; padding: 24px 16px 48px; }
main { max-width: 920px; margin: 0 auto; display: grid; gap: 18px; }
h1 { margin: 0; font-size: clamp(26px, 5vw, 34px); line-height: 1.15; }
p { margin: 0; }
.muted { color: var(--muted); }
a { color: var(--accent); }
.links { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.controls { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
label { display: grid; gap: 4px; font-size: 14px; font-weight: 600; }
select { font: inherit; font-weight: 400; padding: 8px; border: 1px solid var(--line); border-radius: 6px;
background: var(--card); color: var(--ink); min-width: 0; width: 100%; }
h2 { margin: 0 0 4px; font-size: 21px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); align-items: start; }
.rates { display: flex; gap: 20px; flex-wrap: wrap; }
.rate b { display: block; font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.rate span { font-size: 14px; color: var(--muted); }
.dots { display: grid; grid-template-columns: repeat(10, 14px); gap: 4px; margin-top: 10px; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ok); }
.dot.late { background: var(--late); border-color: var(--late); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 15px; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
.buffer { font-size: 15px; }
.buffer b { font-size: 22px; }
footer { font-size: 13px; color: var(--muted); }
</style>
</head>
<body>
<main>
<header style="display:grid;gap:8px">
<h1>Flight delay risk explorer</h1>
<p>How often do US domestic flights arrive 15+ minutes late, and how well did LightGBM models anticipate it?
Pick a route, a departure-hour block and a season from the <b>one-shot final test (Mar-Aug 2026, 2.37 M flights from 30 airports)</b>.</p>
<p class="muted">Numbers are <b>precomputed</b> from the locked models (no live inference): <span id="n-cells">…</span> route × hour × season cells
with at least 50 flights. Cells where one airline operates more than 90% of the flights are not shown, so no figure describes a single airline.
<i>Based on public data (US DOT BTS, Iowa Environmental Mesonet); not affiliated with any airline.</i></p>
<div class="links">
<a href="https://github.com/Slmnbal/flight-delay-forecasting">Code on GitHub</a>
<a href="https://slmnbal.github.io/flight-delay-forecasting/">Full results website</a>
<a href="https://huggingface.co/balselman/flight-delay-forecasting">Model files and model card</a>
</div>
</header>
<section class="panel controls" aria-label="Selection">
<label>Origin airport <select id="origin"></select></label>
<label>Destination <select id="dest"></select></label>
<label>Departure hour block (local time) <select id="block"></select></label>
<label>Season <select id="season"></select></label>
</section>
<section class="panel" id="result" aria-live="polite"><p class="muted">Loading…</p></section>
<footer>Delay quantiles come from the schedule-only model; the late-arrival probability from the T-2h model with weather,
recalibrated monthly (rolling Platt). Conformal bounds use a monthly rolling window. The buffer suggestion is the newsvendor
rule with a delay minute assumed 4× as costly as an idle minute (τ = 0.80); costs are an assumption, not airline data.</footer>
</main>
<script>
const SEASONS = { ilkbahar: "Spring (Mar-May)", yaz: "Summer (Jun-Aug)" };
const BLOCKS = ["00-06", "06-09", "09-12", "12-15", "15-18", "18-21", "21-24"];
const $ = (id) => document.getElementById(id);
const state = { airports: {}, destNames: {}, cells: {} };
function el(tag, props, ...kids) {
const n = document.createElement(tag);
if (props) for (const [k, v] of Object.entries(props)) n[k] = v;
for (const k of kids.flat()) if (k !== null && k !== undefined) n.append(k);
return n;
}
const pct = (x) => (x === null || x === undefined ? "n/a" : (100 * x).toFixed(1) + "%");
const mins = (x) => (x === null || x === undefined ? "n/a" : (x >= 0 ? "+" : "−") + Math.abs(x).toFixed(1) + " min");
function fill(select, options, keep) {
const prev = keep ? select.value : null;
select.replaceChildren(...options.map(([value, text]) => el("option", { value, textContent: text })));
if (prev && options.some(([v]) => v === prev)) select.value = prev;
}
function rows(origin, dest, block) {
return (state.cells[origin] || []).filter((r) => (!dest || r.dest === dest) && (!block || r.saat_blogu === block));
}
function onOrigin() {
const dests = [...new Set(rows($("origin").value).map((r) => r.dest))].sort();
fill($("dest"), dests.map((d) => [d, `${d} - ${state.destNames[d] || d}`]), true);
onDest();
}
function onDest() {
const present = new Set(rows($("origin").value, $("dest").value).map((r) => r.saat_blogu));
fill($("block"), BLOCKS.filter((b) => present.has(b)).map((b) => [b, b]), true);
onBlock();
}
function onBlock() {
const present = new Set(rows($("origin").value, $("dest").value, $("block").value).map((r) => r.mevsim));
fill($("season"), Object.entries(SEASONS).filter(([k]) => present.has(k)), true);
render();
}
function render() {
const r = rows($("origin").value, $("dest").value, $("block").value).find((x) => x.mevsim === $("season").value);
const box = $("result");
if (!r) { box.replaceChildren(el("p", { className: "muted", textContent: "No published cell for this selection. Pick another destination, hour block or season." })); return; }
const late = Math.round(100 * r.gozlenen_arrdel15_orani);
const dots = el("div", { className: "dots", role: "img", ariaLabel: `${late} of 100 flights arrived 15+ minutes late` },
Array.from({ length: 100 }, (_, i) => el("span", { className: i < late ? "dot late" : "dot" })));
const q = r.kantil_dk, qc = r.kantil_conf_dk, iv = r.aralik80_dk;
const tr = (a, b, c) => el("tr", null, el("td", { textContent: a }), el("td", { textContent: b }), el("td", { textContent: c }));
const buffer = r.tampon_onerisi_dk;
box.replaceChildren(
el("h2", { textContent: `${$("origin").value} → ${r.dest} · departs ${r.saat_blogu} local · ${SEASONS[r.mevsim]}` }),
el("p", { className: "muted", textContent: `Based on ${r.n_ucus.toLocaleString("en-US")} scheduled flights in the final test period (Mar-Aug 2026).` }),
el("div", { className: "grid", style: "margin-top:14px" },
el("div", null,
el("div", { className: "rates" },
el("div", { className: "rate" }, el("b", { textContent: pct(r.gozlenen_arrdel15_orani) }), el("span", { textContent: "actually arrived 15+ min late" })),
el("div", { className: "rate" }, el("b", { textContent: pct(r.tahmin_arrdel15_orani) }), el("span", { textContent: "model expected (T-2h, calibrated)" }))),
dots,
el("p", { className: "muted", style: "font-size:13px;margin-top:6px", textContent: "Filled dot = a flight that arrived 15+ minutes late, per 100 flights (observed)." })),
el("div", null,
el("p", { style: "font-weight:600;margin-bottom:4px", textContent: "How late do they arrive? (negative = early)" }),
el("table", null,
el("thead", null, el("tr", null, el("th", { textContent: "Quantile" }), el("th", { textContent: "Model" }), el("th", { textContent: "Conformal" }))),
el("tbody", null,
tr("Median (P50)", mins(q.p50), "-"),
tr("4 in 5 arrive by (P80)", mins(q.p80), mins(qc.p80)),
tr("19 in 20 arrive by (P95)", mins(q.p95), mins(qc.p95)))),
el("p", { className: "muted", style: "font-size:14px;margin-top:6px",
textContent: `80% interval ${mins(iv.alt)} to ${mins(iv.ust)} · observed coverage P80 ${pct(r.kapsama.p80)}, P95 ${pct(r.kapsama.p95)}` }))),
el("p", { className: "buffer", style: "margin-top:14px" },
"Suggested schedule buffer: ", el("b", { textContent: buffer === null || buffer === undefined ? "not published" : `${Math.round(buffer)} min` }),
el("span", { className: "muted", textContent: ` · cancellation rate ${pct(r.iptal_orani)} · median scheduled block time ${Math.round(r.planli_blok_sure_medyan_dk)} min` }))
);
}
async function getJson(path) {
const res = await fetch(path);
if (!res.ok) throw new Error(`${path}: ${res.status}`);
return res.json();
}
async function start() {
try {
const [airports, dests] = await Promise.all([getJson("data/havalimanlari.json"), getJson("data/varis-noktalari.json")]);
for (const a of airports.havalimanlari) state.airports[a.iata] = a;
for (const p of dests.noktalar) state.destNames[p.iata] = p.ad;
const codes = Object.keys(state.airports).sort();
const files = await Promise.all(codes.map((c) => getJson(`data/rotalar/${c}.json`)));
codes.forEach((c, i) => { state.cells[c] = files[i].hucreler; });
$("n-cells").textContent = files.reduce((s, f) => s + f.hucreler.length, 0).toLocaleString("en-US");
fill($("origin"), codes.map((c) => [c, `${c} - ${state.airports[c].ad}`]));
$("origin").value = "ORD";
$("dest").value = "LGA";
onOrigin();
if (rows("ORD", "LGA").length) { $("dest").value = "LGA"; onDest(); }
} catch (err) {
$("result").replaceChildren(el("p", { textContent: "The data could not be loaded. Please reload the page. (" + err.message + ")" }));
}
}
$("origin").addEventListener("change", onOrigin);
$("dest").addEventListener("change", onDest);
$("block").addEventListener("change", onBlock);
$("season").addEventListener("change", render);
start();
</script>
</body>
</html>