Update warehouse digital twin and robot fleet optimization
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
"""Integration tests for Three-Stage Demonstration video generation and FFmpeg encoding."""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from warehouse_twin.demo.staged_video_generator import StagedVideoGenerator, verify_video
|
||||
from warehouse_twin.visualization.trajectory_player import TrajectoryData
|
||||
|
||||
|
||||
def test_staged_demo_video_rendering_and_ffmpeg_encoding(tmp_path: Path):
|
||||
"""Verify that StagedVideoGenerator produces broadcast-quality 1080p MP4 videos validated by ffprobe."""
|
||||
# 1. Prepare minimal valid trajectory data
|
||||
mock_traj = {
|
||||
"metadata": {
|
||||
"simulation_duration": 6.0,
|
||||
"random_seed": 42,
|
||||
},
|
||||
"robots": {
|
||||
"amr_light_01": [
|
||||
{"t": 0.0, "pos": [2.0, 36.0, 0.0], "yaw_deg": 0.0, "state": "IDLE", "battery_percent": 100.0, "is_loaded": False},
|
||||
{"t": 2.0, "pos": [8.0, 36.0, 0.0], "yaw_deg": 0.0, "state": "MOVING_EMPTY", "battery_percent": 99.0, "is_loaded": False},
|
||||
{"t": 4.0, "pos": [14.0, 36.0, 0.0], "yaw_deg": 90.0, "state": "LOADED_TRANSIT", "battery_percent": 98.0, "is_loaded": True},
|
||||
{"t": 6.0, "pos": [14.0, 30.0, 0.0], "yaw_deg": 90.0, "state": "DROPPING", "battery_percent": 97.0, "is_loaded": True},
|
||||
],
|
||||
"amr_heavy_01": [
|
||||
{"t": 0.0, "pos": [2.0, 38.0, 0.0], "yaw_deg": 0.0, "state": "IDLE", "battery_percent": 100.0, "is_loaded": False},
|
||||
{"t": 3.0, "pos": [10.0, 38.0, 0.0], "yaw_deg": 0.0, "state": "CHARGING", "battery_percent": 80.0, "is_loaded": False},
|
||||
{"t": 6.0, "pos": [10.0, 38.0, 0.0], "yaw_deg": 0.0, "state": "CHARGING", "battery_percent": 85.0, "is_loaded": False},
|
||||
],
|
||||
},
|
||||
}
|
||||
traj_data = TrajectoryData.from_dict(mock_traj)
|
||||
|
||||
# 2. Configure video generator and inputs
|
||||
from warehouse_twin.config.loader import ConfigLoader
|
||||
from warehouse_twin.analytics.kpi_calculator import ComprehensiveKPIReport, DistributionStats
|
||||
|
||||
project_root = Path(__file__).resolve().parent.parent.parent
|
||||
loader = ConfigLoader(project_root / "config")
|
||||
bundle = loader.load_all()
|
||||
|
||||
out_video = tmp_path / "test_stage1_preview.mp4"
|
||||
generator = StagedVideoGenerator(
|
||||
width=1920,
|
||||
height=1080,
|
||||
fps=15, # Faster for test execution
|
||||
playback_speed=2.0,
|
||||
)
|
||||
|
||||
kpi_report = ComprehensiveKPIReport(
|
||||
throughput_tasks_per_hour=78.5,
|
||||
turnaround_time=DistributionStats(p50=35.0, p90=45.2),
|
||||
on_time_delivery_percent=100.0,
|
||||
total_travel_distance_meters=420.5,
|
||||
loaded_distance_ratio_percent=58.2,
|
||||
fleet_utilization_percent=68.4,
|
||||
conflicts_detected=0,
|
||||
total_yield_wait_time_seconds=0.0,
|
||||
energy_intensity_kwh_per_task=0.042,
|
||||
total_energy_consumed_kwh=1.25,
|
||||
tasks_completed=12,
|
||||
bay_occupancy_percent=25.0,
|
||||
avg_charging_queue_wait_seconds=0.0,
|
||||
)
|
||||
|
||||
# 3. Render video
|
||||
result_path = generator.render_baseline_video(
|
||||
output_mp4=out_video,
|
||||
wh_cfg=bundle.warehouse,
|
||||
trajectory_data=traj_data,
|
||||
kpi_report=kpi_report,
|
||||
duration_seconds=6.0,
|
||||
)
|
||||
|
||||
# 4. Assert video file was written
|
||||
assert result_path.exists(), f"Rendered video should exist at {result_path}"
|
||||
assert result_path.stat().st_size > 5000, "Rendered video file size must exceed 5KB"
|
||||
|
||||
# 5. Validate video with ffprobe
|
||||
probe = verify_video(str(result_path))
|
||||
assert probe["valid"] is True, f"Video verification failed: {probe.get('error')}"
|
||||
assert probe["width"] == 1920, f"Expected width 1920, got {probe.get('width')}"
|
||||
assert probe["height"] == 1080, f"Expected height 1080, got {probe.get('height')}"
|
||||
assert probe["codec"] in ("h264", "libx264"), f"Expected h264 codec, got {probe.get('codec')}"
|
||||
assert probe["duration_seconds"] > 0, "Video duration must be positive"
|
||||
Reference in New Issue
Block a user