57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
"""
|
||
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())
|