feat: استيراد كود سيرو إلى تريبز (سيرو @ecfe7568) — بلا تعديل
قرار المالك 2026-07-27: باك إند سيرو PHP هو المعتمد، وتطبيقاته المجرّبة ميدانياً تحل محل إعادة البناء المؤرشفة. سيرو نفسه لم يُمسّ. الخريطة: backend · payment_server · loction_server · ride_server · passenger_server · docker · dashboard · stress_test → الجذر siro_rider → apps/rider siro_driver → apps/driver siro_admin → dashboards/admin siro_service → dashboards/service android_bot → apps/android_bot socialBot → apps/socialBot نُسخ المتعقَّب في git سيرو فقط عبر `git archive` (3,198 ملفاً / ~169 م.ب) لا `cp -r` — فاستُثنيت مخلفات البناء تلقائياً. بلا أي تعديل محتوى عمداً: كل ما يلي يصير فرقاً مقروءاً مقابل المصدر. لم يُستورد وسببه: siromove.com (الموقع التسويقي يبقى marketing/ في تريبز، سيرو فيه 8 ملفات) · docs و planning (تريبز له docs/ الخاص) · deploy.sh (ليس نشراً على سيرفر بل `git add . && git push origin --all` — فخّ في مستودع آخر) · transit_dashboard (بانتظار قرار مصير backend-transit و dashboards/transit-web). ⚠️ لا يبني بعد — ثلاثة نواقص متوقعة ومقصودة: 1. `.env` و `lib/env/env.g.dart` غير متعقَّبين في سيرو (أسرار لكل مستأجر): كل تطبيق فلاتر يحتاج .env خاصاً ثم توليد env.g.dart بـ build_runner. 2. إعدادات Firebase (9 ملفات google-services.json و GoogleService-Info.plist) يستبعدها .gitignore تريبز — ولكل مستأجر مشروع Firebase خاص أصلاً. 3. apps/driver في سيرو يشير إلى `../../Intaleq/packages/get` خارج المستودع → يجب ضمّ الحزم داخله أسوة بـ apps/rider. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
9909d9b4c1
commit
4d8414c96b
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* get_price_gap_heatmap.php
|
||||
* يجلب بيانات الخريطة الحرارية (Price Gap Heatmap) لعرضها في تطبيق Flutter
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
if ($role !== 'admin' && $role !== 'super_admin') {
|
||||
http_response_code(403);
|
||||
echo json_encode(['status' => 'failure', 'message' => 'Unauthorized']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$countryCode = filterRequest('country_code');
|
||||
|
||||
if (!$countryCode) {
|
||||
jsonError("Missing required parameter: country_code");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Determine current Siro speed price
|
||||
$sqlKazan = "SELECT speedPrice FROM kazan WHERE country = :country LIMIT 1";
|
||||
$stmtKazan = $con->prepare($sqlKazan);
|
||||
$countryNameMap = ['SY' => 'Syria', 'JO' => 'Jordan', 'EG' => 'Egypt', 'IQ' => 'Iraq'];
|
||||
$stmtKazan->execute([':country' => $countryNameMap[strtoupper($countryCode)] ?? 'Syria']);
|
||||
$kazanRow = $stmtKazan->fetch(PDO::FETCH_ASSOC);
|
||||
$currentSpeedPrice = $kazanRow ? (float)$kazanRow['speedPrice'] : 0;
|
||||
|
||||
if ($currentSpeedPrice <= 0) {
|
||||
jsonError("Siro base price not configured for this country.");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Aggregate competitor data by geographical grid (approx 1.5km x 1.5km)
|
||||
$sql = "SELECT
|
||||
ROUND(start_lat * 74, 0) / 74 AS lat_group,
|
||||
ROUND(start_lng * 74, 0) / 74 AS lng_group,
|
||||
AVG(price_per_km) as avg_competitor_price_per_km,
|
||||
COUNT(*) as trip_count
|
||||
FROM scraped_competitor_prices
|
||||
WHERE country_code = :country
|
||||
AND price_per_km > 0
|
||||
AND created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)
|
||||
GROUP BY lat_group, lng_group
|
||||
HAVING trip_count >= 3"; // Require at least 3 trips for a reliable heatmap point
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute([':country' => strtoupper($countryCode)]);
|
||||
$grids = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$heatmapData = [];
|
||||
|
||||
foreach ($grids as $grid) {
|
||||
$compPricePerKm = (float)$grid['avg_competitor_price_per_km'];
|
||||
if ($compPricePerKm <= 0) continue;
|
||||
|
||||
// Calculate PCI for this specific grid
|
||||
// PCI < 1 means we are cheaper. PCI > 1 means we are more expensive.
|
||||
$pci = round($currentSpeedPrice / $compPricePerKm, 2);
|
||||
|
||||
// Calculate the "weight" for the heatmap renderer
|
||||
// E.g. -1 (We are 100% cheaper) to +1 (We are 100% more expensive)
|
||||
$weight = round($pci - 1.0, 2);
|
||||
// Clamp between -1 and 1
|
||||
$weight = max(-1.0, min(1.0, $weight));
|
||||
|
||||
$heatmapData[] = [
|
||||
'lat' => (float)$grid['lat_group'],
|
||||
'lng' => (float)$grid['lng_group'],
|
||||
'pci' => $pci,
|
||||
'weight' => $weight, // Negative = Green (Cheaper), Positive = Red (More expensive)
|
||||
'sample_size' => (int)$grid['trip_count']
|
||||
];
|
||||
}
|
||||
|
||||
jsonSuccess([
|
||||
'total_heatmap_points' => count($heatmapData),
|
||||
'current_siro_price_per_km' => $currentSpeedPrice,
|
||||
'heatmap_data' => $heatmapData
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("[get_price_gap_heatmap] Error: " . $e->getMessage());
|
||||
jsonError("Failed to generate heatmap data");
|
||||
}
|
||||
Reference in New Issue
Block a user