mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 19:04:02 +00:00
fix(satellites): decode Alpha-5 catalog numbers in the shared TLE module
Catalog numbers above 99999 arrive in a TLE as Alpha-5: a letter A-Z, skipping I and O, stands for 10-33 in the ten-thousands place, so 100000 is A0000. satellite.js keeps the field as the string satrec.satnum, and the three catalog builders converted it with Number(), which gives NaN; the Set and Map used to deduplicate and store treat NaN as equal to NaN, so the first such satellite was stored under NaN and every later one was dropped as a duplicate (#751). The satellite tools read the same field with parseInt and reported no number, so such a satellite could not be found by it. The decoder lives in src/sources/tle.js, beside parseTleText, which the layer and the tools both import already: noradIdFromSatnum() for the three builders, and tleCatalogNumber() decodes through the same function. Every other field reads as it did before: Number() in the layer, parseInt or null in the tools.
This commit is contained in:
1 parent
79b9de07d8
commit
ac62542641
5 files changed
+100
-6
No files matched your search
@@ -1,7 +1,12 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { twoline2satrec } from 'satellite.js';
|
||||
import { composeCatalog, coreTools } from '../index.js';
|
||||
import { parseTleText, tleCatalogNumber } from '../../sources/tle.js';
|
||||
import {
|
||||
noradIdFromSatnum,
|
||||
parseTleText,
|
||||
tleCatalogNumber,
|
||||
} from '../../sources/tle.js';
|
||||
|
||||
// Element sets published for 1 January 2024.
|
||||
const TLE = `ISS (ZARYA)
|
||||
@@ -51,6 +56,51 @@ for (const missingLine of [1, 2]) {
|
||||
});
|
||||
}
|
||||
|
||||
test('Alpha-5 catalog numbers decode, skipping I and O', () => {
|
||||
for (const [field, id] of [
|
||||
['A0000', 100000],
|
||||
['A0404', 100404],
|
||||
['H9999', 179999],
|
||||
['J0000', 180000],
|
||||
['N9999', 229999],
|
||||
['P0000', 230000],
|
||||
['T0449', 270449],
|
||||
['Z9999', 339999],
|
||||
]) {
|
||||
assert.equal(noradIdFromSatnum(field), id, field);
|
||||
assert.equal(tleCatalogNumber(`1 ${field}U`), id, field);
|
||||
}
|
||||
});
|
||||
|
||||
test('every other catalog field reads as it did before', () => {
|
||||
assert.equal(noradIdFromSatnum('25544'), 25544);
|
||||
assert.equal(noradIdFromSatnum('00404'), 404);
|
||||
assert.equal(noradIdFromSatnum(''), 0); // as Number('') did
|
||||
for (const field of ['I0000', 'O0000', 'a0404', 'A00']) {
|
||||
assert.ok(Number.isNaN(noradIdFromSatnum(field)), field);
|
||||
assert.equal(tleCatalogNumber(`1 ${field}U`), null, field);
|
||||
}
|
||||
});
|
||||
|
||||
test('a satellite numbered above 99999 keeps its number and is found by it', async () => {
|
||||
// The ISS set with its catalog field in Alpha-5: A0000 is 100000.
|
||||
const text = TLE.replaceAll('25544', 'A0000');
|
||||
const [iss] = parseTleText(text);
|
||||
const { satnum } = twoline2satrec(iss.line1, iss.line2);
|
||||
assert.ok(Number.isNaN(Number(satnum))); // what the catalog builders used
|
||||
assert.equal(noradIdFromSatnum(satnum), 100000);
|
||||
const catalog = composeCatalog({
|
||||
tools: coreTools,
|
||||
services: { satellites: satellites(text), clock: CLOCK },
|
||||
});
|
||||
const result = await catalog.call('next_satellite_pass', {
|
||||
location: { lat: 40.7, lon: -74 },
|
||||
satellite: '100000',
|
||||
});
|
||||
assert.equal(result.data.satellite, 'ISS (ZARYA)');
|
||||
assert.equal(result.data.norad, 100000);
|
||||
});
|
||||
|
||||
test('the next pass defaults to the ISS and reports times, peak and direction', async () => {
|
||||
const catalog = composeCatalog({
|
||||
tools: coreTools,
|
||||
|
||||
Reference in new issue
Block a user