cosmo/backend/scripts/optimize_vesta_orbit.py

57 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""
Optimize orbit data by downsampling excessively detailed orbits
灶神星(Vesta)的轨道数据被过度采样了31,825个点降采样到合理的数量
"""
import asyncio
from sqlalchemy import text
from app.database import engine
async def optimize_vesta_orbit():
"""Downsample Vesta orbit from 31,825 points to ~1,326 points (every 24th point)"""
async with engine.begin() as conn:
# Get current Vesta orbit data
result = await conn.execute(text("""
SELECT points, num_points
FROM orbits
WHERE body_id = '2000004'
"""))
row = result.fetchone()
if not row:
print("❌ Vesta orbit not found")
return
points = row[0] # JSONB array
current_count = row[1]
print(f"当前Vesta轨道点数: {current_count}")
print(f"实际数组长度: {len(points)}")
# Downsample: take every 24th point (0.04 days * 24 ≈ 1 day per point)
downsampled = points[::24]
new_count = len(downsampled)
print(f"降采样后点数: {new_count}")
print(f"数据大小减少: {current_count - new_count}")
print(f"降采样比例: {current_count / new_count:.1f}x")
# Calculate size reduction
import json
old_size = len(json.dumps(points))
new_size = len(json.dumps(downsampled))
print(f"JSON大小: {old_size:,} -> {new_size:,} bytes ({old_size/new_size:.1f}x)")
# Update database
await conn.execute(text("""
UPDATE orbits
SET points = :points, num_points = :num_points
WHERE body_id = '2000004'
"""), {"points": json.dumps(downsampled), "num_points": new_count})
print("✅ Vesta轨道数据已优化")
if __name__ == "__main__":
asyncio.run(optimize_vesta_orbit())