Agent2Robot / backup /record_trial_videos.py
sam133
οΏ½ Restructure repo following successful MCP Hackathon pattern: Clean modular architecture with mcp_client.py, design_tools.py, and organized app.py
fe37569
raw
history blame
4.43 kB
#!/usr/bin/env python3
"""
Record trial videos with timestamps to avoid overriding existing files
"""
import os
import time
from datetime import datetime
import main_orchestrator_enhanced
def record_trial_videos():
"""Run trial and record videos with unique timestamps"""
# Create timestamp for this session
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
print(f"🎬 Recording Trial Videos - Session: {timestamp}")
print("=" * 60)
# Ensure outputs directory exists
os.makedirs("outputs", exist_ok=True)
# List existing videos
existing_videos = [f for f in os.listdir("outputs") if f.endswith('.gif')]
print(f"πŸ“ Existing videos: {len(existing_videos)} files")
for video in existing_videos[:5]: # Show first 5
print(f" β€’ {video}")
if len(existing_videos) > 5:
print(f" β€’ ... and {len(existing_videos) - 5} more")
print(f"\nπŸš€ Starting Enhanced Trial with Video Recording...")
print(f"πŸ“Ή New videos will be saved with timestamp: {timestamp}")
try:
# Test Robot Design
print(f"\nπŸ€– Testing Robot Design...")
robot_success, robot_specs = main_orchestrator_enhanced.console_design_vehicle_for_obstacle(
vehicle_type='robot',
user_task_description=f'Design a robot that can pass the 5cm high obstacle - Session {timestamp}'
)
print(f"βœ… Robot trial completed!")
print(f" Success: {robot_success}")
print(f" Final specs: {robot_specs}")
# Test Drone Design
print(f"\n🚁 Testing Drone Design...")
drone_success, drone_specs = main_orchestrator_enhanced.console_design_vehicle_for_obstacle(
vehicle_type='drone',
user_task_description=f'Design a drone that can pass the 5cm high obstacle - Session {timestamp}'
)
print(f"βœ… Drone trial completed!")
print(f" Success: {drone_success}")
print(f" Final specs: {drone_specs}")
# List new videos created
print(f"\nπŸ“Ή VIDEO RECORDING RESULTS:")
new_videos = [f for f in os.listdir("outputs") if f.endswith('.gif')]
new_count = len(new_videos) - len(existing_videos)
print(f"Total videos now: {len(new_videos)} files (+{new_count} new)")
# Show newest videos (those created in this session)
newest_videos = sorted([f for f in new_videos if f not in existing_videos])
if newest_videos:
print(f"\n🎬 NEW VIDEOS CREATED:")
for video in newest_videos:
file_path = os.path.join("outputs", video)
file_size = os.path.getsize(file_path)
print(f" β€’ {video} ({file_size:,} bytes)")
# Check JSON files
json_files = [f for f in os.listdir(".") if f.startswith("best_") and f.endswith(".json")]
latest_json = sorted(json_files)[-2:] if len(json_files) >= 2 else json_files
if latest_json:
print(f"\nπŸ“„ LATEST JSON RESULTS:")
for json_file in latest_json:
print(f" β€’ {json_file}")
print(f"\n🎯 TRIAL SESSION {timestamp} COMPLETED SUCCESSFULLY!")
print(f" Robot moved: {robot_success}")
print(f" Drone moved: {drone_success}")
print(f" Videos created: {new_count}")
print(f" No existing videos were overridden βœ…")
return {
"timestamp": timestamp,
"robot_success": robot_success,
"drone_success": drone_success,
"videos_created": new_count,
"newest_videos": newest_videos
}
except Exception as e:
print(f"❌ Error during trial recording: {e}")
import traceback
traceback.print_exc()
return None
if __name__ == "__main__":
result = record_trial_videos()
if result:
print(f"\nπŸ† FINAL SUMMARY:")
print(f"Session: {result['timestamp']}")
print(f"Robot performance: {'βœ… Success' if result['robot_success'] else '❌ Failed'}")
print(f"Drone performance: {'βœ… Success' if result['drone_success'] else '❌ Failed'}")
print(f"Videos recorded: {result['videos_created']}")
print(f"All videos preserved! 🎬")
else:
print("❌ Trial recording failed")