53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* get_surge_heatmap.php
|
|
* يزود تطبيق الكابتن بأماكن الذروة وفرص الطلب الحالية
|
|
*/
|
|
|
|
require_once __DIR__ . '/../../connect.php';
|
|
|
|
// Authentication happens in connect.php (JWT check)
|
|
if (!isset($user_id) || $role !== 'driver') {
|
|
http_response_code(403);
|
|
echo json_encode(['status' => 'failure', 'message' => 'Unauthorized']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$countryCode = filterRequest('country_code');
|
|
if (!$countryCode) {
|
|
$countryCode = 'SY'; // Fallback
|
|
}
|
|
|
|
$surgeKey = "surge:opportunities:{$countryCode}";
|
|
$hotspotsJson = $redis->get($surgeKey);
|
|
$hotspots = $hotspotsJson ? json_decode($hotspotsJson, true) : [];
|
|
|
|
$driverHeatmap = [];
|
|
|
|
if (!empty($hotspots)) {
|
|
foreach ($hotspots as $grid => $multiplier) {
|
|
// Only show grids with a meaningful multiplier > 1.05
|
|
if ($multiplier > 1.05) {
|
|
list($lat, $lng) = explode('_', $grid);
|
|
$driverHeatmap[] = [
|
|
'lat' => (float)$lat,
|
|
'lng' => (float)$lng,
|
|
'surge_multiplier' => (float)$multiplier,
|
|
'radius_meters' => 1500 // 1.5km grid box
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
jsonSuccess([
|
|
'status' => 'success',
|
|
'message' => 'Surge heatmap data fetched',
|
|
'hotspots' => $driverHeatmap
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
error_log("[get_surge_heatmap] Error: " . $e->getMessage());
|
|
jsonError("Failed to fetch heatmap");
|
|
}
|