83 lines
3.6 KiB
Bash
Executable File
83 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# --------------------------------------------------------------------------
|
|
# normalize-oneway.sh — تشغيل تصحيح الاتجاهات وإعادة بناء رسم GraphHopper
|
|
#
|
|
# الاستخدام:
|
|
# 1) تقرير فقط (لا يعدّل شيئاً):
|
|
# bash infrastructure/scripts/normalize-oneway.sh audit
|
|
# → infrastructure/osm-data/oneway-audit.csv
|
|
#
|
|
# 2) تعديل طرق محددة بالاسم (الأكثر أماناً):
|
|
# bash infrastructure/scripts/normalize-oneway.sh apply --names "طريق السخنة"
|
|
#
|
|
# 3) تعديل قائمة way_ids معتمدة بعد مراجعة التقرير:
|
|
# bash infrastructure/scripts/normalize-oneway.sh apply \
|
|
# --allowlist infrastructure/osm-data/oneway-allowlist.txt
|
|
#
|
|
# 4) تعديل شامل لأصناف كاملة (خطر — يكسر الطرق المزدوجة الصحيحة):
|
|
# bash infrastructure/scripts/normalize-oneway.sh apply --force
|
|
#
|
|
# بعد apply يعيد السكربت بناء الرسم: يحذف graph-cache ويقلع map-routing.
|
|
# النسخة الأصلية من الـ PBF تبقى كما هي (master_map.osm.pbf.orig).
|
|
# --------------------------------------------------------------------------
|
|
set -euo pipefail
|
|
|
|
DATA_DIR="./infrastructure/osm-data"
|
|
PBF="$DATA_DIR/master_map.osm.pbf"
|
|
VENV="./.venv-osm"
|
|
PY="$VENV/bin/python"
|
|
SCRIPT="./infrastructure/scripts/normalize_oneway.py"
|
|
|
|
MODE="${1:-audit}"
|
|
shift || true
|
|
|
|
[ -f "$PBF" ] || { echo "❌ الملف غير موجود: $PBF"; exit 1; }
|
|
|
|
# ── بيئة pyosmium ────────────────────────────────────────────────────────
|
|
if [ ! -x "$PY" ]; then
|
|
echo "📦 تهيئة بيئة pyosmium..."
|
|
python3 -m venv "$VENV"
|
|
"$VENV/bin/pip" install --quiet --upgrade pip
|
|
"$VENV/bin/pip" install --quiet osmium
|
|
fi
|
|
|
|
if [ "$MODE" = "audit" ]; then
|
|
"$PY" "$SCRIPT" audit --input "$PBF" --report "$DATA_DIR/oneway-audit.csv" "$@"
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$MODE" != "apply" ]; then
|
|
echo "❌ الوضع غير معروف: $MODE (المتاح: audit | apply)"; exit 1
|
|
fi
|
|
|
|
# ── تعديل البيانات ───────────────────────────────────────────────────────
|
|
TMP="$DATA_DIR/master_map.normalized.osm.pbf"
|
|
rm -f "$TMP"
|
|
"$PY" "$SCRIPT" apply --input "$PBF" --output "$TMP" "$@"
|
|
|
|
if [ ! -f "$PBF.orig" ]; then
|
|
echo "💾 حفظ نسخة أصلية: $PBF.orig"
|
|
cp "$PBF" "$PBF.orig"
|
|
fi
|
|
mv "$TMP" "$PBF"
|
|
|
|
# ── إعادة بناء الرسم ─────────────────────────────────────────────────────
|
|
# GraphHopper لا يعيد قراءة الـ PBF إن كان graph-cache موجوداً.
|
|
# نحذف المجلدين: graph-cache (من إعدادنا) و default-gh (اسم GraphHopper
|
|
# الافتراضي، وهو المستخدم فعلياً إن لم يُقرأ config.yml).
|
|
echo "🧹 حذف الرسم المخزّن وإعادة البناء..."
|
|
docker compose stop routing || true
|
|
rm -rf "$DATA_DIR/graph-cache" "$DATA_DIR/default-gh"
|
|
docker compose up -d routing
|
|
|
|
echo "⏳ انتظار جهوزية المحرك (قد يستغرق البناء عدة دقائق)..."
|
|
for i in $(seq 1 120); do
|
|
if curl -fsS http://localhost:8989/health >/dev/null 2>&1; then
|
|
echo "✅ map-routing جاهز."
|
|
exit 0
|
|
fi
|
|
sleep 10
|
|
done
|
|
echo "⚠️ لم يستجب المحرك بعد 20 دقيقة — راجع: docker compose logs -f routing"
|
|
exit 1
|