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
@@ -410,6 +410,25 @@ function keepTrailLimit(fixes, maxPoints) {
|
||||
return fixes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the estimated reports out of the trail, judging again the break before
|
||||
* each report that followed one.
|
||||
*/
|
||||
function dropEstimatedFixes(fixes) {
|
||||
let dropped = false;
|
||||
let kept = 0;
|
||||
for (const fix of fixes) {
|
||||
if (fix.estimated) {
|
||||
dropped = true;
|
||||
continue;
|
||||
}
|
||||
if (dropped) fix.breakBefore = trailFixBreaks(fixes[kept - 1], fix);
|
||||
dropped = false;
|
||||
fixes[kept++] = fix;
|
||||
}
|
||||
fixes.length = kept;
|
||||
}
|
||||
|
||||
/** Index a fix at `timeMs` goes in at: after every entry at or before it. */
|
||||
function insertionIndex(fixes, timeMs) {
|
||||
let i = fixes.length;
|
||||
@@ -425,9 +444,13 @@ function insertionIndex(fixes, timeMs) {
|
||||
* @param {{x: number, y: number, z: number}} position - Owned position.
|
||||
* @param {number} timeMs - The report's epoch ms.
|
||||
* @param {number} maxPoints - Point limit across all segments.
|
||||
* @param {{nullAltitude?: boolean, onGround?: boolean, track?: number}} [options]
|
||||
* @param {{nullAltitude?: boolean, onGround?: boolean, track?: number, estimated?: boolean}} [options]
|
||||
* `onGround`: whether the report was on the ground, when known;
|
||||
* `track`: its reported track, which the curve leaves it along.
|
||||
* `track`: its reported track, which the curve leaves it along;
|
||||
* `estimated`: the feed estimated the position rather than received it. An
|
||||
* estimated report stands in only until the next received one, which takes
|
||||
* every estimated report out of the trail: the line runs between received
|
||||
* positions, never through a feed's guesses and the jump back.
|
||||
* @returns {object[]} `fixes`.
|
||||
*/
|
||||
export function insertTrailFix(
|
||||
@@ -435,14 +458,21 @@ export function insertTrailFix(
|
||||
position,
|
||||
timeMs,
|
||||
maxPoints,
|
||||
{ nullAltitude = false, onGround = undefined, track = undefined } = {},
|
||||
{
|
||||
nullAltitude = false,
|
||||
onGround = undefined,
|
||||
track = undefined,
|
||||
estimated = false,
|
||||
} = {},
|
||||
) {
|
||||
if (!estimated) dropEstimatedFixes(fixes);
|
||||
const entry = {
|
||||
position: nullAltitude ? null : position,
|
||||
timeMs,
|
||||
nullAltitude,
|
||||
breakBefore: false,
|
||||
};
|
||||
if (estimated) entry.estimated = true;
|
||||
if (Number.isFinite(track)) entry.track = track;
|
||||
// Whether the report was on the ground, when known: a history backfill
|
||||
// joins it only across a landing or take-off it saw.
|
||||
|
||||
@@ -109,6 +109,35 @@ test('a report with no altitude keeps no position and breaks the line', () => {
|
||||
assert.equal(trailBodySegments(fixes, fixes.length).length, 2);
|
||||
});
|
||||
|
||||
test('an estimated report stands in only until the next received one', () => {
|
||||
// Out of receiver range a feed carries the aircraft on its last course; the
|
||||
// next received report is 900 m off that line. The guesses go, so the line
|
||||
// runs received report to received report.
|
||||
const fixes = [];
|
||||
insertTrailFix(fixes, at(0, 0), 0, LIMIT);
|
||||
insertTrailFix(fixes, at(1_500, 0), 15 * SEC, LIMIT, { estimated: true });
|
||||
insertTrailFix(fixes, at(3_000, 0), 30 * SEC, LIMIT, { estimated: true });
|
||||
assert.equal(fixes.length, 3);
|
||||
assert.equal(fixes[2].estimated, true);
|
||||
insertTrailFix(fixes, at(4_500, -900), 45 * SEC, LIMIT);
|
||||
assert.deepEqual(
|
||||
fixes.map((fix) => [fix.timeMs, fix.estimated === true]),
|
||||
[
|
||||
[0, false],
|
||||
[45 * SEC, false],
|
||||
],
|
||||
);
|
||||
// 45 s and 4.6 km apart: still one path, joined.
|
||||
assert.equal(fixes[1].breakBefore, false);
|
||||
// A received report a sweep late, older than the guesses, takes them out too.
|
||||
insertTrailFix(fixes, at(6_000, -900), 60 * SEC, LIMIT, { estimated: true });
|
||||
insertTrailFix(fixes, at(5_000, -900), 50 * SEC, LIMIT);
|
||||
assert.deepEqual(
|
||||
fixes.map((fix) => fix.timeMs),
|
||||
[0, 45 * SEC, 50 * SEC],
|
||||
);
|
||||
});
|
||||
|
||||
test('a report arriving late goes in time order and the curve stays smooth', () => {
|
||||
const fixes = [];
|
||||
for (const t of [0, 30, 15, 45])
|
||||
|
||||
@@ -336,6 +336,9 @@ export class FlightRecords {
|
||||
geoAltitudeM,
|
||||
renderAltitudeM,
|
||||
renderAltitudeInvented,
|
||||
// The feed estimated this position: it places the aircraft, and stands
|
||||
// in on the tracked trail only until the next received report.
|
||||
estimated: observation.estimated === true,
|
||||
groundM: Number.isFinite(groundM) ? groundM : null,
|
||||
onGround,
|
||||
// Round 7: sticky airborne history — the landed fast-cull only
|
||||
|
||||
@@ -217,6 +217,7 @@ export function createFlightSnapshotRenderer({
|
||||
{
|
||||
nullAltitude: meta.renderAltitudeInvented === true,
|
||||
track: meta.true_track,
|
||||
estimated: meta.estimated === true,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -336,15 +336,17 @@ export function createTracking({
|
||||
* @param {{x: number, y: number, z: number}} position - The report's ECEF position.
|
||||
* @param {number} [epochMs] - The report's time; defaults to the tracked
|
||||
* aircraft's newest position-history fix, which every caller has just pushed.
|
||||
* @param {{nullAltitude?: boolean, track?: number}} [options] - `nullAltitude`:
|
||||
* @param {{nullAltitude?: boolean, track?: number, estimated?: boolean}} [options] - `nullAltitude`:
|
||||
* the report had no altitude, so its position is not kept and the line
|
||||
* breaks there; `track`: its reported track, which the line leaves it along.
|
||||
* breaks there; `track`: its reported track, which the line leaves it along;
|
||||
* `estimated`: the feed estimated it, so it stands in only until the next
|
||||
* received report.
|
||||
*/
|
||||
|
||||
function _appendTrailFix(
|
||||
position,
|
||||
epochMs,
|
||||
{ nullAltitude = false, track = undefined } = {},
|
||||
{ nullAltitude = false, track = undefined, estimated = false } = {},
|
||||
) {
|
||||
const history = flightState._positionHistory.get(flightState._trackedIcao);
|
||||
const timeMs = Number.isFinite(epochMs)
|
||||
@@ -355,7 +357,7 @@ export function createTracking({
|
||||
position,
|
||||
timeMs,
|
||||
TRAIL_MAX_POINTS,
|
||||
{ nullAltitude, track },
|
||||
{ nullAltitude, track, estimated },
|
||||
);
|
||||
_refreshTrailDisplay();
|
||||
}
|
||||
|
||||
@@ -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