From 537a5d6e0f6277822cdcd3ed7b8825e99b37420f Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sun, 15 Nov 2026 11:11:35 -0800 Subject: [PATCH 1/3] fix(flights): an aircraft with no track or true heading faces the way it moved, not north Some feed rows carry neither a ground track nor a true heading for an aircraft on the ground. Its course then fell back to 0, and an aircraft taxiing south was drawn facing north, moving backwards or sideways. With neither reported, the course is now read from its last fix to this one when they are at least 30 m apart; nearer fixes are position noise and keep the last course. --- changelog.d/course-from-fixes.md | 3 ++ docs/CURRENT-STATE.md | 6 +++ src/layers/flights/records.js | 33 +++++++++++++++- src/layers/flights/records.test.mjs | 58 ++++++++++++++++++++++++++++- 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 changelog.d/course-from-fixes.md diff --git a/changelog.d/course-from-fixes.md b/changelog.d/course-from-fixes.md new file mode 100644 index 000000000..43898dc00 --- /dev/null +++ b/changelog.d/course-from-fixes.md @@ -0,0 +1,3 @@ +### Fixed + +- An aircraft whose feed sends neither a ground track nor a true heading now faces the way it moved since its last position, instead of north, so a taxiing aircraft no longer appears to move sideways or backwards. diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index a935ac0dd..4228e9713 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1,5 +1,11 @@ # God's Eye View Current State +An aircraft faces its reported ground track, else its true heading (readsb +`true_heading`). With neither, it faces the way it moved since its last fix +when that is at least 30 m (`courseFromFixes`, `src/layers/flights/records.js`); +nearer fixes are position noise and keep its last course, and an aircraft with +no course at all faces north. + Docker Compose mounts the checkout with the shared SELinux `:z` label so containers can read it on enforcing SELinux hosts. The separate image-owned `node_modules` volume and loopback-only port publishing remain unchanged. diff --git a/src/layers/flights/records.js b/src/layers/flights/records.js index 02c50f3d8..84394f7cf 100644 --- a/src/layers/flights/records.js +++ b/src/layers/flights/records.js @@ -20,6 +20,30 @@ import { } from './recordPolicy.js'; /** Source-independent aircraft metadata and bounded missing-poll retention. */ +/** Metres a contact must move between fixes before its course is read from them. */ +const COURSE_FROM_FIXES_MIN_M = 30; + +/** + * The course from one fix to the next, in degrees from true north, or null + * when either is missing or they are less than COURSE_FROM_FIXES_MIN_M apart + * (position noise on a parked aircraft is not a course). + */ +export function courseFromFixes(fromLat, fromLon, toLat, toLon) { + if (![fromLat, fromLon, toLat, toLon].every(Number.isFinite)) return null; + if ( + approxDistanceKm(fromLat, fromLon, toLat, toLon) * 1000 < + COURSE_FROM_FIXES_MIN_M + ) + return null; + const φ1 = (fromLat * Math.PI) / 180; + const φ2 = (toLat * Math.PI) / 180; + const Δλ = ((toLon - fromLon) * Math.PI) / 180; + const y = Math.sin(Δλ) * Math.cos(φ2); + const x = + Math.cos(φ1) * Math.sin(φ2) - Math.sin(φ1) * Math.cos(φ2) * Math.cos(Δλ); + return ((Math.atan2(y, x) * 180) / Math.PI + 360) % 360; +} + export class FlightRecords { constructor({ geoidHeight, @@ -309,7 +333,14 @@ export class FlightRecords { // applies to contacts that actually flew this session. wasAirborne: prevMeta?.wasAirborne === true || !onGround, velocity: stickyNumber(velocity, prevMeta?.velocity, 0), - true_track: stickyNumber(true_track, prevMeta?.true_track, 0), + // With no reported track or true heading, a moving contact faces the + // way it moved since its last fix; a still one keeps its last course. + true_track: stickyNumber( + true_track, + courseFromFixes(prevMeta?.rawLat, prevMeta?.rawLon, lat, lon) ?? + prevMeta?.true_track, + 0, + ), category: cat, // An adsbdb-enriched type code outranks the coarse OpenSky category. klass: classifyAircraft({ diff --git a/src/layers/flights/records.test.mjs b/src/layers/flights/records.test.mjs index cafe55cbf..fe3c789f4 100644 --- a/src/layers/flights/records.test.mjs +++ b/src/layers/flights/records.test.mjs @@ -3,7 +3,7 @@ import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; -import { FlightRecords } from './records.js'; +import { FlightRecords, courseFromFixes } from './records.js'; const FLEET = path.resolve( path.dirname(fileURLToPath(import.meta.url)), @@ -319,3 +319,59 @@ test('a ground vehicle or station with no altitude stands on the ground; an airc ).meta; assert.equal(unloaded.onGround, false); }); + +test('a contact reported with no course faces the way it moved since its last fix', () => { + const store = records(); + // Taxiing south along a runway with no track or true heading reported. + store.receive( + observation({ + latitude: 30.1908, + longitude: -97.6588, + courseDeg: null, + onGround: true, + speedMps: 8, + }), + view(), + ); + assert.equal(store.data.get('abc123').true_track, 0, 'nothing known yet'); + store.receive( + observation({ + latitude: 30.1885, + longitude: -97.6588, + courseDeg: null, + onGround: true, + speedMps: 8, + }), + view(), + ); + assert.ok(Math.abs(store.data.get('abc123').true_track - 180) < 0.1); + // Standing still (a metre of position noise): the last course is kept. + store.receive( + observation({ + latitude: 30.18849, + longitude: -97.6588, + courseDeg: null, + onGround: true, + speedMps: 0, + }), + view(), + ); + assert.ok(Math.abs(store.data.get('abc123').true_track - 180) < 0.1); + // A reported course always wins. + store.receive( + observation({ + latitude: 30.188, + longitude: -97.6588, + courseDeg: 175, + onGround: true, + }), + view(), + ); + assert.equal(store.data.get('abc123').true_track, 175); +}); + +test('course from fixes ignores position noise and reads east as 90', () => { + assert.equal(courseFromFixes(30, -97, 30.0001, -97), null, 'about 11 m'); + assert.ok(Math.abs(courseFromFixes(0, 0, 0, 0.01) - 90) < 1e-6); + assert.equal(courseFromFixes(null, 0, 0, 0.01), null); +}); From e08dcd032615347063056c5fcd4359411c94bfcd Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sun, 15 Nov 2026 11:11:42 -0800 Subject: [PATCH 2/3] Changelog fragment for #1753 --- changelog.d/{course-from-fixes.md => 1753-course-from-fixes.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelog.d/{course-from-fixes.md => 1753-course-from-fixes.md} (100%) diff --git a/changelog.d/course-from-fixes.md b/changelog.d/1753-course-from-fixes.md similarity index 100% rename from changelog.d/course-from-fixes.md rename to changelog.d/1753-course-from-fixes.md From fc4db81d0b2090318cc8c11211f789b308f76530 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sun, 15 Nov 2026 11:19:58 -0800 Subject: [PATCH 3/3] Course from fixes only moves forward in time, from an anchor fix, and not for a standing contact; military contacts too A fix that is not a second newer (a repeat, or an older position from another feed) never gives a course, so a source switch cannot turn an aircraft around. The course runs from an anchor fix that moves only when a course is read, so frequent short steps add up, and a contact reported under 2 m/s reads none. The helper moves to src/data/courseFromFixes.js and the military records use it as well. --- changelog.d/1753-course-from-fixes.md | 2 +- docs/CURRENT-STATE.md | 14 ++-- scripts/package-boundaries.json | 20 ++++-- src/data/courseFromFixes.js | 61 +++++++++++++++++ src/data/courseFromFixes.test.mjs | 42 ++++++++++++ src/layers/flights/records.js | 37 +++-------- src/layers/flights/records.test.mjs | 94 ++++++++++++--------------- src/layers/military/records.js | 16 ++++- src/layers/military/records.test.mjs | 23 +++++++ 9 files changed, 217 insertions(+), 92 deletions(-) create mode 100644 src/data/courseFromFixes.js create mode 100644 src/data/courseFromFixes.test.mjs diff --git a/changelog.d/1753-course-from-fixes.md b/changelog.d/1753-course-from-fixes.md index 43898dc00..1c42498e3 100644 --- a/changelog.d/1753-course-from-fixes.md +++ b/changelog.d/1753-course-from-fixes.md @@ -1,3 +1,3 @@ ### Fixed -- An aircraft whose feed sends neither a ground track nor a true heading now faces the way it moved since its last position, instead of north, so a taxiing aircraft no longer appears to move sideways or backwards. +- A civil or military aircraft whose feed sends neither a ground track nor a true heading now faces the way its newer positions went, instead of north, so a taxiing aircraft no longer appears to move sideways or backwards. An older position from another feed, or position noise on a parked aircraft, never turns it. diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 4228e9713..ceaa5e4e9 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1,10 +1,14 @@ # God's Eye View Current State -An aircraft faces its reported ground track, else its true heading (readsb -`true_heading`). With neither, it faces the way it moved since its last fix -when that is at least 30 m (`courseFromFixes`, `src/layers/flights/records.js`); -nearer fixes are position noise and keep its last course, and an aircraft with -no course at all faces north. +An aircraft (civil or military) faces its reported ground track, else its +true heading (readsb `true_heading`). With neither, it faces the way its own +fixes went (`courseFromFixes`, `src/data/courseFromFixes.js`): the course runs +from an anchor fix to the newest once they are 30 m apart, and the anchor then +moves on, so frequent fixes of a slow aircraft add up while position noise on +a parked one never makes a course. A fix that is not a second newer (a repeat, +or an older position from another feed) and one reported slower than 2 m/s +give no course and keep the last; an aircraft with no course at all faces +north. Docker Compose mounts the checkout with the shared SELinux `:z` label so containers can read it on enforcing SELinux hosts. The separate image-owned diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index 59d369b9b..5f3bfd12e 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -1592,7 +1592,8 @@ "src/time/worldClock.js", "src/time/julian.js", "src/data/planespottersPhoto.js", - "src/layers/flights/placed.js" + "src/layers/flights/placed.js", + "src/data/courseFromFixes.js" ], "external": ["cesium"] }, @@ -1668,7 +1669,9 @@ "src/ui/unitLabels.js", "src/time/worldClock.js", "src/time/julian.js", - "src/layers/flights/placed.js" + "src/layers/flights/placed.js", + "src/data/courseFromFixes.js", + "src/data/approxDistance.js" ], "external": ["cesium"] }, @@ -3839,7 +3842,8 @@ "src/data/openVesselPhoto.js", "src/layers/vessels/photos.js", "src/layers/flights/placed.js", - "src/data/placementProvider.js" + "src/data/placementProvider.js", + "src/data/courseFromFixes.js" ], "external": [ "hls.js", @@ -4565,7 +4569,8 @@ "src/layers/vessels/photos.js", "src/data/openVesselPhoto.js", "src/layers/flights/placed.js", - "src/data/placementProvider.js" + "src/data/placementProvider.js", + "src/data/courseFromFixes.js" ], "external": [ "hls.js", @@ -4851,7 +4856,8 @@ "src/data/aircraftEmergency.js", "src/data/fleetModels.js", "src/data/vesselTypes.js", - "src/data/fleetTrailAnchors.js" + "src/data/fleetTrailAnchors.js", + "src/data/courseFromFixes.js" ], "external": [] }, @@ -4873,7 +4879,9 @@ "src/data/aircraftMeta.js", "src/data/renderAltitude.js", "src/data/aircraftClass.js", - "src/data/aircraftEmergency.js" + "src/data/aircraftEmergency.js", + "src/data/courseFromFixes.js", + "src/data/approxDistance.js" ], "external": [] }, diff --git a/src/data/courseFromFixes.js b/src/data/courseFromFixes.js new file mode 100644 index 000000000..f82eb4d89 --- /dev/null +++ b/src/data/courseFromFixes.js @@ -0,0 +1,61 @@ +/** + * The course of a contact whose feed reports neither a ground track nor a + * true heading, read from its own fixes. + * + * The course runs from an anchor fix to the newest fix once they are at least + * COURSE_FROM_FIXES_MIN_M apart; the anchor then moves to the newest fix. + * Nearer fixes leave the anchor where it is, so frequent fixes of a slow + * aircraft still add up to a course, while position noise on a parked one + * never makes one. A fix that does not move time on by a second (a repeat, or + * an older position from another feed) never moves the anchor or gives a + * course, and neither does one reported slower than + * COURSE_FROM_FIXES_MIN_SPEED_MPS. + */ +import { approxDistanceKm } from './approxDistance.js'; + +/** Metres between fixes before a course is read from them. */ +export const COURSE_FROM_FIXES_MIN_M = 30; +/** A contact reported slower than this (m/s) is standing: no course is read. */ +export const COURSE_FROM_FIXES_MIN_SPEED_MPS = 2; + +/** + * Initial great-circle bearing from one point to another, in degrees from + * true north (0–360), or null when either is missing or they are less than + * COURSE_FROM_FIXES_MIN_M apart. + */ +export function courseBetweenFixes(fromLat, fromLon, toLat, toLon) { + if (![fromLat, fromLon, toLat, toLon].every(Number.isFinite)) return null; + if ( + approxDistanceKm(fromLat, fromLon, toLat, toLon) * 1000 < + COURSE_FROM_FIXES_MIN_M + ) + return null; + const φ1 = (fromLat * Math.PI) / 180; + const φ2 = (toLat * Math.PI) / 180; + const Δλ = ((toLon - fromLon) * Math.PI) / 180; + const y = Math.sin(Δλ) * Math.cos(φ2); + const x = + Math.cos(φ1) * Math.sin(φ2) - Math.sin(φ1) * Math.cos(φ2) * Math.cos(Δλ); + return ((Math.atan2(y, x) * 180) / Math.PI + 360) % 360; +} + +/** + * Read a course from a new fix. + * @param {{lat: number, lon: number, ms: number}|null|undefined} anchor The + * anchor fix kept from the last call (null at first). + * @param {{lat: number, lon: number, ms: number, speedMps?: number|null}} fix + * @returns {{courseDeg: number|null, anchor: {lat: number, lon: number, ms: number}|null}} + * The course, or null when none can be read, and the anchor to keep. + */ +export function courseFromFixes(anchor, { lat, lon, ms, speedMps = null }) { + const keep = anchor ?? null; + if (![lat, lon, ms].every(Number.isFinite)) + return { courseDeg: null, anchor: keep }; + if (!keep) return { courseDeg: null, anchor: { lat, lon, ms } }; + if (ms < keep.ms + 1000) return { courseDeg: null, anchor: keep }; + if (Number.isFinite(speedMps) && speedMps < COURSE_FROM_FIXES_MIN_SPEED_MPS) + return { courseDeg: null, anchor: keep }; + const courseDeg = courseBetweenFixes(keep.lat, keep.lon, lat, lon); + if (courseDeg === null) return { courseDeg: null, anchor: keep }; + return { courseDeg, anchor: { lat, lon, ms } }; +} diff --git a/src/data/courseFromFixes.test.mjs b/src/data/courseFromFixes.test.mjs new file mode 100644 index 000000000..e12b1cdd4 --- /dev/null +++ b/src/data/courseFromFixes.test.mjs @@ -0,0 +1,42 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { courseBetweenFixes, courseFromFixes } from './courseFromFixes.js'; + +test('course between fixes reads true bearings, across the antimeridian too', () => { + assert.ok(Math.abs(courseBetweenFixes(0, 0, 0, 0.01) - 90) < 1e-6); + assert.ok(Math.abs(courseBetweenFixes(0, 0, -0.01, 0) - 180) < 1e-6); + assert.ok( + Math.abs(courseBetweenFixes(0, 179.9997, 0, -179.9997) - 90) < 1e-6, + ); + assert.equal(courseBetweenFixes(30, -97, 30.0001, -97), null, 'about 11 m'); + assert.equal(courseBetweenFixes(null, 0, 0, 0.01), null); +}); + +test('the anchor moves only with a course, and only forward in time', () => { + let state = courseFromFixes(null, { lat: 0, lon: 0, ms: 0 }); + assert.equal(state.courseDeg, null); + assert.deepEqual(state.anchor, { lat: 0, lon: 0, ms: 0 }); + const first = state.anchor; + state = courseFromFixes(first, { lat: 0, lon: 0.0001, ms: 1000 }); + assert.equal(state.courseDeg, null, '11 m: no course'); + assert.equal(state.anchor, first, 'the anchor stays'); + state = courseFromFixes(first, { lat: 0, lon: 0.0005, ms: 500 }); + assert.equal(state.courseDeg, null, 'not a second newer'); + state = courseFromFixes(first, { + lat: 0, + lon: 0.0005, + ms: 2000, + speedMps: 1, + }); + assert.equal(state.courseDeg, null, 'standing'); + state = courseFromFixes(first, { + lat: 0, + lon: 0.0005, + ms: 2000, + speedMps: 8, + }); + assert.ok(Math.abs(state.courseDeg - 90) < 1e-6); + assert.deepEqual(state.anchor, { lat: 0, lon: 0.0005, ms: 2000 }); + state = courseFromFixes(first, { lat: NaN, lon: 0, ms: 3000 }); + assert.equal(state.anchor, first); +}); diff --git a/src/layers/flights/records.js b/src/layers/flights/records.js index 84394f7cf..9dbe08de6 100644 --- a/src/layers/flights/records.js +++ b/src/layers/flights/records.js @@ -1,4 +1,5 @@ import { stickyNumber, stickyText } from '../../data/aircraftMeta.js'; +import { courseFromFixes } from '../../data/courseFromFixes.js'; import { geoidSurfaceLastResortM, pickRenderAltitudeM, @@ -20,30 +21,6 @@ import { } from './recordPolicy.js'; /** Source-independent aircraft metadata and bounded missing-poll retention. */ -/** Metres a contact must move between fixes before its course is read from them. */ -const COURSE_FROM_FIXES_MIN_M = 30; - -/** - * The course from one fix to the next, in degrees from true north, or null - * when either is missing or they are less than COURSE_FROM_FIXES_MIN_M apart - * (position noise on a parked aircraft is not a course). - */ -export function courseFromFixes(fromLat, fromLon, toLat, toLon) { - if (![fromLat, fromLon, toLat, toLon].every(Number.isFinite)) return null; - if ( - approxDistanceKm(fromLat, fromLon, toLat, toLon) * 1000 < - COURSE_FROM_FIXES_MIN_M - ) - return null; - const φ1 = (fromLat * Math.PI) / 180; - const φ2 = (toLat * Math.PI) / 180; - const Δλ = ((toLon - fromLon) * Math.PI) / 180; - const y = Math.sin(Δλ) * Math.cos(φ2); - const x = - Math.cos(φ1) * Math.sin(φ2) - Math.sin(φ1) * Math.cos(φ2) * Math.cos(Δλ); - return ((Math.atan2(y, x) * 180) / Math.PI + 360) % 360; -} - export class FlightRecords { constructor({ geoidHeight, @@ -315,6 +292,12 @@ export class FlightRecords { observation.positionTimeMs > 0 ? observation.positionTimeMs : this.now(); + const course = courseFromFixes(prevMeta?.courseAnchor, { + lat, + lon, + ms: fixEpochMs, + speedMps: velocity, + }); const meta = { sourceReference: observation.reference, observedReceiptMs: this.now(), @@ -334,13 +317,13 @@ export class FlightRecords { wasAirborne: prevMeta?.wasAirborne === true || !onGround, velocity: stickyNumber(velocity, prevMeta?.velocity, 0), // With no reported track or true heading, a moving contact faces the - // way it moved since its last fix; a still one keeps its last course. + // way its fixes went (src/data/courseFromFixes.js); else the last one. true_track: stickyNumber( true_track, - courseFromFixes(prevMeta?.rawLat, prevMeta?.rawLon, lat, lon) ?? - prevMeta?.true_track, + course.courseDeg ?? prevMeta?.true_track, 0, ), + courseAnchor: course.anchor, category: cat, // An adsbdb-enriched type code outranks the coarse OpenSky category. klass: classifyAircraft({ diff --git a/src/layers/flights/records.test.mjs b/src/layers/flights/records.test.mjs index fe3c789f4..1aaddcf5b 100644 --- a/src/layers/flights/records.test.mjs +++ b/src/layers/flights/records.test.mjs @@ -3,7 +3,7 @@ import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; -import { FlightRecords, courseFromFixes } from './records.js'; +import { FlightRecords } from './records.js'; const FLEET = path.resolve( path.dirname(fileURLToPath(import.meta.url)), @@ -320,58 +320,48 @@ test('a ground vehicle or station with no altitude stands on the ground; an airc assert.equal(unloaded.onGround, false); }); -test('a contact reported with no course faces the way it moved since its last fix', () => { +test('a contact reported with no course faces the way its newer fixes went', () => { const store = records(); - // Taxiing south along a runway with no track or true heading reported. - store.receive( - observation({ - latitude: 30.1908, - longitude: -97.6588, - courseDeg: null, - onGround: true, - speedMps: 8, - }), - view(), + const T = 1700000000000; + const taxi = (latitude, seconds, fields = {}) => + store.receive( + observation({ + latitude, + longitude: -97.6588, + courseDeg: null, + onGround: true, + speedMps: 8, + positionTimeMs: T + seconds * 1000, + ...fields, + }), + view(), + ); + const course = () => store.data.get('abc123').true_track; + taxi(30.1908, 0); + assert.equal(course(), 0, 'nothing known yet'); + // Fixes a second apart, 8 m each: they add up until 30 m are covered. + taxi(30.19073, 1); + taxi(30.19066, 2); + assert.equal(course(), 0, 'under 30 m: still nothing'); + taxi(30.19059, 3); + taxi(30.19052, 4); + assert.ok(Math.abs(course() - 180) < 0.1, 'southbound'); + // An older fix from another feed, behind it: never turns it around. + taxi(30.1912, 2); + assert.ok(Math.abs(course() - 180) < 0.1, 'an older fix gives no course'); + taxi(30.1901, 8); + assert.ok(Math.abs(course() - 180) < 0.1); + // Standing (reported under 2 m/s) with 40 m of position noise: kept. + taxi(30.18974, 12, { speedMps: 0.5, longitude: -97.6584 }); + assert.ok( + Math.abs(course() - 180) < 0.1, + 'a standing contact keeps its course', ); - assert.equal(store.data.get('abc123').true_track, 0, 'nothing known yet'); - store.receive( - observation({ - latitude: 30.1885, - longitude: -97.6588, - courseDeg: null, - onGround: true, - speedMps: 8, - }), - view(), - ); - assert.ok(Math.abs(store.data.get('abc123').true_track - 180) < 0.1); - // Standing still (a metre of position noise): the last course is kept. - store.receive( - observation({ - latitude: 30.18849, - longitude: -97.6588, - courseDeg: null, - onGround: true, - speedMps: 0, - }), - view(), - ); - assert.ok(Math.abs(store.data.get('abc123').true_track - 180) < 0.1); // A reported course always wins. - store.receive( - observation({ - latitude: 30.188, - longitude: -97.6588, - courseDeg: 175, - onGround: true, - }), - view(), - ); - assert.equal(store.data.get('abc123').true_track, 175); -}); - -test('course from fixes ignores position noise and reads east as 90', () => { - assert.equal(courseFromFixes(30, -97, 30.0001, -97), null, 'about 11 m'); - assert.ok(Math.abs(courseFromFixes(0, 0, 0, 0.01) - 90) < 1e-6); - assert.equal(courseFromFixes(null, 0, 0, 0.01), null); + taxi(30.189, 16, { courseDeg: 175 }); + assert.equal(course(), 175); + // A reset forgets where it was: it starts again from north. + store.reset(); + taxi(30.188, 20); + assert.equal(course(), 0); }); diff --git a/src/layers/military/records.js b/src/layers/military/records.js index 72ffd2677..8a040b97e 100644 --- a/src/layers/military/records.js +++ b/src/layers/military/records.js @@ -1,5 +1,6 @@ import { pickRenderAltitudeM } from '../../data/renderAltitude.js'; import { stickyText, stickyNumber } from '../../data/aircraftMeta.js'; +import { courseFromFixes } from '../../data/courseFromFixes.js'; import { classifyAircraft } from '../../data/aircraftClass.js'; import { aircraftEmergency } from '../../data/aircraftEmergency.js'; import { @@ -175,6 +176,12 @@ export class MilitaryFlightRecords { // last-known-good (bounded by the layer's eviction, which deletes the entry). const stickyType = stickyText(type, prevMeta?.type); const fixEpochMs = aircraft.positionTimeMs ?? observedAtMs; + const course = courseFromFixes(prevMeta?.courseAnchor, { + lat, + lon, + ms: fixEpochMs, + speedMps: aircraft.speedMps, + }); const meta = { sourceReference: aircraft.reference, observedReceiptMs: this.now(), @@ -206,7 +213,14 @@ export class MilitaryFlightRecords { onGround ? 0 : prevMeta?.speedMps, 0, ), - track: stickyNumber(aircraft.courseDeg, prevMeta?.track, 0), + // With no reported track or true heading, a moving contact faces the + // way its fixes went (src/data/courseFromFixes.js); else the last one. + track: stickyNumber( + aircraft.courseDeg, + course.courseDeg ?? prevMeta?.track, + 0, + ), + courseAnchor: course.anchor, // Analyst seam (additive): sticky like the other kinematics. verticalRateMps: stickyNumber( verticalRateMps, diff --git a/src/layers/military/records.test.mjs b/src/layers/military/records.test.mjs index 3d72aed21..bbea594d8 100644 --- a/src/layers/military/records.test.mjs +++ b/src/layers/military/records.test.mjs @@ -269,3 +269,26 @@ test('a repeated military fix time marks the contact as not updated; removal is records.forget('aaa001'); assert.equal(records.fixRepeated.has('aaa001'), false); }); + +test('a military contact reported with no course faces the way its newer fixes went', () => { + const records = store(); + const T = 1700000000000; + const taxi = (latitude, seconds) => + records.receive( + observation({ + latitude, + onGround: true, + baroAltitudeM: null, + courseDeg: null, + speedMps: 8, + positionTimeMs: T + seconds * 1000, + }), + context({ observedAtMs: T + seconds * 1000 + 500 }), + ); + assert.equal(taxi(39, 0).meta.track, 0); + assert.ok(Math.abs(taxi(38.9995, 5).meta.track - 180) < 0.1); + assert.ok( + Math.abs(taxi(39.002, 3).meta.track - 180) < 0.1, + 'an older fix gives no course', + ); +});