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>
This commit is contained in:
@@ -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