#!/bin/bash

# Voice Designer Production Captioning Monitor
# Usage: ./monitor_production_captioning.sh [--watch]

PYTHON_PATH="/home/vibert/anaconda3/envs/suno_3/bin/python"
MONITOR_SCRIPT="/home/vibert/projects/neon-voice-data/sunoData/src/sunodata/voice_designer/monitor_captioning_progress.py"
OUTPUT_JSONL="/home/vibert/data/voice_designer/metas_v6_tr_vocal_stems_captioned.jsonl"
TOTAL_RECORDS=921820

# Find the most recent log file
LOG_DIR="/home/vibert/tmp"
LOG_FILE=$(find $LOG_DIR -name "voice_captioning_*.log" -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -d' ' -f2-)

if [ -z "$LOG_FILE" ]; then
    echo "⚠️  No log file found. Running without log analysis."
    LOG_OPTION=""
else
    echo "📋 Using log file: $LOG_FILE"
    LOG_OPTION="--log-file $LOG_FILE"
fi

# Check if watch mode is requested
if [ "$1" == "--watch" ] || [ "$1" == "-w" ]; then
    echo "🔄 Starting watch mode (refresh every 30 seconds)..."
    $PYTHON_PATH $MONITOR_SCRIPT \
        --output-jsonl $OUTPUT_JSONL \
        --total-records $TOTAL_RECORDS \
        $LOG_OPTION \
        --watch
else
    echo "📊 Generating single progress report..."
    $PYTHON_PATH $MONITOR_SCRIPT \
        --output-jsonl $OUTPUT_JSONL \
        --total-records $TOTAL_RECORDS \
        $LOG_OPTION
fi