Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions service/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ Airframes coverage aggregation service. Subscribes to NATS processed messages ac
- A station whose location nobody entered only has a GeoIP guess (the provider's
city, often hundreds of km off). Such a station is placed at the centre of the
positions it hears (median of the last 200) once those form one group no wider
than the radio's range and the centre is further from the registered spot than
the group is wide (at least 100 km): src/compute/heard-location.ts and
than the radio's range and the centre is at least twice as far from the
registered spot as the group is wide (at least 100 km; a placed station stays
placed until the centre is back within one width): src/compute/heard-location.ts and
`placeByHeard` in the store. Owner-entered locations (`userLatitude` in the main
API) are never moved. Station responses carry `locationSource` (`registered` or
`heard`), health reports `stationsPlacedByHeard`, and the estimates are saved
Expand Down
21 changes: 15 additions & 6 deletions service/src/aggregation/coverage-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ export class CoverageStore {
* the internet provider's city), that hear their targets directly, and that
* are not area feeds. The station moves to the centre of what it hears when
* the heard positions form one group no wider than the radio's range and that
* centre is further from the registered spot than the group is wide (and at
* least 100 km): a real antenna in the right place sits inside its own group.
* centre is at least twice as far from the registered spot as the group is
* wide (and at least 100 km): a real antenna in the right place sits inside
* its own group.
*/
private placeByHeard(event: CoverageEvent): void {
const meta = this.stationMap.get(event.stationId);
Expand Down Expand Up @@ -292,12 +293,20 @@ export class CoverageStore {
const offsetKm = registered
? haversineDistance(regLat, regLon, estimate.latitude, estimate.longitude)
: Infinity;
const useHeard = oneAntenna && offsetKm > Math.max(HEARD_MIN_OFFSET_KM, estimate.spreadKm);
// Moving a station takes a clear case: the centre must be twice as far from
// the registered spot as the group is wide. That leaves alone a station that
// hears a long stretch of coast or a wide patch of sky, where the centre is
// open water or the middle of the traffic, not the antenna. A station already
// moved stays moved until the centre is back within the group's own width,
// so one near the threshold does not flip back and forth.
const placed = meta.locationSource === 'heard';
const needed = Math.max(HEARD_MIN_OFFSET_KM, estimate.spreadKm * (placed ? 1 : 2));
const useHeard = oneAntenna && offsetKm > needed;

if (useHeard) {
// Small drifts of the centre are not worth throwing the sectors away for
if (meta.locationSource === 'heard'
&& haversineDistance(meta.latitude, meta.longitude, estimate.latitude, estimate.longitude) < HEARD_MOVE_KM) return;
// Drifts of the centre within the group are not worth throwing the sectors away for
if (placed && haversineDistance(meta.latitude, meta.longitude, estimate.latitude, estimate.longitude)
< Math.max(HEARD_MOVE_KM, estimate.spreadKm / 2)) return;
meta.latitude = estimate.latitude;
meta.longitude = estimate.longitude;
meta.locationSource = 'heard';
Expand Down
10 changes: 10 additions & 0 deletions service/test/ingest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,14 @@ describe('stations without an owner-entered location', () => {
expect(store.stationMap.get(44)!.locationSource).toBe('heard');
expect(store.eventsWithPosition).toBe(1);
});
it('leaves a station alone when the centre is not clearly away from the registered spot', () => {
store = new CoverageStore();
// Registered about 270 km from the centre of vessels spread over about 150 km
store.stationMap.set(45, { ...milan(45, false), latitude: 54.0, longitude: -6.4,
registeredLatitude: 54.0, registeredLongitude: -6.4 });

hear(45, 60, 51.6, -7.0, 1.8);

expect(store.stationMap.get(45)!.locationSource).toBe('registered');
});
});