get('siro:cache:heatmap:data'); } catch (Exception $e) { echo json_encode(['status' => 'error', 'message' => 'Redis connection failed']); exit; } if (!$cacheJson) { echo json_encode(['status' => 'error', 'message' => 'Cache not generated yet']); exit; } $cacheData = json_decode($cacheJson, true); if (!$cacheData || !isset($cacheData['data'])) { echo json_encode(['status' => 'error', 'message' => 'Invalid cache data']); exit; } $limitDate = date('Y-m-d', strtotime("-$days days")); $filteredLocations = []; $stats = ['geofence' => 0, 'app_usage' => 0, 'silent_push' => 0]; $dataByCountry = $cacheData['data']; // تحديد الدول التي سنسحب منها $countriesToSearch = ($countryCode === 'ALL') ? array_keys($dataByCountry) : [$countryCode]; foreach ($countriesToSearch as $cc) { if (!isset($dataByCountry[$cc])) continue; foreach ($dataByCountry[$cc] as $loc) { // فلتر الأيام if ($loc['date'] < $limitDate) continue; // فلتر المصدر if ($source !== 'all' && $loc['source'] !== $source) continue; $filteredLocations[] = [ 'latitude' => $loc['lat'], 'longitude' => $loc['lng'], 'source' => $loc['source'] ]; if (isset($stats[$loc['source']])) { $stats[$loc['source']]++; } } } echo json_encode([ 'status' => 'success', 'data' => $filteredLocations, 'total' => count($filteredLocations), 'stats' => $stats, 'source' => 'redis_cache' ], JSON_UNESCAPED_UNICODE); // تم إزالة دالة filterRequest من هنا لتجنب خطأ Redeclaration لأنها معرفة في functions.php ?>