Merge remote-tracking branch 'origin/main' into selection/no-tint

# Conflicts:
#	docs/CURRENT-STATE.md
This commit is contained in:
Sameh Khamis committed 2026-11-17 18:46:23 -08:00
commit ca5e82ae41
10 files changed
+209 -25

No files matched your search

+9 -2
View File
@@ -98,7 +98,7 @@ export function normalizeAdsbLolAircraftState(aircraft, nowSeconds) {
* Normalize an adsb.lol point response to an OpenSky-compatible response.
* Invalid rows and positionless contacts are intentionally excluded.
* @param {object} payload adsb.lol v2 response.
* @returns {{time:number,states:Array[]}}
* @returns {{time:number,states:Array[],emergencyByIcao?:object,typeByIcao?:object}}
*/
export function normalizeAdsbLolPointResponse(payload) {
const responseNow = finiteNumber(payload?.now);
@@ -111,9 +111,10 @@ export function normalizeAdsbLolPointResponse(payload) {
const aircraft = Array.isArray(payload?.ac) ? payload.ac : [];
const states = [];
// Keep the OpenSky vectors unchanged. The regional fallback's extra readsb
// status travels alongside them, keyed only to admitted aircraft.
// status and type travel alongside them, keyed only to admitted aircraft.
const admitted = new Set();
const statuses = [];
const types = [];
for (const row of aircraft) {
const state = normalizeAdsbLolAircraftState(row, nowSeconds);
if (!state) continue;
@@ -125,11 +126,17 @@ export function normalizeAdsbLolPointResponse(payload) {
admitted.add(id);
if (typeof row.emergency === 'string')
statuses.push([id, row.emergency.trim().toLowerCase()]);
const type = typeof row.t === 'string' ? row.t.trim().toUpperCase() : '';
if (type) types.push([id, type]);
}
const emergencyByIcao = Object.fromEntries(statuses);
const typeByIcao = Object.fromEntries(types);
return {
time: nowSeconds,
states,
...(Object.keys(emergencyByIcao).length ? { emergencyByIcao } : {}),
// The ICAO type designator (readsb `t`), so the aircraft is classed from
// its first fix instead of after a lookup.
...(types.length ? { typeByIcao } : {}),
};
}
+19
View File
@@ -61,3 +61,22 @@ test('an aircraft with no track takes its true heading, never its magnetic one',
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);
});
+5 -1
View File
@@ -156,7 +156,11 @@ export function createEnrichment({
(data) => {
const meta = flightState.records.data.get(icao24);
if (!meta) return; // evicted while the lookup was in flight
meta.typeCode = data.typeCode || meta.typeCode;
// A looked-up type outranks the feed's own from now on.
if (data.typeCode) {
meta.typeCode = data.typeCode;
meta.typeLookedUp = true;
}
meta.typeName = data.typeName || meta.typeName;
meta.registration = data.registration || meta.registration;
if (meta.typeCode) {
+72
View File
@@ -608,3 +608,75 @@ test('a route answer for a callsign the plane no longer flies is dropped', async
assert.equal(meta.routeCallsign, 'UAL10');
flightState.lifetime.abort();
});
test("a type lookup overrides the feed's type and fills the type name", async () => {
const queries = [];
const source = {
getEnrichment(query) {
queries.push(query);
return Promise.resolve({
found: true,
typeCode: 'B738',
typeName: 'Boeing 737-800',
registration: 'N123AB',
});
},
};
const flightState = createFlightState({ source, services: services() });
const view = {
viewerLatDeg: null,
viewerLonDeg: null,
trackedId: null,
floorWarmPoints: [],
};
const { meta } = flightState.records.receive(
{
id: 'abc123',
reference: 'abc123',
longitude: -77,
latitude: 39,
callsign: 'TEST1',
baroAltitudeM: 1000,
typeCode: 'EC45',
},
view,
);
assert.equal(meta.klass, 'helicopter', 'classed by the feed type at once');
const restyled = [];
const synced = [];
const enrichment = createEnrichment({
flightState,
services: enrichServices(),
parts: {
icons: { _applyIconPresentation: (id) => restyled.push(id) },
rendering: { _syncModelToClass: (id) => synced.push(id) },
},
});
// A present feed type does not skip the lookup.
enrichment._requestTypeEnrichment('abc123', true);
await new Promise((done) => setImmediate(done));
assert.deepEqual(queries, [{ kind: 'type', id: 'abc123' }]);
const looked = flightState.records.data.get('abc123');
assert.equal(looked.typeCode, 'B738');
assert.equal(looked.typeName, 'Boeing 737-800');
assert.equal(looked.registration, 'N123AB');
assert.equal(looked.klass, 'airliner');
assert.deepEqual(restyled, ['abc123']);
assert.deepEqual(synced, ['abc123']);
// The next poll's feed type no longer wins.
const next = flightState.records.receive(
{
id: 'abc123',
reference: 'abc123',
longitude: -77,
latitude: 39,
callsign: 'TEST1',
baroAltitudeM: 1000,
typeCode: 'EC45',
},
view,
).meta;
assert.equal(next.typeCode, 'B738');
assert.equal(next.klass, 'airliner');
flightState.lifetime.abort();
});
+25 -15
View File
@@ -110,11 +110,12 @@ export class FlightRecords {
// The airframe's facts: this record's, or those kept across a reset.
const airframe = prevMeta ?? this.airframes.get(icao24);
this.airframes.delete(icao24);
// A ground vehicle or ground station (a feed's ZVEH or GRND: a model
// built standing, catalog category `other`) takes the feed's own type,
// which no airframe lookup knows; every other aircraft keeps waiting for
// its looked-up type. With no altitude at all it stands on the ground,
// where it is, instead of at the airborne default.
// The feed's own ICAO type classes the contact and picks its model from
// the first fix; a looked-up type outranks it once one has answered.
// A ground vehicle or ground station (a feed's ZVEH or GRND) is known
// from its feed type alone, which no airframe lookup knows. With no
// altitude at all, a contact drawn with a model built standing is on the
// ground, where it is, instead of at the airborne default.
const groundModel = (typeCode) =>
drawnAsGroundModel(
this.fleetModels(),
@@ -122,15 +123,16 @@ export class FlightRecords {
category,
stickyText(callsign, prevMeta?.callsign),
);
const feedType = observation.typeCode || null;
// The feed's type is kept for what it names itself, not for a surface
// category: a C1 contact whose feed names an airliner type stays a vehicle.
const feedType = cleanType(observation.typeCode);
// A surface category keeps only a feed's ground type: a C1 contact whose
// feed names an airliner type stays a vehicle.
const keepFeedType =
Boolean(feedType) &&
(groundCategory(category)
? GROUND_FEED_TYPES.has(feedType.trim().toUpperCase())
: groundModel(feedType));
const typeCode = airframe?.typeCode ?? (keepFeedType ? feedType : null);
(!groundCategory(category) || GROUND_FEED_TYPES.has(feedType));
const typeLookedUp = airframe?.typeLookedUp === true;
const typeCode = typeLookedUp
? airframe.typeCode
: ((keepFeedType ? feedType : null) ?? airframe?.typeCode ?? null);
const onGround =
on_ground === true ||
(!Number.isFinite(baro_alt) &&
@@ -331,8 +333,8 @@ export class FlightRecords {
),
courseAnchor: course.anchor,
category: cat,
// An adsbdb-enriched type code outranks the coarse OpenSky category;
// a feed's own ground type (ZVEH, GRND) classes it from the first fix.
// A type code (the feed's, or a looked-up one) outranks the coarse
// emitter category, from the first fix.
klass: classifyAircraft({ typeCode, category: cat }),
turnRateDps: prevMeta?.turnRateDps || 0,
verticalRate: stickyNumber(vertical_rate, prevMeta?.verticalRate, null),
@@ -366,8 +368,9 @@ export class FlightRecords {
null,
),
// adsbdb enrichment — written by the enrichment callbacks, carried
// across polls; a ground vehicle's or station's from the feed:
// across polls; the type is the feed's own until a lookup answers:
typeCode,
typeLookedUp,
typeName: airframe?.typeName ?? null,
registration: airframe?.registration ?? null,
airline: routeHeld ? (airframe.airline ?? null) : null,
@@ -432,6 +435,7 @@ export class FlightRecords {
for (const [id, meta] of this.data) {
this.airframes.set(id, {
typeCode: meta.typeCode,
typeLookedUp: meta.typeLookedUp,
typeName: meta.typeName,
registration: meta.registration,
airline: meta.airline,
@@ -473,6 +477,12 @@ function stickyCategory(next, prev) {
return prev ?? null;
}
/** A feed's ICAO type designator, upper case, or null. */
function cleanType(value) {
const text = typeof value === 'string' ? value.trim().toUpperCase() : '';
return text || null;
}
/** The types a feed gives airport vehicles (ZVEH) and ground stations (GRND). */
const GROUND_FEED_TYPES = new Set(['ZVEH', 'GRND']);
+54 -5
View File
@@ -298,14 +298,14 @@ test('a ground vehicle or station with no altitude stands on the ground; an airc
assert.equal(mast.onGround, true);
assert.equal(mast.typeCode, 'GRND');
// An airliner with no altitude keeps the airborne default, and its feed
// type still waits for the airframe lookup.
// type from the first fix.
const plane = store.receive(
observation({ id: 'p1', typeCode: 'A320', ...noAltitude }),
view(),
).meta;
assert.equal(plane.onGround, false);
assert.equal(plane.altitude, 10000);
assert.equal(plane.typeCode, null);
assert.equal(plane.typeCode, 'A320');
// A vehicle reporting an altitude is placed by it.
const reported = store.receive(
observation({ id: 'v2', typeCode: 'ZVEH', baroAltitudeM: 12 }),
@@ -326,7 +326,7 @@ test('a ground vehicle or station with no altitude stands on the ground; an airc
view(),
).meta;
assert.equal(earlyPlane.onGround, false);
assert.equal(earlyPlane.typeCode, null);
assert.equal(earlyPlane.typeCode, 'A320');
});
test('airport vehicles and ground stations take their class from the first fix', () => {
@@ -344,14 +344,63 @@ test('airport vehicles and ground stations take their class from the first fix',
assert.equal(klass({ id: 'v4', category: 'C2' }), 'vehicle');
assert.equal(klass({ id: 'm1', typeCode: 'GRND' }), 'station');
assert.equal(klass({ id: 'm2', category: 'C4' }), 'station');
// An aircraft's feed type still waits for the airframe lookup.
// An aircraft's feed type outranks its emitter category.
assert.equal(
klass({ id: 'p1', typeCode: 'A320', category: 'A7' }),
'helicopter',
'airliner',
);
}
});
test("an aircraft's feed type classes it from the first fix, until a lookup answers", () => {
for (const store of [records(), records(() => fleetSet)]) {
// A helicopter whose feed names its type, with an airliner-like category.
const first = store.receive(
observation({
id: 'h1',
callsign: 'NHC47',
typeCode: 'ec45',
category: 'A3',
}),
view(),
).meta;
assert.equal(first.typeCode, 'EC45');
assert.equal(first.klass, 'helicopter');
assert.equal(first.typeLookedUp, false);
// A later row without the type keeps it.
const quiet = store.receive(
observation({ id: 'h1', callsign: 'NHC47', category: 'A3' }),
view(),
).meta;
assert.equal(quiet.klass, 'helicopter');
assert.equal(quiet.typeCode, 'EC45');
// A looked-up type outranks the feed's on every later poll and reset.
quiet.typeCode = 'EC35';
quiet.typeLookedUp = true;
quiet.typeName = 'Airbus Helicopters H135';
const after = store.receive(
observation({ id: 'h1', callsign: 'NHC47', typeCode: 'B738' }),
view(),
).meta;
assert.equal(after.typeCode, 'EC35');
assert.equal(after.typeName, 'Airbus Helicopters H135');
assert.equal(after.klass, 'helicopter');
store.reset();
const again = store.receive(
observation({ id: 'h1', callsign: 'NHC47', typeCode: 'B738' }),
view(),
).meta;
assert.equal(again.typeCode, 'EC35');
// No type anywhere: the emitter category classes it.
const bare = store.receive(
observation({ id: 'h2', category: 'A7' }),
view(),
).meta;
assert.equal(bare.typeCode, null);
assert.equal(bare.klass, 'helicopter');
}
});
test('a surface emitter category stands on the ground, before and after the model set loads', () => {
const noAltitude = { baroAltitudeM: null, ellipsoidAltitudeM: null };
for (const store of [records(), records(() => fleetSet)]) {
+5
View File
@@ -109,6 +109,11 @@ export function openSkySnapshot(
const statuses = payload?.emergencyByIcao;
if (record && statuses && Object.hasOwn(statuses, record.id))
record.emergency = cleanText(statuses[record.id]).toLowerCase() || null;
// A state vector has no type field; a feed that knows the airframe's
// ICAO type designator sends it alongside, by ICAO address.
const types = payload?.typeByIcao;
if (record && types && Object.hasOwn(types, record.id))
record.typeCode = cleanText(types[record.id]).toUpperCase() || null;
return record;
},
'OpenSky',
+15
View File
@@ -614,3 +614,18 @@ test('a vessel with no name is not named by its id; a ten-digit MMSI is an MMSI'
);
assert.equal(named.name, 'EVER GIVEN');
});
test('a type sent alongside the state vectors becomes the record type code', () => {
const row = (id) => [id, 'TEST1', 'US', 1, 1, -77, 39, 1000, false, 100, 90];
const snapshot = openSkySnapshot({
time: 1,
states: [row('abc123'), row('def456')],
typeByIcao: { abc123: ' ec45 ', zzz999: 'B738' },
});
assert.equal(snapshot.records[0].typeCode, 'EC45');
assert.equal(snapshot.records[1].typeCode, null);
assert.equal(
openSkySnapshot({ states: [row('abc123')] }).records[0].typeCode,
null,
);
});