Files
chicken-counting-sukawarna-det/start_dashboard.sh
T

55 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Portable dashboard launcher — resolves all paths relative to this script's directory.
# Works regardless of where the project folder is located or its name.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export PYTHONPATH="$SCRIPT_DIR/src"
# Use project-local venv if available, otherwise fall back to system python3
if [ -f "$SCRIPT_DIR/venv/bin/python" ]; then
PYTHON="$SCRIPT_DIR/venv/bin/python"
else
PYTHON="python3"
fi
DB_PATH="${DB_PATH:-$SCRIPT_DIR/db/chicken_counts.db}"
PORT="${PORT:-8080}"
DATE_ARG="${DATE_ARG:-}"
CMD=("$PYTHON" "$SCRIPT_DIR/dashboard.py" --port "$PORT" --db "$DB_PATH")
# Startup check: Ensure sibling VIDEOS directory structure exists
VIDEOS_BASE="$SCRIPT_DIR/../VIDEOS"
if [ ! -d "$VIDEOS_BASE" ]; then
echo "[dashboard] 📁 Sibling directory '$VIDEOS_BASE' not found; creating skeleton directory..."
mkdir -p "$VIDEOS_BASE/cycle7"
fi
# Auto-discover mortality directories (any folder containing mortality_report.json or mortality folders)
if [ -n "${MORTALITY_DIRS:-}" ]; then
IFS=',' read -ra MDIRS <<< "$MORTALITY_DIRS"
for mdir in "${MDIRS[@]}"; do
CMD+=(--mortality-dir "$mdir")
done
else
# Recursively discover all mortality subdirectories under ../VIDEOS
FOUND_MDIRS=()
while IFS= read -r -d '' mdir; do
FOUND_MDIRS+=("$mdir")
done < <(find "$VIDEOS_BASE" -type d -name "mortality" -print0 2>/dev/null)
if [ ${#FOUND_MDIRS[@]} -gt 0 ]; then
for mdir in "${FOUND_MDIRS[@]}"; do
CMD+=(--mortality-dir "$mdir")
done
fi
fi
if [ -n "$DATE_ARG" ]; then
CMD+=(--date "$DATE_ARG")
fi
echo "[dashboard] Starting at http://0.0.0.0:${PORT} db=${DB_PATH}"
exec "${CMD[@]}"