Aircraft drawn as far behind real time as their feed is late, along one curve their trail follows

Civil and military aircraft were drawn a fixed 30 s (15 s) behind real time
while anonymous feed reports arrive about 90 s old every 30 s, so every
contact dead reckoned about a minute past its newest report and snapped
when the next one landed (several km on a turn), and the tracked trail,
recorded from those drawn positions and patched as reports arrived, kinked.

- The display delay (data/displayDelay.js) is the 90th percentile of the
  newest 256 report lags plus 5 s, between the layer's floor (30 s, 15 s)
  and five minutes, slewed at most 0.2 s/s up and 0.05 s/s down. Icons,
  the renderer's live motion clock, labels, HUD, detection, the tracked
  camera and the trail read the one delay; following the world clock
  draws with none and deliveries leave it alone.
- Between two reports an aircraft flies a biarc (data/fixCurve.js) that
  passes through both and leaves each along its track, sent as contract
  arc segments; the trail is the reports joined along the same curve, so
  the icon sits on it. Nothing drawn between reports is kept.
- A report a coasting contact missed is eased onto from where it would
  have been that frame (at least 3 s, at most 30% over its speed, within
  20 s); over 5 km it jumps. Past its newest report a contact coasts
  straight on: a turn rate averaged over earlier reports outlived the turn.
- Forward synthetic fixes no longer block real reports older than them,
  and a history keeps 24 fixes.
- A feed simulation (testSupport/aircraftFeedSim.mjs) checks both layers
  against a 90 s late feed, a fallback switch, repeated reports, outages
  and the world clock.
This commit is contained in:
Sameh Khamis committed 2026-11-14 00:31:29 -08:00
1 parent c57eb74506
commit 5f98f8bdf3
40 files changed
+2606 -1238

No files matched your search

+164
View File
@@ -0,0 +1,164 @@
/**
* @module data/displayDelay
* @description How far behind real time a live aircraft feed is drawn.
*
* Contacts are drawn at `now − delay` so that, at the time drawn, every
* contact has a report on both sides and is placed between two real reports
* instead of dead reckoned past its newest one. The delay has to cover how
* late the feed really is: a feed whose reports arrive 90 s old every 30 s
* needs about two minutes, a fresh one about half a minute.
*
* Each time a contact's report moves on, the feed's lag is how long the
* display had to wait for it: its receipt time less the contact's previous
* report time (lateness, the gap between reports and the wait for the next
* poll together). The delay aimed at is the 90th percentile of the newest 256
* lags plus 5 s, within the layer's floor and a five-minute cap. Before a
* feed has given 16 lags, its first reports stand in: their age plus one poll
* interval.
*
* The delay drawn with moves toward that aim at a bounded rate, rising by at
* most 0.2 s and falling by at most 0.05 s per second, so every contact
* slows or speeds up a little rather than the whole fleet jumping; an aim
* within 2 s of where it is leaves it there. Until a layer has drawn a
* contact, it takes its aim at once.
*/
/** @constant {number} Percentile of the recent lags the delay covers. */
export const DISPLAY_DELAY_RANK = 0.9;
/** @constant {number} How many recent lags the percentile is taken over. */
export const DISPLAY_DELAY_LAGS = 256;
/** @constant {number} Lags before they, rather than first reports, set the aim. */
export const DISPLAY_DELAY_MIN_LAGS = 16;
/** @constant {number} Added to the percentile for jitter (ms). */
export const DISPLAY_DELAY_MARGIN_MS = 5_000;
/** @constant {number} The longest delay (ms). */
export const DISPLAY_DELAY_CAP_MS = 300_000;
/** @constant {number} Delay gained per unit of real time, at most. */
export const DISPLAY_DELAY_RISE = 0.2;
/** @constant {number} Delay shed per unit of real time, at most. */
export const DISPLAY_DELAY_FALL = 0.05;
/** @constant {number} An aim this close (ms) to the delay leaves it be. */
export const DISPLAY_DELAY_DEADBAND_MS = 2_000;
function createWindow(capacity) {
return { values: new Float64Array(capacity), count: 0, cursor: 0 };
}
function add(window, value) {
if (!Number.isFinite(value) || value < 0) return;
window.values[window.cursor] = value;
window.cursor = (window.cursor + 1) % window.values.length;
window.count = Math.min(window.count + 1, window.values.length);
}
function percentile(window, rank) {
const sorted = window.values.slice(0, window.count).sort();
return sorted[Math.max(0, Math.ceil(sorted.length * rank) - 1)];
}
/**
* One live feed's display delay.
* @param {object} options
* @param {number} options.floorMs The shortest delay (ms), and where it starts.
* @param {number} options.pollMs How often the feed is asked (ms).
* @param {number} [options.capMs] The longest delay (ms).
*/
export function createDisplayDelay({
floorMs,
pollMs,
capMs = DISPLAY_DELAY_CAP_MS,
}) {
const lags = createWindow(DISPLAY_DELAY_LAGS);
const firstAges = createWindow(DISPLAY_DELAY_LAGS);
let aimMs = floorMs;
let fromMs = floorMs;
let fromAtMs = NaN;
let currentMs = floorMs;
const clamp = (ms) => Math.max(floorMs, Math.min(capMs, ms));
/** The delay at `nowMs` on its way from `fromMs` toward the aim. */
function delayAt(nowMs) {
if (!Number.isFinite(fromAtMs)) return fromMs;
const elapsed = Math.max(0, nowMs - fromAtMs);
const change = Math.max(
-DISPLAY_DELAY_FALL * elapsed,
Math.min(DISPLAY_DELAY_RISE * elapsed, aimMs - fromMs),
);
return fromMs + change;
}
return {
/** The delay contacts are drawn with now (whole ms), as last stepped. */
get currentMs() {
return currentMs;
},
/** The delay it is moving toward (ms). */
get aimMs() {
return aimMs;
},
/** Lags seen so far, up to the window. */
get lagCount() {
return lags.count;
},
/**
* A contact's report received at `receiptMs`: its time, and the
* contact's previous report time (none for a contact seen first).
*/
noteReport(receiptMs, reportMs, previousReportMs) {
if (Number.isFinite(previousReportMs)) {
if (reportMs > previousReportMs)
add(lags, receiptMs - previousReportMs);
} else if (Number.isFinite(reportMs))
add(firstAges, receiptMs - reportMs);
},
/**
* Aim again after a delivery. `jump`: nothing is drawn yet, so the delay
* takes the aim at once.
* @param {number} nowMs
* @param {{jump?: boolean}} [options]
* @returns {number} The delay now (whole ms).
*/
settle(nowMs, { jump = false } = {}) {
let next = aimMs;
if (lags.count >= DISPLAY_DELAY_MIN_LAGS)
next = clamp(
percentile(lags, DISPLAY_DELAY_RANK) + DISPLAY_DELAY_MARGIN_MS,
);
else if (firstAges.count)
next = clamp(
percentile(firstAges, DISPLAY_DELAY_RANK) +
pollMs +
DISPLAY_DELAY_MARGIN_MS,
);
const now = delayAt(nowMs);
fromMs = jump ? next : now;
fromAtMs = nowMs;
// An aim this close leaves the delay where it is.
aimMs =
Math.abs(next - now) < DISPLAY_DELAY_DEADBAND_MS && !jump ? now : next;
currentMs = Math.round(fromMs);
return currentMs;
},
/**
* Move the delay on to `nowMs`: what the contacts are drawn with until
* the next step.
* @returns {number} Whole ms.
*/
step(nowMs) {
currentMs = Math.round(delayAt(nowMs));
return currentMs;
},
/** Forget the feed: back to the floor, nothing learned. */
reset() {
lags.count = lags.cursor = 0;
firstAges.count = firstAges.cursor = 0;
aimMs = fromMs = currentMs = floorMs;
fromAtMs = NaN;
},
};
}