mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32:19 +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 } : {}),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user