mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32:19 +00:00
An estimated aircraft position stands in on the trail only until the next received one (#1817)
* An estimated aircraft position stands in on the trail only until the next received one * Changelog fragment for #1817
This commit is contained in:
1 parent
522f5b415d
commit
d6972f8b78
8 files changed
+126
-8
No files matched your search
@@ -11,6 +11,20 @@ import { readAdsbVerticalRateFpm } from '../adsbFields.js';
|
||||
const openSkyId = (row) =>
|
||||
Array.isArray(row) ? cleanText(row[0]).toLowerCase() : '';
|
||||
|
||||
/** The aircraft (lowercase ICAO) a state-vector snapshot's `estimatedByIcao` names. */
|
||||
const estimatedCache = new WeakMap();
|
||||
function estimatedIds(payload) {
|
||||
const list = payload?.estimatedByIcao;
|
||||
if (!Array.isArray(list)) return EMPTY_IDS;
|
||||
let ids = estimatedCache.get(list);
|
||||
if (!ids) {
|
||||
ids = new Set(list.map((id) => cleanText(id).toLowerCase()));
|
||||
estimatedCache.set(list, ids);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
const EMPTY_IDS = new Set();
|
||||
|
||||
/** Normalize the OpenSky state-vector route, including its regional fallback. */
|
||||
export function normalizeOpenSkyAircraft(row) {
|
||||
const id = openSkyId(row);
|
||||
@@ -114,6 +128,10 @@ export function openSkySnapshot(
|
||||
const types = payload?.typeByIcao;
|
||||
if (record && types && Object.hasOwn(types, record.id))
|
||||
record.typeCode = cleanText(types[record.id]).toUpperCase() || null;
|
||||
// Nor a position source; a feed that estimates some positions (carried
|
||||
// on the last course out of receiver range) names those aircraft.
|
||||
if (record && estimatedIds(payload).has(record.id))
|
||||
record.estimated = true;
|
||||
return record;
|
||||
},
|
||||
'OpenSky',
|
||||
@@ -157,7 +175,12 @@ export function readsbSnapshot(
|
||||
) {
|
||||
const admitted = admitRecords(
|
||||
payload?.ac,
|
||||
(row) => normalizeReadsbAircraft(row, observedAtMs),
|
||||
(row) => {
|
||||
const record = normalizeReadsbAircraft(row, observedAtMs);
|
||||
// A row whose position the feed estimated rather than received.
|
||||
if (record && row.estimated === true) record.estimated = true;
|
||||
return record;
|
||||
},
|
||||
'adsb.lol',
|
||||
readsbUnpositionedId,
|
||||
);
|
||||
|
||||
@@ -615,6 +615,32 @@ 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('aircraft a feed names as estimated are marked estimated, and only those', () => {
|
||||
const row = (id) => [id, 'TEST1', 'US', 1, 1, -77, 39, 1000, false, 100, 90];
|
||||
const vectors = openSkySnapshot({
|
||||
time: 1,
|
||||
states: [row('abc123'), row('def456')],
|
||||
estimatedByIcao: ['ABC123', 'zzz999'],
|
||||
}).records;
|
||||
assert.equal(vectors[0].estimated, true);
|
||||
assert.equal('estimated' in vectors[1], false);
|
||||
assert.equal(
|
||||
'estimated' in openSkySnapshot({ states: [row('abc123')] }).records[0],
|
||||
false,
|
||||
);
|
||||
const rows = readsbSnapshot(
|
||||
{
|
||||
ac: [
|
||||
{ hex: 'abc123', lat: 39, lon: -77, estimated: true },
|
||||
{ hex: 'def456', lat: 39, lon: -77 },
|
||||
],
|
||||
},
|
||||
{ observedAtMs: null },
|
||||
).records;
|
||||
assert.equal(rows[0].estimated, true);
|
||||
assert.equal('estimated' in rows[1], false);
|
||||
});
|
||||
|
||||
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({
|
||||
|
||||
Reference in new issue
Block a user