115 lines
3.4 KiB
Bash
Executable File
115 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# run_all_coops.sh - Master runner for batch chicken counting across farm sites and floors
|
|
# Supports:
|
|
# ./run_all_coops.sh site_a -> Run Site A (5 coops x 2 floors = 10 floors)
|
|
# ./run_all_coops.sh site_b -> Run Site B (3 coops x 3 floors = 9 floors)
|
|
# ./run_all_coops.sh all -> Run All 19 floors across both sites
|
|
# ./run_all_coops.sh site_a 2026-06-18 -> Run Site A for a specific date
|
|
# ./run_all_coops.sh K1-L1 -> Run specific floor
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$SCRIPT_DIR"
|
|
export PYTHONPATH="$SCRIPT_DIR/src"
|
|
|
|
if [ -f "$SCRIPT_DIR/venv/bin/python" ]; then
|
|
PYTHON="$SCRIPT_DIR/venv/bin/python"
|
|
else
|
|
PYTHON="python3"
|
|
fi
|
|
|
|
TARGET="${1:-site_a}"
|
|
DATE="${2:-}"
|
|
MAX_JOBS="${MAX_JOBS:-2}"
|
|
NO_VIDEO_FLAG="--no-video"
|
|
|
|
SITE_A_FLOORS=(
|
|
"K1-L1" "K1-L2"
|
|
"K2-L1" "K2-L2"
|
|
"K3-L1" "K3-L2"
|
|
"K4-L1" "K4-L2"
|
|
"K5-L1" "K5-L2"
|
|
)
|
|
|
|
SITE_B_FLOORS=(
|
|
"K1-L1" "K1-L2" "K1-L3"
|
|
"K2-L1" "K2-L2" "K2-L3"
|
|
"K3-L1" "K3-L2" "K3-L3"
|
|
)
|
|
|
|
floors=()
|
|
|
|
case "${TARGET,,}" in
|
|
site_a|site-a|"a")
|
|
echo "🏢 Target: Site A (5 coops, 2 floors each = 10 floors)"
|
|
floors=("${SITE_A_FLOORS[@]}")
|
|
;;
|
|
site_b|site-b|"b")
|
|
echo "🏢 Target: Site B (3 coops, 3 floors each = 9 floors)"
|
|
floors=("${SITE_B_FLOORS[@]}")
|
|
;;
|
|
all|"both")
|
|
echo "🏢 Target: All Sites (19 floors total)"
|
|
# Combined distinct floor configurations
|
|
floors=(
|
|
"K1-L1" "K1-L2" "K1-L3"
|
|
"K2-L1" "K2-L2" "K2-L3"
|
|
"K3-L1" "K3-L2" "K3-L3"
|
|
"K4-L1" "K4-L2"
|
|
"K5-L1" "K5-L2"
|
|
)
|
|
;;
|
|
*)
|
|
# Single floor config (e.g. K1-L1 or kandang-atas)
|
|
echo "📍 Target Floor: $TARGET"
|
|
floors=("$TARGET")
|
|
;;
|
|
esac
|
|
|
|
echo "======================================================================"
|
|
echo "🚀 Starting Multi-Floor Batch Processing"
|
|
echo " Floors to Process : ${#floors[@]} floors (${floors[*]})"
|
|
echo " Auto-Discovery : OFF (Using static site profiles)"
|
|
echo " Max Parallel Jobs : $MAX_JOBS"
|
|
if [ -n "$DATE" ]; then
|
|
echo " Target Date : $DATE"
|
|
fi
|
|
echo "======================================================================"
|
|
|
|
start_time=$(date +%s)
|
|
success_count=0
|
|
fail_count=0
|
|
|
|
for fl in "${floors[@]}"; do
|
|
echo ""
|
|
echo "----------------------------------------------------------------------"
|
|
echo "▶️ Processing Floor: $fl"
|
|
echo "----------------------------------------------------------------------"
|
|
|
|
cfg_file="$SCRIPT_DIR/configs/floor_config/${fl}.yaml"
|
|
if [ ! -f "$cfg_file" ]; then
|
|
cfg_file="$fl"
|
|
fi
|
|
|
|
cmd=("$PYTHON" -m chicken_counter.cli batch --config "$cfg_file" $NO_VIDEO_FLAG)
|
|
if [ -n "$DATE" ]; then
|
|
cmd+=(--date "$DATE")
|
|
fi
|
|
|
|
if "${cmd[@]}"; then
|
|
success_count=$((success_count + 1))
|
|
echo "✅ Finished floor: $fl"
|
|
else
|
|
fail_count=$((fail_count + 1))
|
|
echo "❌ Failed floor: $fl"
|
|
fi
|
|
done
|
|
|
|
elapsed=$(( $(date +%s) - start_time ))
|
|
echo ""
|
|
echo "======================================================================"
|
|
echo "✨ Batch Run Finished in ${elapsed}s!"
|
|
echo " Successful Floors : $success_count"
|
|
echo " Failed Floors : $fail_count"
|
|
echo "======================================================================"
|