An existing product called PG Orbit (a mobile PostgreSQL client) creates a naming conflict. pg_orrery — a database orrery built from Keplerian parameters and SQL instead of brass gears. Build system: control file, Makefile, Dockerfile, docker init script. C source: GUC prefix, PG_FUNCTION_INFO_V1 symbol, header guards, ereport prefixes, comments across ~30 files including vendored SGP4. SQL: all 5 install/migration scripts, function name pg_orrery_ephemeris_info. Tests: 9 SQL suites, 8 expected outputs, standalone DE reader test. Documentation: CLAUDE.md, README.md, DESIGN.md, Starlight site infra, 36 MDX pages, OG renderer, logo SVG, docker-compose, agent threads. All 13 regression suites pass. Docs site builds (37 pages).
93 lines
3.5 KiB
Plaintext
93 lines
3.5 KiB
Plaintext
-- Test SGP4/SDP4 propagation functions
|
|
CREATE EXTENSION IF NOT EXISTS pg_orrery;
|
|
NOTICE: extension "pg_orrery" already exists, skipping
|
|
-- ISS TLE (LEO, near-earth -> SGP4)
|
|
WITH iss AS (
|
|
SELECT '1 25544U 98067A 24001.50000000 .00016717 00000-0 10270-3 0 9025
|
|
2 25544 51.6400 208.9163 0006703 30.1694 61.7520 15.50100486 00001'::tle AS t
|
|
)
|
|
SELECT
|
|
round(eci_x(sgp4_propagate(t, '2024-01-01 12:00:00+00'))::numeric, 1) AS x_km,
|
|
round(eci_y(sgp4_propagate(t, '2024-01-01 12:00:00+00'))::numeric, 1) AS y_km,
|
|
round(eci_z(sgp4_propagate(t, '2024-01-01 12:00:00+00'))::numeric, 1) AS z_km,
|
|
round(eci_speed(sgp4_propagate(t, '2024-01-01 12:00:00+00'))::numeric, 3) AS speed_kms,
|
|
round(eci_altitude(sgp4_propagate(t, '2024-01-01 12:00:00+00'))::numeric, 0) AS alt_km
|
|
FROM iss;
|
|
x_km | y_km | z_km | speed_kms | alt_km
|
|
--------+---------+--------+-----------+--------
|
|
2242.3 | -3571.3 | 5315.9 | 7.667 | 407
|
|
(1 row)
|
|
|
|
-- Propagation 1 hour after epoch
|
|
WITH iss AS (
|
|
SELECT '1 25544U 98067A 24001.50000000 .00016717 00000-0 10270-3 0 9025
|
|
2 25544 51.6400 208.9163 0006703 30.1694 61.7520 15.50100486 00001'::tle AS t
|
|
)
|
|
SELECT
|
|
round(eci_speed(sgp4_propagate(t, '2024-01-01 13:00:00+00'))::numeric, 3) AS speed_1h,
|
|
round(eci_altitude(sgp4_propagate(t, '2024-01-01 13:00:00+00'))::numeric, 0) AS alt_1h
|
|
FROM iss;
|
|
speed_1h | alt_1h
|
|
----------+--------
|
|
7.659 | 418
|
|
(1 row)
|
|
|
|
-- GPS satellite (MEO, deep-space -> SDP4)
|
|
WITH gps AS (
|
|
SELECT '1 28874U 05038A 24001.50000000 .00000012 00000+0 00000+0 0 9993
|
|
2 28874 55.4408 300.3467 0117034 51.6543 309.5420 2.00557079 00006'::tle AS t
|
|
)
|
|
SELECT
|
|
round(eci_speed(sgp4_propagate(t, '2024-01-01 12:00:00+00'))::numeric, 3) AS gps_speed,
|
|
round(eci_altitude(sgp4_propagate(t, '2024-01-01 12:00:00+00'))::numeric, 0) AS gps_alt
|
|
FROM gps;
|
|
gps_speed | gps_alt
|
|
-----------+---------
|
|
3.903 | 19988
|
|
(1 row)
|
|
|
|
-- Propagation series: ISS, 10 minute steps over 1 orbit (~93 min)
|
|
WITH iss AS (
|
|
SELECT '1 25544U 98067A 24001.50000000 .00016717 00000-0 10270-3 0 9025
|
|
2 25544 51.6400 208.9163 0006703 30.1694 61.7520 15.50100486 00001'::tle AS t
|
|
)
|
|
SELECT
|
|
count(*) AS num_points,
|
|
round(min(sqrt(x*x + y*y + z*z) - 6378.135)::numeric, 0) AS min_alt,
|
|
round(max(sqrt(x*x + y*y + z*z) - 6378.135)::numeric, 0) AS max_alt
|
|
FROM iss, sgp4_propagate_series(t, '2024-01-01 12:00:00+00', '2024-01-01 13:33:00+00', '10 minutes');
|
|
num_points | min_alt | max_alt
|
|
------------+---------+---------
|
|
10 | 407 | 425
|
|
(1 row)
|
|
|
|
-- Distance between ISS and GPS at epoch
|
|
WITH sats AS (
|
|
SELECT '1 25544U 98067A 24001.50000000 .00016717 00000-0 10270-3 0 9025
|
|
2 25544 51.6400 208.9163 0006703 30.1694 61.7520 15.50100486 00001'::tle AS iss,
|
|
'1 28874U 05038A 24001.50000000 .00000012 00000+0 00000+0 0 9993
|
|
2 28874 55.4408 300.3467 0117034 51.6543 309.5420 2.00557079 00006'::tle AS gps
|
|
)
|
|
SELECT
|
|
round(tle_distance(iss, gps, '2024-01-01 12:00:00+00')::numeric, 0) AS dist_km,
|
|
round(tle_distance(iss, iss, '2024-01-01 12:00:00+00')::numeric, 6) AS self_dist
|
|
FROM sats;
|
|
dist_km | self_dist
|
|
---------+-----------
|
|
22768 | 0.000000
|
|
(1 row)
|
|
|
|
-- Distance to self should be zero
|
|
WITH iss AS (
|
|
SELECT '1 25544U 98067A 24001.50000000 .00016717 00000-0 10270-3 0 9025
|
|
2 25544 51.6400 208.9163 0006703 30.1694 61.7520 15.50100486 00001'::tle AS t
|
|
)
|
|
SELECT
|
|
tle_distance(t, t, '2024-01-01 12:00:00+00') = 0.0 AS self_is_zero
|
|
FROM iss;
|
|
self_is_zero
|
|
--------------
|
|
t
|
|
(1 row)
|
|
|