#!/bin/bash

# ========== Params ==========
experiment_dir="/home/marcus/code/ros2_ws/src/khronos/output/tmp/2025_08_19-01_36_50"
# Get package path using ros2 pkg prefix
pkg_path=$(ros2 pkg prefix khronos_eval 2>/dev/null)
if [[ $? -ne 0 ]]; then
    echo "Could not find khronos_eval package. Did you source the ROS2 workspace?"
    exit 1
fi
evaluation_config=$pkg_path/share/khronos_eval/config/pipeline/office.yaml           # Which evaluation config to use.
force_recompute=true                                                                 # Force recomputation if output or results already exist.
only_evaluate_final_map=false                                                        # Only evaluate the final map.
# ========== What to run ==========
run_evaluation=true

# ========== Params can be supplied as arguments ==========
if [ -n "$1" ]; then
    experiment_dir=$1
fi
if [ -n "$2" ]; then
    evaluation_config=$2
fi
if [ -n "$3" ]; then
    force_recompute=$3
fi
if [ -n "$4" ]; then
    only_evaluate_final_map=$4
fi

# ========== Autogenerated arguments ==========
# Find executable directory - in ROS2 it's in lib/khronos_eval
exec_dir=$pkg_path/lib/khronos_eval
if [[ ! -d $exec_dir ]]; then
    echo "Could not find executable directory at $exec_dir. Did you build the workspace?"
    exit 1
fi
src_dir=$pkg_path/share/khronos_eval
if [[ ! -d $src_dir ]]; then
    echo "Could not find source directory at $src_dir. Did you install the package?"
    exit 1
fi

# ========== Functions ==========
function evaluate {
    if [ $run_evaluation == true ]; then
        echo "---------- Evaluation ----------"
        eval $exec_dir/exp_pipeline $evaluation_config $experiment_dir $force_recompute $run_evaluation $only_evaluate_final_map
    fi
}
# ========== Run Evaluation ==========
evaluate
