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
@@ -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 } : {}),
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
Reference in new issue
Block a user