guard(() => {
const lq = days.at(-1);
if (lq == null) return noData();
const partial = latest?.scheduled_service?.trips_ended_before_collection > 0 && latest?.paradata?.observed_from;
const far = lq.prediction_over_30min_share_5min;
return html`<p class="note">These grades are for ${longDate(latestDate)}.${partial ? ` Collection began at ${pacificClock(latest.paradata.observed_from)} Pacific that day, so the grades cover only part of it.` : ""}</p>
${stats([
{label: "Did every scheduled trip show up?", value: fmtShare(lq.trip_coverage),
note: `of ${count(lq.scheduled_trips)} scheduled trips appeared in the tracking around the time they were due`},
{label: "Did the collector keep running?", value: fmtShare(lq.vehicle_uptime),
note: "of 20-second checks got a good answer from the feed"},
{label: "How fresh are bus locations?", value: unit(lq.position_age_s_median, "second"),
note: "typical age of a location when it first appears"},
{label: "How close are arrival predictions?", value: unit(lq.prediction_min_5min, "min", 1, "min"),
note: `typical miss, for predictions made 5 minutes before the bus arrived${far ? `; ${pct(far)} were off by more than 30 minutes` : ""}`},
{label: "Are buses where the route says?", value: lq.off_shape_share == null ? "–" : fmtShare(1 - lq.off_shape_share),
note: "of locations were within 100 meters (about 330 feet) of the bus's published route"},
])}`;
}, "The day's grades")Can the data be trusted?
How reliable Island Transit’s bus-tracking feed is, checked every day
How complete and accurate Island Transit’s live bus tracking is: trips seen, gaps, location age and prediction misses.
Trip-planning apps, this site, and anyone else who studies Island Transit all lean on the same live feed, so every number built on it is only as good as the feed itself. That’s why we grade the feed every day.
import {csv, json, pct, num, count, unit, routeLabel, longDate, pacificClock, plural, isFalse, isoDate, serviceDays, recentDays, withDates, showAllToggle, emptyNote, guard, stats, h, DATA_URL, DATA_RAW_URL, periodInput, periodName, fmtShare, hourLabel} from "./lib.js"
import {makeCharts} from "./charts.js"
import {Plot, d3} from "./vendor/plot-0.6.11/plot.js"
ch = makeCharts({Plot})
daily = csv(d3, "data/quality/daily.csv")
minutes = s => s == null ? null : s / 60
// Days with scheduled service; a holiday is archived and listed under "All
// days" but not graded or charted.
days = withDates(serviceDays(daily)).map(d => ({...d, prediction_min_5min: minutes(d.prediction_median_abs_s_5min)}))
latestDate = days.length ? days.at(-1).day : null
latest = latestDate ? json(`data/quality/days/${latestDate}.json`) : null
noData = () => days.length === 0 ? emptyNote("no-days") : emptyNote("unavailable", `The details for ${longDate(latestDate)}`)
ev = latest?.events ?? null
qperiods = json("data/quality/periods.json")
routeName = id => routeLabel(latest?.routes, id)We sort the details below the way survey researchers grade any source of data, into coverage, nonresponse, measurement error, processing error and paradata. Hover over or tap each term for a plain explanation, or see the Methods page for the exact definitions.
Over time
Each small chart follows one measure. Pick how to group the days; a week runs Monday to Sunday, Pacific time.
viewof showAll = period === "day" ? showAllToggle(days.length) : Object.assign(h("span", {hidden: true}), {value: false})series = [
{key: "trip_coverage", pooled: "trip_coverage", title: "Scheduled trips seen in the feed", share: true},
{key: "vehicle_uptime", pooled: "vehicle_uptime", title: "Collector uptime (vehicle locations)", share: true},
{key: "timepoint_coverage", pooled: "timepoint_coverage", title: "Departures at timetable stops we could time", share: true},
{key: "off_shape_share", pooled: "off_shape_share", title: "Locations more than 100 meters off the route", share: true},
{key: "position_age_s_median", pooled: null, title: "Typical age of a bus location when first seen", word: "second"},
{key: "longest_gap_s_median", pooled: null, title: "Typical longest tracking gap per trip", word: "second"},
{key: "prediction_min_5min", pooled: null, title: "Typical arrival prediction miss, 5 minutes ahead", word: "minute"},
]
howMeasured = html`<p class="how-measured"><a href="methods.html#feed-quality-metrics">How we measured these</a></p>`
say = (s, v) => s.share ? fmtShare(v) : unit(v, s.word, 1)
// The rows a small chart draws for the chosen period: service days from the
// daily table, or weeks and months from the period file.
periodRows = (s, grain) => (qperiods?.grains?.[grain] ?? [])
.filter(r => r.metrics?.[s.pooled]?.value != null)
.map(r => ({day: grain === "week" ? r.period : `${r.period}-01`, label: periodName(grain, r.period), partial: r.partial, value: r.metrics[s.pooled].value}))
.map(r => ({...r, date: new Date(`${r.day}T12:00:00Z`)}))guard(() => {
if (days.length === 0) return noData();
if (period === "hour") {
const hourly = qperiods?.grains?.hour?.pooled;
const pooled = series.filter(s => hourly?.metrics?.[s.pooled]?.length);
const none = series.filter(s => !pooled.includes(s)).map(s => s.title.toLowerCase());
if (pooled.length === 0) return emptyNote("unavailable", "The figures by hour");
const span = hourly.first_service_date === hourly.last_service_date ? `on ${longDate(hourly.last_service_date)}` : `from ${longDate(hourly.first_service_date)} to ${longDate(hourly.last_service_date)}`;
return html`<p class="note">By the hour each trip or departure was scheduled, in Pacific time, ${span}. Not measured by hour: ${none.join("; ")}.</p>
<div class="chart-grid small">${pooled.map(s => {
const rows = hourly.metrics[s.pooled].map(r => ({...r, label: hourLabel(r.hour)}));
return ch.figure({
title: s.title,
chart: ch.bars(rows, {category: "label", value: "value", upright: true, format: fmtShare, ariaLabel: `${s.title}, by scheduled hour`,
tip: d => `${d.label}\n${fmtShare(d.value)}\n${count(d.numerator)} of ${count(d.denominator)}`}),
});
})}</div>${howMeasured}`;
}
if (period === "week" || period === "month") {
const drawn = series.filter(s => s.pooled && periodRows(s, period).length);
const none = series.filter(s => !drawn.includes(s)).map(s => s.title.toLowerCase());
if (drawn.length === 0) return emptyNote("unavailable", `The figures by ${period}`);
return html`<p class="note">Each ${period} pools its service days: the ${period}'s seen trips over its scheduled trips, and so on, so a busier day counts for more.${none.length ? ` Shown by day only: ${none.join("; ")}.` : ""}</p>
<div class="chart-grid small">${drawn.map(s => {
const rows = periodRows(s, period);
return rows.length < 2
? ch.figure({title: s.title, value: say(s, rows[0].value), chart: html`<p class="empty">${rows[0].label}${rows[0].partial ? " (part)" : ""}: ${say(s, rows[0].value)}. A line appears once a second ${period} comes in.</p>`})
: ch.figure({
title: s.title, value: say(s, rows.at(-1).value),
chart: ch.trend(rows, {y: "value", share: !!s.share, height: 150, maxTicks: 4,
ariaLabel: `${s.title}, by ${period}`, describe: `Latest ${period}: ${say(s, rows.at(-1).value)}.`,
tip: d => `${d.label}${d.partial ? " (part)" : ""}\n${say(s, d.value)}`}),
});
})}</div>${howMeasured}`;
}
if (days.length < 2) return emptyNote("one-day", "Charts that follow each measure over time");
const shown = recentDays(days, showAll);
return html`<div class="chart-grid small">${series.map(s => ch.figure({
title: s.title, value: say(s, days.at(-1)[s.key]),
chart: ch.trend(shown, {
y: s.key, share: !!s.share, height: 150, maxTicks: 4, yLabel: s.share ? null : `${s.word}s`,
ariaLabel: `${s.title}, by service day`,
describe: `From ${longDate(shown[0].day)} to ${longDate(latestDate)}. Latest value: ${say(s, days.at(-1)[s.key])}. Every day's value is in the table under "All days".`,
tip: d => `${longDate(d.day)}\n${say(s, d[s.key])}`,
}),
}))}</div>${howMeasured}`;
}, "The charts over time")Details
guard(() => latest == null ? noData() : html`<p>These details are for ${longDate(latestDate)}${latest.schedule?.passio_version
? html`, measured against Passio schedule version <code>${latest.schedule.passio_version}</code>` : ""}.</p>`, "The day's details")Trip coverage by route
guard(() => {
const rows = Object.entries(latest?.coverage?.by_route ?? {}).map(([id, c]) => ({route: routeName(id), ...c}));
if (rows.length === 0) return noData();
return ch.figure({
chart: ch.bars(rows, {
category: "route", value: "coverage", axisLabel: "Share of scheduled trips seen",
ariaLabel: `Share of scheduled trips seen in the tracking, by route, ${longDate(latestDate)}`,
tip: d => `${d.route}\n${count(d.observed)} of ${count(d.scheduled)} trips (${pct(d.coverage)})`,
}),
table: ch.table(rows, {
caption: `Scheduled trips seen in the tracking, by route, ${longDate(latestDate)}`,
sort: {key: "coverage", descending: true}, pageSize: 40,
columns: [
{key: "route", label: "Route"},
{key: "coverage", label: "Trips seen", align: "right", format: v => pct(v)},
{key: "observed", label: "Seen", align: "right", format: count},
{key: "scheduled", label: "Scheduled", align: "right", format: count},
],
}),
});
}, "Trip coverage by route")Timepoint events observed, by route
This shows how many scheduled departures at printed timepoints (or arrivals, at a trip’s last stop) we could put a time on, using the bus locations.
guard(() => {
const rows = Object.entries(ev?.stop_coverage?.timepoints?.by_route ?? {}).map(([id, c]) => ({
route: routeName(id), ...c, off_shape_share: ev?.shape_fit?.by_route?.[id]?.off_shape_share ?? null}));
if (rows.length === 0) return noData();
return ch.figure({
chart: ch.bars(rows, {
category: "route", value: "coverage", axisLabel: "Share of scheduled timepoint events observed",
ariaLabel: `Share of scheduled timepoint events we could time, by route, ${longDate(latestDate)}`,
tip: d => `${d.route}\n${count(d.observed)} of ${count(d.scheduled)} events (${pct(d.coverage)})\nPositions off the route shape: ${pct(d.off_shape_share, 1)}`,
}),
table: ch.table(rows, {
caption: `Scheduled timepoint events we could time, by route, ${longDate(latestDate)}`,
sort: {key: "coverage", descending: true}, pageSize: 40,
columns: [
{key: "route", label: "Route"},
{key: "coverage", label: "Events timed", align: "right", format: v => pct(v)},
{key: "observed", label: "Timed", align: "right", format: count},
{key: "scheduled", label: "Scheduled", align: "right", format: count},
{key: "off_shape_share", label: "Locations off route", align: "right", format: v => pct(v, 1)},
],
}),
});
}, "Timepoint events by route")Arrival predictions
For each prediction, we take the arrival time the feed was showing a given number of minutes ahead and subtract the arrival time we estimated from the bus’s locations. A positive error means the bus showed up earlier than the feed said it would. Some predictions carry the wrong day’s date, so we count those separately and leave them out of the error figures. A few others are off by hours, which pulls the mean far from the typical miss, so the table gives both the mean and the median and counts the predictions that were off by more than 30 minutes.
// A quantile dot chart: the 20 dots are the 2.5th, 7.5th, ... 97.5th
// percentiles of the miss, so each dot stands for 1 in 20 predictions.
guard(() => {
const q = ev?.prediction_error?.by_horizon_min?.["5"]?.quantiles_20_s;
if (!Array.isArray(q) || q.length !== 20 || !q.every(Number.isFinite)) return html``;
const LO = -15, HI = 10;
const later = q.map(s => -s / 60); // minutes the bus came after the prediction
const height = {};
const dots = later.map(m => {
const shown = Math.max(LO, Math.min(HI, m));
const bin = Math.round(shown);
height[bin] = (height[bin] ?? 0) + 1;
return {m, bin, y: height[bin], clipped: m !== shown};
});
const near = later.filter(m => Math.abs(m) <= 1).length;
const late = later.filter(m => m > 2).length, early = later.filter(m => m < -2).length;
const say = `Of 20 buses the feed said would arrive in 5 minutes, about ${near} came within a minute of that, ${late} came more than 2 minutes later and ${early} more than 2 minutes sooner.`;
return ch.figure({
title: `Arrival predictions made 5 minutes ahead, ${longDate(latestDate)}`,
note: `${say} Each dot stands for 1 in 20 predictions; a hollow dot at an edge stands for a miss of more than ${-LO} minutes sooner or ${HI} minutes later.`,
chart: ch.responsive((width) => Plot.plot({
ariaLabel: "Twenty dots, each 1 in 20 arrival predictions made 5 minutes ahead, by how many minutes later than predicted the bus came",
ariaDescription: say,
style: {background: "transparent", fontSize: "12px", overflow: "visible"},
width, height: 30 + 16 * Math.max(4, ...Object.values(height)), marginBottom: 36, marginLeft: 12, marginRight: 12,
x: {domain: [LO - 0.5, HI + 0.5], label: "Minutes later than predicted (negative: sooner)", ticks: [-15, -10, -5, 0, 5, 10], grid: true},
y: {axis: null, domain: [0, Math.max(4, ...Object.values(height)) + 0.5]},
marks: [
Plot.ruleX([0], {stroke: "var(--rule)"}),
Plot.dot(dots, {x: "bin", y: "y", r: 6, fill: d => d.clipped ? "var(--surface)" : "var(--series-1)", stroke: "var(--series-1)", strokeWidth: 1.5}),
Plot.tip(dots, Plot.pointer({x: "bin", y: "y", title: d => `${Math.abs(d.m).toFixed(1)} minutes ${d.m >= 0 ? "later" : "sooner"} than predicted`})),
],
}), {height: 120}),
methods: "feed-quality-metrics",
});
}, "The prediction dot chart")guard(() => {
const rows = Object.entries(ev?.prediction_error?.by_horizon_min ?? {}).map(([ahead, b]) => ({ahead: +ahead, ...b}));
if (rows.length === 0) return noData();
const seconds = v => num(v, 1);
return ch.table(rows, {
caption: `Arrival prediction error by minutes ahead, ${longDate(latestDate)}`, wide: true,
columns: [
{key: "ahead", label: "Minutes ahead", align: "right"},
{key: "n", label: "Predictions", align: "right", format: count},
{key: "bias_s", label: "Mean error (seconds)", align: "right", format: seconds},
{key: "median_s", label: "Median error (seconds)", align: "right", format: seconds},
{key: "median_abs_s", label: "Typical miss (seconds)", align: "right", format: seconds},
{key: "mae_s", label: "Mean miss (seconds)", align: "right", format: seconds},
{key: "within_60s_share", label: "Within 60 seconds", align: "right", format: v => pct(v, 1)},
{key: "over_30min", label: "Off by over 30 minutes", align: "right", format: count},
{key: "other_day", label: "Dated another day", align: "right", format: count},
],
});
}, "The prediction figures")Fields the feed leaves empty
This table shows how often each field is missing from the position reports. When a field is missing from every single report, the feed simply doesn’t send it.
guard(() => {
const rows = Object.entries(latest?.nonresponse?.items?.missing_share ?? {}).map(([field, share]) => ({field, share}));
if (rows.length === 0) return noData();
return ch.table(rows, {
caption: `Share of position reports missing each field, ${longDate(latestDate)}`, pageSize: 40,
columns: [
{key: "field", label: "Field", format: v => h("code", {}, v)},
{key: "share", label: "Missing", align: "right", format: v => pct(v, 1)},
],
});
}, "The table of empty fields")Other figures for the day
guard(() => {
if (latest == null) return noData();
const q = latest, m = q.measurement ?? {}, fit = ev?.shape_fit ?? {};
const refresh = q.paradata?.tripUpdates?.refresh;
const canceled = q.coverage?.canceled_trips;
const of = (a, b) => a == null || b == null ? "–" : `${count(a)} of ${count(b)}`;
const rows = [
["Fetch failures, vehicle positions", pct(q.nonresponse?.fetch?.vehiclePositions?.rate, 2)],
["Empty vehicle feed while buses are scheduled", pct(q.nonresponse?.vehicle_feed?.empty_in_service_rate, 2)],
["Positions with no trip, an unknown trip, or a trip not scheduled that day", pct(q.coverage?.over_coverage?.share, 2)],
["Trips the feed marked as canceled", canceled == null ? "not measured for this day" : canceled === 0 ? "none" : count(canceled)],
["Impossible jumps (over 130 km/h, about 80 mph)", count(m.impossible_jumps_over_130_kmh)],
["Vehicle timestamps in the future", count(m.timestamps_in_future)],
["Vehicle timestamps going backwards", count(m.timestamps_going_backwards)],
["Trip ids found in the schedule", pct(q.processing?.id_match?.trip_id?.match_rate, 1)],
["Stop ids found in the schedule", pct(q.processing?.id_match?.stop_id?.match_rate, 1)],
["Median response time, vehicle positions", unit(q.paradata?.vehiclePositions?.latency_ms_median, "millisecond")],
...(refresh == null ? [] : [
["Checks 20 seconds apart in which a trip's prediction had changed", pct(refresh.changed_share, 1)],
["Typical time between new predictions for a trip", unit(refresh.update_interval_s_median, "second")],
]),
["Distinct vehicles reporting", count(q.coverage?.vehicles_seen)],
...(ev == null ? [] : [
["All stop events with an inferred time", pct(ev.stop_coverage?.all_stops?.coverage, 1)],
["Positions more than 100 meters (about 330 feet) off the route shape", pct(fit.off_shape_share, 1)],
["Positions moving against the route shape", pct(fit.wrong_direction_share, 1)],
["Trips that left out part of the published route shape", fit.trips_skipping_part_of_shape == null ? "–"
: `${count(fit.trips_skipping_part_of_shape)} (${num(fit.skipped_km, 1)} km, about ${num(fit.skipped_km * 0.621371, 1)} miles)`],
["Route shapes that draw segments three times (corrected)", of(ev.retraced_shapes?.shapes_retraced, ev.retraced_shapes?.shapes_used)],
["Trip ids seen that are not scheduled that day", of(ev.assignment?.unassignable, ev.assignment?.observed_trip_ids)],
["Position jitter at terminals, 95th percentile", ev.jitter?.jitter_m_p95 == null ? "–"
: `${num(ev.jitter.jitter_m_p95, 1)} meters (about ${num(ev.jitter.jitter_m_p95 * 3.28084)} feet)`],
["Vehicles seen in the previous 30 days but not this day",
ev.missing_vehicles == null ? "–" : ev.missing_vehicles.missing_count == null ? "no earlier days" : count(ev.missing_vehicles.missing_count)],
]),
].map(([measure, value]) => ({measure, value}));
return ch.table(rows, {
caption: `Other quality figures for ${longDate(latestDate)}`, pageSize: 40,
columns: [{key: "measure", label: "Measure", sortable: false}, {key: "value", label: "Value", align: "right", sortable: false}],
});
}, "The day's other figures")Randomness of gaps
When the feed misses a trip, is that bad luck spread evenly, or does it tend to happen at certain hours, on certain routes, or when lots of buses are out at once? The tables below show the share of scheduled trips that sent no position report around the time they were due, over every day so far. Once there are enough days and enough missed trips, a statistical model called a logistic regression will test all of these at the same time.
gaps = json("data/quality/gaps.json")
pval = p => p == null ? "–" : p < 0.0001 ? "< 0.0001" : `= ${num(p, 4)}`guard(() => {
const rates = gaps?.rates;
if (rates == null || Object.keys(rates).length === 0) return noData();
const named = Object.fromEntries(Object.entries(rates.by_route ?? {}).map(([id, v]) => [routeName(id), v]));
const groups = [
["Hour band (Pacific)", rates.by_hour_band, false],
["Trips in service at the trip's start", rates.by_trips_in_service, false],
["Day type", rates.by_day_type, false],
["Route", named, true],
].filter(([, t]) => t && Object.keys(t).length);
return html`
<p>Over ${plural(gaps.days?.length ?? 0, "day")}, ${count(gaps.trips)} trips were scheduled and
${count(gaps.unobserved)} sent no position report within 30 minutes of their scheduled time.</p>
<div class="chart-grid">${groups.map(([title, t, sortable]) => html`<div>
<h3 class="chart-title">${title}</h3>
${ch.table(Object.entries(t).map(([group, v]) => ({group, ...v})), {
caption: `Scheduled trips not seen, by ${title.toLowerCase()}`, pageSize: 40,
columns: [
{key: "group", label: "Group", sortable},
{key: "scheduled", label: "Scheduled", align: "right", format: count, sortable},
{key: "unobserved", label: "Not seen", align: "right", format: count, sortable},
{key: "rate", label: "Share not seen", align: "right", format: v => pct(v, 1), sortable},
],
})}</div>`)}</div>`;
}, "The gap tables")guard(() => {
if (gaps == null) return html``;
const model = gaps.model;
if (model == null) {
const status = gaps.model_status ?? "";
return status === "" ? html`` : html`<p><em>${status.startsWith("not fitted: needs")
? `The model hasn't been fitted yet, because it ${status.slice("not fitted: ".length)}.`
: `Model status: ${status}.`}</em></p>`;
}
// The file named these with spaces at first and with underscores since.
const ref = model.reference_levels ?? {};
const level = key => ref[key] ?? ref[key.replace("_", " ")];
const test = model.lr_test_all_predictors ?? {};
const terms = (model.terms ?? []).filter(t => t.term !== "intercept").map(t => ({...t,
term: t.term.startsWith("route: ") ? `route: ${routeName(t.term.slice(7))}` : t.term.replaceAll("_", " "),
low: t.or_95ci?.[0], high: t.or_95ci?.[1]}));
return html`
<p>This logistic regression looks at ${count(model.trips)} trips and asks which ones the feed missed. We fit it with
Firth's penalized likelihood, which keeps the estimates sensible even when a route never missed a trip.
Testing all the predictors together gives χ² = ${num(test.statistic, 1)},
df = ${count(test.df)}, p ${pval(test.p)}.
A small p-value means the gaps are not missing completely at random, so something about the hour, the route,
the day or the number of buses out is tied to which trips go missing. The model treats every trip as
separate, but trips lost on the same day or the same bus tend to go missing together, so the p-values
here are more confident than they should be. Each odds ratio compares a group with
${level("hour_band")}, route ${routeName(level("route"))}
and ${level("day_type")}.${model.converged ? "" : " The model did not settle on a stable answer (it did not converge), so treat these numbers with caution."}</p>
${ch.table(terms, {
caption: "Odds ratios from the model of which trips the feed missed", pageSize: 40,
columns: [
{key: "term", label: "Term"},
{key: "odds_ratio", label: "Odds ratio", align: "right", format: v => num(v, 2)},
{key: "low", label: "95% interval, low", align: "right", format: v => num(v, 2)},
{key: "high", label: "95% interval, high", align: "right", format: v => num(v, 2)},
{key: "p", label: "p", align: "right", format: v => pval(v).replace(/^= /, "")},
],
})}`;
}, "The model of gaps")All days
guard(() => {
const rows = withDates(daily).map(d => ({...d, holiday: isFalse(d.service_expected), predict: minutes(d.prediction_median_abs_s_5min)})).reverse();
if (rows.length === 0) return noData();
return ch.table(rows, {
caption: "Daily quality figures for every archived day", wide: true, pageSize: 15,
columns: [
{key: "day", label: "Service day", format: v => longDate(v)},
{key: "holiday", label: "Buses scheduled", format: v => v ? "No service (holiday)" : "Yes", sortValue: d => d.holiday ? 0 : 1},
{key: "scheduled_trips", label: "Scheduled trips", align: "right", format: count},
{key: "trip_coverage", label: "Trips seen", align: "right", format: v => pct(v, 1)},
{key: "vehicle_uptime", label: "Collector uptime", align: "right", format: v => pct(v, 2)},
{key: "stale_in_service_rate", label: "Feed over 2 minutes behind", align: "right", format: v => pct(v, 1)},
{key: "position_age_s_median", label: "Location age (seconds)", align: "right", format: v => num(v, 1)},
{key: "longest_gap_s_median", label: "Longest gap per trip (seconds)", align: "right", format: v => num(v, 1)},
{key: "timepoint_coverage", label: "Timepoint events timed", align: "right", format: v => pct(v, 1)},
{key: "off_shape_share", label: "Locations off route", align: "right", format: v => pct(v, 1)},
{key: "predict", label: "Typical prediction miss, 5 minutes ahead (minutes)", align: "right", format: v => num(v, 1)},
],
});
}, "The table of all days")