Files
traccar_animation/test_transition.py
2025-07-08 15:26:33 +03:00

116 lines
4.1 KiB
Python

#!/usr/bin/env python3
"""
Test script to verify the transition from space entry to route following works correctly
"""
import sys
import os
sys.path.append('/home/pi/Desktop/traccar_animation')
from py_scripts.video_3d_generator import create_3d_frame, draw_3d_route
import numpy as np
def test_route_transition():
"""Test the transition from space entry to route following"""
print("Testing route transition...")
# Sample route positions
positions = [
{'latitude': 45.7749, 'longitude': -122.4194, 'speed': 0, 'deviceTime': '2025-07-08 12:00:00'},
{'latitude': 45.7750, 'longitude': -122.4195, 'speed': 20, 'deviceTime': '2025-07-08 12:01:00'},
{'latitude': 45.7751, 'longitude': -122.4196, 'speed': 30, 'deviceTime': '2025-07-08 12:02:00'},
{'latitude': 45.7752, 'longitude': -122.4197, 'speed': 40, 'deviceTime': '2025-07-08 12:03:00'},
{'latitude': 45.7753, 'longitude': -122.4198, 'speed': 50, 'deviceTime': '2025-07-08 12:04:00'},
]
# Test parameters
center_lat = 45.7751
center_lon = -122.4196
min_lat = 45.7740
max_lat = 45.7760
min_lon = -122.4210
max_lon = -122.4180
width = 1920
height = 1080
# Test the first few frames (transition period)
for frame_index in range(len(positions)):
print(f"Testing route frame {frame_index}...")
try:
current_pos = positions[frame_index]
frame = create_3d_frame(
current_pos, positions, frame_index,
center_lat, center_lon, min_lat, max_lat, min_lon, max_lon,
width, height
)
# Check frame integrity
if frame is None:
print(f"ERROR: Route frame {frame_index} is None")
return False
if frame.shape != (height, width, 3):
print(f"ERROR: Route frame {frame_index} has wrong shape: {frame.shape}")
return False
# Check for valid pixel values
if np.any(frame < 0) or np.any(frame > 255):
print(f"ERROR: Route frame {frame_index} has invalid pixel values")
return False
print(f"Route frame {frame_index} OK - Shape: {frame.shape}, Min: {np.min(frame)}, Max: {np.max(frame)}")
except Exception as e:
print(f"ERROR: Route frame {frame_index} failed: {e}")
import traceback
traceback.print_exc()
return False
print("All route transition frames generated successfully!")
return True
def test_draw_3d_route():
"""Test the draw_3d_route function with various scenarios"""
print("Testing draw_3d_route function...")
# Create test frame
frame = np.zeros((1080, 1920, 3), dtype=np.uint8)
# Test scenarios
test_cases = [
# Empty route
([], 0, "Empty route"),
# Single point - no past points
([(960, 540, False)], 0, "Single future point"),
# Single point - current point
([(960, 540, True)], 0, "Single current point"),
# Multiple points - beginning of route
([(960, 540, True), (970, 550, False), (980, 560, False)], 0, "Beginning of route"),
# Multiple points - middle of route
([(950, 530, True), (960, 540, True), (970, 550, False), (980, 560, False)], 1, "Middle of route"),
]
for route_points_3d, frame_index, description in test_cases:
print(f"Testing: {description}")
try:
test_frame = frame.copy()
draw_3d_route(test_frame, route_points_3d, frame_index)
print(f"{description} - OK")
except Exception as e:
print(f"{description} - Failed: {e}")
return False
print("All draw_3d_route tests passed!")
return True
if __name__ == "__main__":
route_success = test_route_transition()
draw_success = test_draw_3d_route()
if route_success and draw_success:
print("✅ All transition tests PASSED")
sys.exit(0)
else:
print("❌ Some transition tests FAILED")
sys.exit(1)