Files
gods-eye-view/src/data/adsbLolFallback.test.mjs
T
Sameh Khamis f2537743ab fix(flights): class an aircraft by its feed's type from the first fix
A civil aircraft was drawn as an airliner until its type lookup answered,
even when its feed already named the type: a helicopter showed the
airliner icon and model for as long as the lookup took.

- Flights classes every contact, and picks its model, by the feed's own
  ICAO type designator from the first fix. A looked-up type replaces it
  once the lookup answers and outranks the feed's on every later poll;
  the lookup still runs and fills the type name and registration.
- A surface emitter category still keeps only a ground type (ZVEH, GRND)
  from the feed.
- State vectors have no type field, so an /api/flights answer may send
  `typeByIcao` beside them, by ICAO address, as `emergencyByIcao` is sent.
  The regional adsb.lol fallback now sends it from each row's `t`.
2026-11-17 17:37:48 -08:00

83 lines
2.6 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');
});
test('the point response sends each admitted aircraft type alongside the vectors', () => {
const response = normalizeAdsbLolPointResponse({
now: 1000,
ac: [
{ hex: 'A1B2C3', lat: 30, lon: -97, t: 'ec45' },
{ hex: 'A1B2C3', lat: 31, lon: -97, t: 'B738' },
{ hex: 'D4E5F6', lat: 30, lon: -98 },
{ hex: 'BAD000', t: 'A320' },
],
});
assert.equal(response.states.length, 3);
assert.deepEqual(response.typeByIcao, { a1b2c3: 'EC45' });
const untyped = normalizeAdsbLolPointResponse({
now: 1000,
ac: [{ hex: 'D4E5F6', lat: 30, lon: -98 }],
});
assert.equal(Object.hasOwn(untyped, 'typeByIcao'), false);
});