mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
readsb omits lat/lon for a contact heard without a current position; about a third of every /v2/mil response is such rows. They made every military snapshot partial, so a contact that left the feed was retained at full opacity for five minutes instead of fading and leaving on the missed-poll limits. A row with a hex and no lat/lon now leaves the snapshot complete and is listed in retainIds, as OpenSky's null-position rows already are.
177 lines
5.8 KiB
JavaScript
177 lines
5.8 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { MilitaryFlightRecords } from './records.js';
|
|
const observation = (fields = {}) => ({
|
|
id: 'aaa001',
|
|
reference: 'aaa001',
|
|
longitude: -77,
|
|
latitude: 39,
|
|
baroAltitudeM: 1000,
|
|
ellipsoidAltitudeM: null,
|
|
onGround: false,
|
|
callsign: 'MIL1',
|
|
typeCode: 'C17',
|
|
speedMps: 100,
|
|
courseDeg: 90,
|
|
verticalRateMps: 1,
|
|
positionTimeMs: 1700000000000,
|
|
...fields,
|
|
});
|
|
const context = (fields = {}) => ({
|
|
observedAtMs: 1700000001000,
|
|
floorWarmPoints: [],
|
|
modelOwnsVisual: false,
|
|
...fields,
|
|
});
|
|
const store = () =>
|
|
new MilitaryFlightRecords({
|
|
geoidHeight: () => 40,
|
|
cachedGroundFloor: () => 200,
|
|
floorAltitudeM: (height, floor) => Math.max(height, floor + 1.5),
|
|
});
|
|
|
|
test('military records preserve feet for aviation, metres for rendering and source epochs', () => {
|
|
const records = store();
|
|
records.geoidReady = true;
|
|
const first = records.receive(observation(), context());
|
|
assert.equal(first.meta.altitudeFt, 1000 / 0.3048);
|
|
assert.equal(first.meta.renderAltitudeM, 1040);
|
|
assert.equal(first.fixEpochMs, 1700000000000);
|
|
const next = records.receive(
|
|
observation({ callsign: '', typeCode: '', positionTimeMs: null }),
|
|
context(),
|
|
);
|
|
assert.equal(next.meta.callsign, 'MIL1');
|
|
assert.equal(next.meta.type, 'C17');
|
|
assert.equal(next.fixEpochMs, 1700000001000);
|
|
assert.equal(Object.hasOwn(next.meta, 'cullPosition'), false);
|
|
});
|
|
|
|
test('military ground records leave model-owned placement alone and warm the same floor cell', () => {
|
|
const records = store();
|
|
const owned = context({ modelOwnsVisual: true });
|
|
const first = records.receive(
|
|
observation({ onGround: true, baroAltitudeM: null }),
|
|
owned,
|
|
);
|
|
assert.equal(first.meta.renderAltitudeM, 0);
|
|
assert.deepEqual(owned.floorWarmPoints, [{ lat: 39, lon: -77 }]);
|
|
const unowned = context();
|
|
const second = records.receive(
|
|
observation({ onGround: true, baroAltitudeM: null }),
|
|
unowned,
|
|
);
|
|
assert.equal(second.meta.renderAltitudeM, 201.5);
|
|
assert.deepEqual(unowned.floorWarmPoints, owned.floorWarmPoints);
|
|
});
|
|
|
|
test('military records keep bounded partial retention and release metadata only after removal admission', () => {
|
|
const first = store();
|
|
const second = store();
|
|
const { meta } = first.receive(observation(), context());
|
|
assert.equal(second.data.size, 0);
|
|
assert.equal(
|
|
first.absence('aaa001', { complete: false, likelyLanded: true }),
|
|
'retain',
|
|
);
|
|
meta.observedReceiptMs = Date.now() - 300001;
|
|
assert.equal(
|
|
first.absence('aaa001', { complete: false, likelyLanded: false }),
|
|
'stale',
|
|
);
|
|
assert.equal(
|
|
first.absence('aaa001', { complete: true, likelyLanded: false }),
|
|
'stale',
|
|
);
|
|
assert.equal(
|
|
first.absence('aaa001', { complete: true, likelyLanded: false }),
|
|
'remove',
|
|
);
|
|
assert.equal(first.data.get('aaa001'), meta);
|
|
first.forget('aaa001');
|
|
assert.equal(first.data.size, 0);
|
|
assert.equal(first.geoidNCache.size, 0);
|
|
assert.equal(first.missingPolls.size, 0);
|
|
first.receive(observation(), context());
|
|
assert.equal(
|
|
first.absence('aaa001', { complete: true, likelyLanded: true }),
|
|
'remove',
|
|
);
|
|
});
|
|
|
|
test('complete military snapshots age out vanished aircraft and retain position-less ones unless landed', () => {
|
|
const records = store();
|
|
for (const id of ['aaa001', 'aaa002', 'aaa003'])
|
|
records.receive(observation({ id, reference: id }), context());
|
|
// aaa001 and aaa003 are still listed without a position; aaa002 vanished.
|
|
const absent = (id, likelyLanded = false) =>
|
|
records.absence(id, {
|
|
complete: true,
|
|
retainIds: new Set(['aaa001', 'aaa003']),
|
|
likelyLanded,
|
|
});
|
|
assert.deepEqual(
|
|
[absent('aaa002'), absent('aaa002'), absent('aaa002')],
|
|
['stale', 'stale', 'remove'],
|
|
);
|
|
assert.equal(absent('aaa001'), 'retain');
|
|
assert.equal(records.missingPolls.has('aaa001'), false);
|
|
// A landed contact that lost its position takes the landed fast-cull.
|
|
assert.equal(absent('aaa003', true), 'remove');
|
|
// Position-less retention stays bounded like partial admission.
|
|
records.data.get('aaa001').observedReceiptMs = Date.now() - 300001;
|
|
assert.equal(absent('aaa001'), 'stale');
|
|
});
|
|
|
|
test('military emergency status follows the latest poll instead of sticking', () => {
|
|
const records = store();
|
|
const first = records.receive(
|
|
observation({ squawk: '1234', emergency: 'minfuel' }),
|
|
context(),
|
|
);
|
|
assert.equal(first.meta.squawk, '1234');
|
|
assert.equal(first.meta.emergency.kind, 'minfuel');
|
|
assert.equal(first.meta.emergency.severity, 'priority');
|
|
const next = records.receive(
|
|
observation({ squawk: '1234', emergency: 'none' }),
|
|
context(),
|
|
);
|
|
assert.equal(next.meta.emergency, null);
|
|
});
|
|
|
|
test('military records hold the last track and speed when a poll omits them', () => {
|
|
const records = store();
|
|
records.receive(observation({ courseDeg: 270, speedMps: 200 }), context());
|
|
const missing = records.receive(
|
|
observation({ courseDeg: null, speedMps: null }),
|
|
context(),
|
|
);
|
|
assert.equal(missing.meta.track, 270);
|
|
assert.equal(missing.meta.speedMps, 200);
|
|
const north = records.receive(
|
|
observation({ courseDeg: 0, speedMps: 0 }),
|
|
context(),
|
|
);
|
|
assert.equal(north.meta.track, 0);
|
|
assert.equal(north.meta.speedMps, 0);
|
|
const unseen = store().receive(
|
|
observation({ courseDeg: undefined, speedMps: undefined }),
|
|
context(),
|
|
);
|
|
assert.equal(unseen.meta.track, 0);
|
|
assert.equal(unseen.meta.speedMps, 0);
|
|
const landing = store();
|
|
landing.receive(observation({ courseDeg: 90, speedMps: 70 }), context());
|
|
const parked = landing.receive(
|
|
observation({
|
|
onGround: true,
|
|
baroAltitudeM: null,
|
|
courseDeg: null,
|
|
speedMps: null,
|
|
}),
|
|
context(),
|
|
);
|
|
assert.equal(parked.meta.speedMps, 0);
|
|
assert.equal(parked.meta.track, 90);
|
|
});
|