cosmo/backend/scripts/fix_sun_data.py

59 lines
1.6 KiB
Python

"""
Fix missing Sun position
"""
import asyncio
import os
import sys
from datetime import datetime
# Add backend directory to path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from app.database import get_db
from app.models.db import Position
async def fix_sun_position():
"""Insert missing position for Sun at 2025-12-04 00:00:00"""
async for session in get_db():
try:
target_time = datetime(2025, 12, 4, 0, 0, 0)
print(f"Fixing Sun position for {target_time}...")
# Check if it exists first (double check)
from sqlalchemy import select, func
stmt = select(func.count(Position.id)).where(
Position.body_id == '10',
Position.time == target_time
)
result = await session.execute(stmt)
count = result.scalar()
if count > 0:
print("✅ Position already exists!")
return
# Insert
new_pos = Position(
body_id='10',
time=target_time,
x=0.0,
y=0.0,
z=0.0,
vx=0.0,
vy=0.0,
vz=0.0,
source='calculated'
)
session.add(new_pos)
await session.commit()
print("✅ Successfully inserted Sun position!")
except Exception as e:
print(f"❌ Error: {e}")
await session.rollback()
finally:
break
if __name__ == "__main__":
asyncio.run(fix_sun_position())