#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────────────────
# Dataset Profiling Launch Script
# Usage: bash run_profiling.sh [original|roi]
#   Positional arg (optional): analysis mode — "original" (default) or "roi"
# ─────────────────────────────────────────────────────────────────────────────

# ── User-configurable parameters ─────────────────────────────────────────────

# Path to dataset YAML config
DATA="data/mono3d.yaml"

# Which split(s) to profile: train | val | both
SPLIT="train"

# Max files to process per split (0 = all)
MAX_FILES=0

# Output directory (analysis mode suffix is appended automatically)
OUTPUT_DIR="dataset_profiling_cncap"

# Image size for pixel-unit conversion [width height]
# Leave empty ("") to use the default from YAML (ori_img_size or roi_size)
IMG_SIZE=""

# Analysis mode: "original" (full image) or "roi" (crop + calibration-based filtering)
# Can also be overridden by the first positional argument: bash run_profiling.sh roi
ANALYSIS_MODE="${1:-original}"

# Number of parallel workers (0 = auto-detect CPU count, 1 = sequential)
WORKERS=32

# ── Build command ─────────────────────────────────────────────────────────────

CMD="python tools/scripts_for_gt/profiling/dataset_profiling.py \
  --data         ${DATA} \
  --split        ${SPLIT} \
  --max-files    ${MAX_FILES} \
  --output-dir   ${OUTPUT_DIR} \
  --analysis-mode ${ANALYSIS_MODE} \
  --workers      ${WORKERS}"

if [ -n "${IMG_SIZE}" ]; then
    CMD="${CMD} --img-size ${IMG_SIZE}"
fi

# ── Run ───────────────────────────────────────────────────────────────────────

cd "$(dirname "$0")/../../.." || exit 1   # ensure cwd is project root

echo "========================================================================"
echo "  Dataset Profiling"
echo "  data:          ${DATA}"
echo "  split:         ${SPLIT}"
echo "  analysis-mode: ${ANALYSIS_MODE}"
echo "  max-files:     ${MAX_FILES}  (0 = all)"
echo "  workers:       ${WORKERS}"
echo "  output-dir:    ${OUTPUT_DIR}_${ANALYSIS_MODE}"
[ -n "${IMG_SIZE}" ] && echo "  img-size:      ${IMG_SIZE}"
echo "========================================================================"

eval "${CMD}"
