mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
A live source may now declare a timeline: it can answer a snapshot at a
given time (source.timeline = { coverage(), stepMs, subscribe? }, read by
readSnapshotTimeline). While such a layer is on it follows the world clock
and registers the coverage. At the live edge it polls exactly as before;
away from it the layer asks for getSnapshot({ ...query, atMs }) at the step
at or before the clock time and shows that snapshot instead of polling.
src/time/snapshotTimeline.js owns the following: a seek, time going
backwards or leaving live replaces every contact with the snapshot at the
new time (play waits on it, for at most 8 s); playing on keeps one
snapshot ahead and gates play on it, applying those snapshots as polls so
contacts move smoothly; outside coverage the layer is empty; back at live
it is cleared and polls at once. One load at a time, and a load the
source drops for a newer one is not a failure.
While following, aircraft are drawn at the clock time with no render
delay, records and absences are judged at the clock, track requests carry
atMs, and vessels move between fixes along the great circle. The world
clock counts jumps (seeks and returns to live) in getState().
A source with no timeline never follows the clock, and every layer stays
live, unchanged.
89 lines
2.9 KiB
JavaScript
89 lines
2.9 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { MilitaryFlightRecords } from './records.js';
|
|
import { createIngestion, createMilitaryFeed } from './ingestion.js';
|
|
import { displayDelayMs, RENDER_DELAY_SEC } from './policy.js';
|
|
|
|
// Military aircraft follow the world clock only while their source declares
|
|
// a timeline (src/time/snapshotTimeline.js); these cover the layer's side.
|
|
|
|
const T = 1_800_000_000_000;
|
|
|
|
test('military contacts are drawn behind the live edge, and at the time following the clock', () => {
|
|
assert.equal(displayDelayMs({ timeline: null }), RENDER_DELAY_SEC * 1000);
|
|
assert.equal(displayDelayMs({ timeline: { active: () => false } }), 15_000);
|
|
assert.equal(displayDelayMs({ timeline: { active: () => true } }), 0);
|
|
});
|
|
|
|
test('military records judge absence at the layer clock and reset at a jump', () => {
|
|
let now = T;
|
|
const store = new MilitaryFlightRecords({
|
|
geoidHeight: () => 0,
|
|
cachedGroundFloor: () => null,
|
|
floorAltitudeM: (altitude) => altitude,
|
|
now: () => now,
|
|
});
|
|
const { meta } = store.receive(
|
|
{
|
|
id: 'ae0001',
|
|
reference: 'ae0001',
|
|
latitude: 39,
|
|
longitude: -77,
|
|
baroAltitudeM: 3000,
|
|
onGround: false,
|
|
positionTimeMs: T - 1_000,
|
|
},
|
|
{ observedAtMs: T, floorWarmPoints: [] },
|
|
);
|
|
assert.equal(meta.observedReceiptMs, T);
|
|
assert.equal(
|
|
store.absence('ae0001', { complete: true, tracked: true }),
|
|
'stale',
|
|
);
|
|
now = T + 11 * 60_000;
|
|
assert.equal(
|
|
store.absence('ae0001', { complete: true, tracked: true }),
|
|
'remove',
|
|
);
|
|
store.receive(
|
|
{ id: 'ae0001', latitude: 39, longitude: -77, positionTimeMs: T },
|
|
{ observedAtMs: T, floorWarmPoints: [] },
|
|
);
|
|
store.absence('ae0001', { complete: true });
|
|
store.reset();
|
|
assert.equal(store.data.size, 0);
|
|
assert.equal(store.missingPolls.size, 0);
|
|
assert.equal(store.lastSnapshotMs, null);
|
|
});
|
|
|
|
test('military polls carry no time; a snapshot at a time carries it, and polls stop following', async () => {
|
|
const queries = [];
|
|
const applied = [];
|
|
let follows = false;
|
|
const feed = createMilitaryFeed({
|
|
async getSnapshot(query) {
|
|
queries.push(query);
|
|
return { records: [], observedAtMs: T, freshness: 'current' };
|
|
},
|
|
});
|
|
const { methods } = createIngestion({
|
|
feed,
|
|
applySnapshot: (_snapshot, _viewer, options) => {
|
|
applied.push(options);
|
|
return { count: 0, ids: new Set() };
|
|
},
|
|
setSourceLabel: () => {},
|
|
applyPendingTrackingRestore: () => {},
|
|
followsClock: () => follows,
|
|
});
|
|
await methods.update(null);
|
|
assert.deepEqual(queries, [{}]);
|
|
assert.deepEqual(applied, [undefined]);
|
|
follows = true;
|
|
await methods.update(null);
|
|
assert.equal(queries.length, 1, 'no poll while following');
|
|
assert.equal(await methods.loadAt(T, { replace: true }), true);
|
|
assert.deepEqual(queries[1], { atMs: T });
|
|
assert.deepEqual(applied[1], { replace: true });
|
|
});
|