Files
intaleq/backend/bot/fill_durations.php
Hamza-AyedandClaude Opus 5 92dc6b3641 chore: استيراد أولي من سيرو (ecfe7568) — بلا أي تعديل
نسخة كاملة من مستودع سيرو عند ecfe7568 لتكون أساس تطبيق «انطلق».
نُسخ المتعقَّب في git فقط (12,509 ملفاً / 302 م.ب) بـ git archive، لا
`cp -r` — فاستُثنيت تلقائياً مخلفات البناء (build · node_modules ·
.dart_tool · .gradle · Pods ≈ 10.7 غ.ب) وكل ما يستثنيه .gitignore.

هذا الكوميت **بلا أي تعديل عمداً** حتى يكون كل ما يليه فرقاً مقروءاً
مقابل سيرو الأصلي. سيرو نفسه لم يُمسّ.

⚠️ لا يبني بعد: `.env` و`lib/env/env.g.dart` غير متعقَّبين في سيرو (وهذا
صحيح — أسرار لكل مستأجر). كل تطبيق فلاتر هنا يحتاج .env خاصاً بانطلق ثم
توليد env.g.dart عبر build_runner. لا تُنسخ أسرار سيرو.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:10:29 +03:00

75 lines
2.3 KiB
PHP

<?php
// =========================================================
// backend/bot/fill_durations.php
// One-off script to fill missing duration_min values
// in the scraped_competitor_prices table using Intaleq Maps.
// =========================================================
require_once __DIR__ . '/../core/bootstrap.php';
require_once __DIR__ . '/../functions.php';
require_once __DIR__ . '/../core/osrm_routing.php';
try {
$con = Database::get('main');
} catch (Exception $e) {
die("Database connection failed: " . $e->getMessage() . "\n");
}
echo "Fetching rows where duration_min IS NULL...\n";
// Get rows needing update
$stmt = $con->prepare("
SELECT id, start_lat, start_lng, end_lat, end_lng, country_code
FROM scraped_competitor_prices
WHERE duration_min IS NULL
AND start_lat IS NOT NULL
AND start_lng IS NOT NULL
");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!$rows || count($rows) === 0) {
echo "No rows found needing duration updates.\n";
exit(0);
}
echo "Found " . count($rows) . " rows to update. Processing...\n";
$updateStmt = $con->prepare("
UPDATE scraped_competitor_prices
SET duration_min = :duration_min, distance_km = :distance_km
WHERE id = :id
");
$successCount = 0;
$failCount = 0;
foreach ($rows as $index => $row) {
$id = $row['id'];
$countryCode = $row['country_code'];
// Call GraphHopper / Intaleq Maps
$routeInfo = getOsrmRouteDetails($row['start_lat'], $row['start_lng'], $row['end_lat'], $row['end_lng'], $countryCode);
if ($routeInfo && isset($routeInfo['duration_min']) && isset($routeInfo['distance_km'])) {
$updateStmt->execute([
':duration_min' => (int) round($routeInfo['duration_min']),
':distance_km' => $routeInfo['distance_km'],
':id' => $id
]);
$successCount++;
echo "Row $id: Distance {$routeInfo['distance_km']}km, Duration " . round($routeInfo['duration_min']) . "min [SUCCESS]\n";
} else {
$failCount++;
echo "Row $id: Failed to fetch route details.\n";
}
// Small sleep to avoid hitting API rate limits too hard
usleep(100000); // 100ms
}
echo "======================================\n";
echo "Completed processing " . count($rows) . " rows.\n";
echo "Success: $successCount\n";
echo "Failed: $failCount\n";