#!/usr/bin/env bash
# FFT band-pass preprocessing ('fft' prep): build the cache, then the best DNN config and the WF baseline on it.
cd "$(dirname "$0")/.."
PY=../../.venv/bin/python
QLOG=logs/queue_fft.log
echo "$(date '+%F %T') build cache/fft" | tee -a "$QLOG"
$PY prepare_data.py fft >> logs/prepare_fft.stdout 2>&1 || { echo "$(date '+%F %T') cache build FAILED" | tee -a "$QLOG"; exit 1; }
for spec in "vlaai_ws _aug_cluster --aug-variant cluster" "wf"; do
  set -- $spec; dec=$1; tag=${2:-}; shift; shift 2>/dev/null; extra="$*"
  exp="${dec}__fft${tag}"
  [[ -f results/$exp.json ]] && continue
  echo "$(date '+%F %T') START $exp" | tee -a "$QLOG"
  if $PY run_experiment.py --decoder $dec --prep fft ${tag:+--tag $tag} $extra < /dev/null >> logs/$exp.stdout 2>&1; then
    rm -f results/$exp.FAILED
    echo "$(date '+%F %T') DONE  $exp: $(grep 'MEAN over' logs/$exp.log | tail -1 | cut -d' ' -f3-)" | tee -a "$QLOG"
  else
    touch results/$exp.FAILED; echo "$(date '+%F %T') FAILED $exp" | tee -a "$QLOG"
  fi
  $PY summarize.py > /dev/null 2>&1 || true
done
echo "$(date '+%F %T') queue fft finished" | tee -a "$QLOG"
