#!/bin/bash
# Example script for comparing two model evaluation results
#
# Usage: bash eval_tools/compare_models_example.sh

# =============================================================================
# Configuration
# =============================================================================

# Model 1 (mono3d)

# Set PYTHONPATH to project root for module imports
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
export PYTHONPATH="${PROJECT_ROOT}:${PYTHONPATH}"
MODEL1_REPORT="eval_results_multiprocess/mono3d/20260203_162537/evaluation_report.json"

MODEL1_NAME="mono3d"

# Model 2 (yolov5s-300w)
MODEL2_REPORT="eval_results_multiprocess/yolov5s/20260203_161644/evaluation_report.json"
MODEL2_NAME="yolov5s-300w"

# Output directory
OUTPUT_DIR="comparison_results/$(date +%Y%m%d_%H%M%S)"

# =============================================================================
# Run Comparison
# =============================================================================

echo "=========================================="
echo "Model Evaluation Comparison"
echo "=========================================="
echo "Model 1: $MODEL1_NAME"
echo "  Report: $MODEL1_REPORT"
echo "Model 2: $MODEL2_NAME"
echo "  Report: $MODEL2_REPORT"
echo "Output: $OUTPUT_DIR"
echo "=========================================="

# Check if reports exist
if [ ! -f "$MODEL1_REPORT" ]; then
    echo "Error: Model 1 report not found: $MODEL1_REPORT"
    exit 1
fi

if [ ! -f "$MODEL2_REPORT" ]; then
    echo "Error: Model 2 report not found: $MODEL2_REPORT"
    exit 1
fi

# Run comparison with visualization
python eval_tools/model_comparison/compare_models_visualize.py \
    --model1 "$MODEL1_REPORT" \
    --model2 "$MODEL2_REPORT" \
    --output-dir "$OUTPUT_DIR" \
    --model1-name "$MODEL1_NAME" \
    --model2-name "$MODEL2_NAME"

# Check if comparison was successful
if [ $? -eq 0 ]; then
    echo ""
    echo "✓ Comparison completed successfully!"
    echo ""
    echo "View results:"
    echo "  Text report: $OUTPUT_DIR/comparison_report.txt"
    echo "  JSON report: $OUTPUT_DIR/comparison_report.json"
    echo "  Plots: $OUTPUT_DIR/comparison_*.png"
    echo ""
    
    # Display summary from text report
    if [ -f "$OUTPUT_DIR/comparison_report.txt" ]; then
        echo "=========================================="
        echo "Quick Summary (from report):"
        echo "=========================================="
        grep -A 20 "2D DETECTION METRICS - OVERALL COMPARISON" "$OUTPUT_DIR/comparison_report.txt" | head -25
    fi
else
    echo ""
    echo "✗ Comparison failed!"
    exit 1
fi
