Files
gods-eye-view/src/data/adsbLolFallback.test.mjs
T
Sameh Khamis fd06272e37 fix(flights): an aircraft with no ground track faces its true heading, not north
readsb rows (adsb.lol and a local dump1090 receiver) often send no track for
an aircraft on the ground, only its true heading. The track then read as
missing and the aircraft was drawn facing north, so one taxiing south looked
like it was moving backwards. Each normalizer now falls back to true_heading,
never the magnetic heading.
2026-11-14 08:49:29 -08:00

64 lines
1.9 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {
normalizeAdsbLolAircraftState,
normalizeAdsbLolPointResponse,
} from './adsbLolFallback.js';
test('normalizes adsb.lol units into an OpenSky-compatible state vector', () => {
const state = normalizeAdsbLolAircraftState({
hex: 'A1B2C3',
flight: 'UAL123 ',
lat: 30,
lon: -97,
alt_baro: 10000,
alt_geom: 10200,
gs: 200,
track: 90,
baro_rate: 600,
seen_pos: 2,
seen: 1,
category: 'A3',
}, 1000);
assert.equal(state[0], 'a1b2c3');
assert.equal(state[1], 'UAL123');
assert.equal(state[2], null);
assert.equal(state[3], 998);
assert.equal(state[5], -97);
assert.equal(state[6], 30);
assert.equal(state[7], 3048);
assert.ok(Math.abs(state[9] - 102.8888) < 0.001);
assert.equal(state[10], 90);
assert.ok(Math.abs(state[11] - 3.048) < 0.001);
assert.equal(state[13], 3108.96);
assert.equal(state[17], 4);
});
test('keeps grounded fallback contacts and rejects rows without positions', () => {
const normalized = normalizeAdsbLolPointResponse({
now: 1_700_000_000_000,
ac: [
{ hex: 'abc123', lat: 0, lon: 0, alt_baro: 'ground', gs: 8 },
{ hex: 'def456', lat: null, lon: 10, alt_baro: 5000 },
],
});
assert.equal(normalized.time, 1_700_000_000);
assert.equal(normalized.states.length, 1);
assert.equal(normalized.states[0][7], null);
assert.equal(normalized.states[0][8], true);
});
test('an aircraft with no track takes its true heading, never its magnetic one', () => {
const at = (extra) =>
normalizeAdsbLolAircraftState(
{ hex: 'abc123', lat: 37.7, lon: -122.2, alt_baro: 'ground', ...extra },
1000,
)[10];
assert.equal(at({ track: 56.25, true_heading: 40 }), 56.25, 'track first');
assert.equal(at({ true_heading: 244.69 }), 244.69, 'true heading');
assert.equal(at({ mag_heading: 278.44 }), null, 'not magnetic');
assert.equal(at({}), null, 'none');
});