#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MODEL_INFERENCE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
PROJECT_ROOT="$(cd "${MODEL_INFERENCE_DIR}/../.." && pwd)"

# Launcher for scene-keyed CSV -> JSON conversion.
#
# Usage:
#   bash tools/model_inference/scripts/run_parse_scene_csv_to_json.sh
#
# Common env overrides:
#   INPUT_FILE, SCENE_COLUMN, OUTPUT_FILE, KEEP_SCENE_FIELD, EXTRA_ARGS

PYTHON_BIN="${PYTHON_BIN:-/deeplearning_team/ydong/dongying/miniconda/envs/dev/bin/python}"
INPUT_FILE="${INPUT_FILE:-${MODEL_INFERENCE_DIR}/examples/events/G1Q3_场地评测数据集_0418.csv}"
SCENE_COLUMN="${SCENE_COLUMN:-scene}"
OUTPUT_FILE="${OUTPUT_FILE:-}"
KEEP_SCENE_FIELD="${KEEP_SCENE_FIELD:-0}"
EXTRA_ARGS="${EXTRA_ARGS:-}"

CMD=(
  "${PYTHON_BIN}" "${MODEL_INFERENCE_DIR}/data_tools/parse_scene_csv_to_json.py"
  --input-file "${INPUT_FILE}"
  --scene-column "${SCENE_COLUMN}"
)

if [[ -n "${OUTPUT_FILE}" ]]; then
  CMD+=(--output-file "${OUTPUT_FILE}")
fi

if [[ "${KEEP_SCENE_FIELD}" == "1" ]]; then
  CMD+=(--keep-scene-field)
fi

if [[ -n "${EXTRA_ARGS}" ]]; then
  # shellcheck disable=SC2206
  EXTRA_ARR=(${EXTRA_ARGS})
  CMD+=("${EXTRA_ARR[@]}")
fi

CMD+=("$@")

"${CMD[@]}"
