67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Direct API test - simulate the exact API call"""
|
|
import asyncio
|
|
import sys
|
|
import os
|
|
from datetime import datetime
|
|
|
|
sys.path.append(os.path.join(os.getcwd(), "backend"))
|
|
|
|
from app.database import AsyncSessionLocal
|
|
from app.services.db_service import celestial_body_service, position_service
|
|
|
|
async def simulate_api_call():
|
|
"""Simulate /celestial/positions endpoint"""
|
|
async with AsyncSessionLocal() as db:
|
|
# Get all bodies from database
|
|
all_bodies = await celestial_body_service.get_all_bodies(db)
|
|
|
|
# Filter to only Solar System bodies
|
|
all_bodies = [b for b in all_bodies if b.system_id == 1]
|
|
|
|
# Filter to Earth only
|
|
all_bodies = [b for b in all_bodies if b.id == "399"]
|
|
|
|
bodies_data = []
|
|
now = datetime.utcnow()
|
|
|
|
for body in all_bodies:
|
|
# Get most recent position
|
|
recent_positions = await position_service.get_positions(
|
|
body_id=body.id,
|
|
start_time=now,
|
|
end_time=now,
|
|
session=db
|
|
)
|
|
|
|
if recent_positions and len(recent_positions) > 0:
|
|
latest_pos = recent_positions[-1]
|
|
body_dict = {
|
|
"id": body.id,
|
|
"name": body.name,
|
|
"name_zh": body.name_zh,
|
|
"type": body.type,
|
|
"description": body.description,
|
|
"is_active": body.is_active,
|
|
"extra_data": body.extra_data, # THIS IS THE KEY LINE
|
|
"positions": [{
|
|
"time": latest_pos.time.isoformat(),
|
|
"x": latest_pos.x,
|
|
"y": latest_pos.y,
|
|
"z": latest_pos.z,
|
|
}]
|
|
}
|
|
bodies_data.append(body_dict)
|
|
|
|
print("=== Simulated API Response for Earth ===")
|
|
print(f"ID: {body_dict['id']}")
|
|
print(f"Name: {body_dict['name']}")
|
|
print(f"Type: {body_dict['type']}")
|
|
print(f"Extra Data: {body_dict['extra_data']}")
|
|
print(f"Extra Data Type: {type(body_dict['extra_data'])}")
|
|
if body_dict['extra_data']:
|
|
print(f"Real Radius: {body_dict['extra_data'].get('real_radius')}")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(simulate_api_call())
|