mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 09:12:18 +00:00
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`.
This commit is contained in:
1 parent
2f0c01eaa7
commit
f2537743ab
9 files changed
+205
-24
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
@@ -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']);
|
||||
|
||||
|
||||
@@ -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)]) {
|
||||
|
||||
Reference in new issue
Block a user