#!/usr/bin/env bash

set -euo pipefail

ANALYSIS_REPORT=${ANALYSIS_REPORT:-/data1/dongying/Mono3d/G1Q3/model_inference/KPI/DL_KPI_SCENE/model_20260403_analysis/analysis_3d/analysis_report.json}
CONFIG_PATH=${CONFIG_PATH:-eval_tools/configs/eval_config_yolov26s-roi0.yaml}
OUTPUT_BASE=${OUTPUT_BASE:-$(dirname "${ANALYSIS_REPORT}")/visualizations_distance}
TOP_K=${TOP_K:-300}
TOP_K_PER_DISTANCE_BIN=${TOP_K_PER_DISTANCE_BIN:-50}

METRICS=(longitudinal_error heading_error reversal)
CLASSES=(car suv van bus truck pedestrian bicycle)
PYTHON_BIN=${PYTHON_BIN:-/deeplearning_team/ydong/dongying/miniconda/envs/dev/bin/python}

for metric_name in "${METRICS[@]}"; do
  for class_name in "${CLASSES[@]}"; do
    output_dir="${OUTPUT_BASE}/${metric_name}_vis_${class_name}"

    echo "============================================================"
    echo "Running 3D visualization"
    echo "  metric: ${metric_name}"
    echo "  class:  ${class_name}"
    echo "  output: ${output_dir}"
    echo "============================================================"

    "${PYTHON_BIN}" eval_tools/analysis/visualize_3d_badcases.py \
      --analysis-report "${ANALYSIS_REPORT}" \
      --config "${CONFIG_PATH}" \
      --metrics "${metric_name}" \
      --classes "${class_name}" \
      --top-k "${TOP_K}" \
      --top-k-per-distance-bin "${TOP_K_PER_DISTANCE_BIN}" \
      --group-by-distance-bin \
      --output-dir "${output_dir}"
  done
done
