Files
maps-saas/infrastructure/scripts/check-bidirectional.sh
T
Hamza-Ayed 3a49029ee4 fix(routing): allow bidirectional travel on two-way corridors
- u_turn_costs: 60 (was infinite -> U-turns forbidden -> huge detours)
- distance_influence 70 -> 20, de-prioritise service/living_street/track
- restore safe ignored_highways (was "" -> footways imported, bad snapping)
- profiles_ch -> profiles_lm (edge-based CH too heavy with turn_costs)
- server port 8989 -> 8080 to match compose mapping, healthcheck and API
- add normalize-oneway + check-bidirectional tooling
2026-07-26 15:35:55 +03:00

68 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
# --------------------------------------------------------------------------
# check-bidirectional.sh — فحص التوجيه في الاتجاهين على نفس المقطع
#
# المنطق: على طريق ثنائي الاتجاه سليم، مسافة A→B ومسافة B→A يجب أن تكونا
# متقاربتين. فارق كبير (> عتبة النسبة) = المحرك يجبر التفافاً في أحد
# الاتجاهين، أي أن الحافة أحادية الاتجاه في البيانات أو أن قيود الدوران
# تمنع العودة.
#
# الاستخدام:
# bash infrastructure/scripts/check-bidirectional.sh # حالات مدمجة
# bash infrastructure/scripts/check-bidirectional.sh 32.05 36.09 32.07 36.12
#
# متغيّرات: GH_URL (افتراضي http://localhost:8989)، RATIO (افتراضي 1.5)
# --------------------------------------------------------------------------
set -uo pipefail
GH_URL="${GH_URL:-http://localhost:8989}"
RATIO="${RATIO:-1.5}"
# lat1 lon1 lat2 lon2 label
CASES=(
"32.0537 36.0891 32.0721 36.1204 طريق السخنة (الزرقاء)"
"31.9539 35.9106 31.9705 35.9412 عمّان — محور رئيسي"
)
if [ "$#" -ge 4 ]; then
CASES=("$1 $2 $3 $4 مقطع مخصص")
fi
dist() { # lat1 lon1 lat2 lon2 → متر أو FAIL
curl -fsS -X POST "$GH_URL/route" -H 'Content-Type: application/json' \
-d "{\"points\":[[$2,$1],[$4,$3]],\"profile\":\"car\",\"instructions\":false,\"calc_points\":false}" \
2>/dev/null | sed -n 's/.*"distance":\([0-9.]*\).*/\1/p' | head -1
}
echo "════════════════════════════════════════════════════════════"
echo " فحص التوجيه ثنائي الاتجاه — $GH_URL"
echo "════════════════════════════════════════════════════════════"
FAIL=0
for c in "${CASES[@]}"; do
read -r a b x y label <<< "$c"
fwd=$(dist "$a" "$b" "$x" "$y")
rev=$(dist "$x" "$y" "$a" "$b")
echo ""
echo "▸ $label"
if [ -z "$fwd" ] || [ -z "$rev" ]; then
echo " ✗ لم يُعِد المحرك مساراً في أحد الاتجاهين (تحقّق أن الحاوية تعمل والنقاط داخل التغطية)"
FAIL=1
continue
fi
printf " ذهاب : %.0f م\n عودة : %.0f م\n" "$fwd" "$rev"
verdict=$(awk -v f="$fwd" -v r="$rev" -v t="$RATIO" \
'BEGIN{ if(f<=0||r<=0){print "bad"; exit} m=(f>r?f/r:r/f); printf "%s %.2f", (m>t?"fail":"ok"), m }')
set -- $verdict
if [ "$1" = "ok" ]; then
echo " ✓ متقارب (نسبة ${2})"
else
echo " ✗ فارق كبير (نسبة ${2:-؟}) — اتجاه واحد مفروض أو التفاف إجباري"
echo " شغّل: bash infrastructure/scripts/normalize-oneway.sh audit"
FAIL=1
fi
done
echo ""
[ "$FAIL" = "0" ] && echo "✅ كل الحالات سليمة." || echo "⚠️ توجد حالات تحتاج معالجة."
exit $FAIL