From df23cc4a402f38866361c3f25f18950a53a72537 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Mon, 16 Jun 2025 13:33:38 +0530 Subject: [PATCH] Show empty gauges if not value --- .../APIS/CustomerApi/TelemetryController.php | 7 --- app/Services/TelemetryService.php | 43 ++++++++++++------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php b/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php index 6a0d9a7..3d972ec 100644 --- a/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php +++ b/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php @@ -1297,13 +1297,6 @@ class TelemetryController extends Controller $cachedData = Cache::remember($cacheKey, now()->addSeconds(value: 60), function () use ($deviceId) { $deviceParams = $this->getPopupTimeseriesKeys($deviceId); - if ($deviceParams->isEmpty()) { - return [ - 'success' => false, - 'error' => 'No indicator parameters found for this device' - ]; - } - $keyNameList = $deviceParams->pluck('key_name')->implode(','); $displayNameMap = $deviceParams->pluck('display_name', 'key_name')->toArray(); diff --git a/app/Services/TelemetryService.php b/app/Services/TelemetryService.php index 2bbf2e1..d7f8c10 100644 --- a/app/Services/TelemetryService.php +++ b/app/Services/TelemetryService.php @@ -220,23 +220,34 @@ class TelemetryService $thresholds = $this->getThresholdMap()[$key] ?? $this->getThresholdMap()['default']; $thresholdLimits = $this->getThresholdLimit($deviceId)[$key] ?? $this->getThresholdLimit($deviceId)['default']; - $status = $this->getHealthStatus($value, $thresholds); - $statusColor = match($status) { - 'Alert' => 'red', - 'Attention' => 'orange', - 'Stable' => 'green' - }; + if(!$value){ + $transformedTelemetry[] = [ + 'display_name' => $displayNameMap[$key] ?? $key, + 'value' => "", + 'health_status' => "", + 'status_color' => "", + 'thresholds' => $thresholds, + 'limit' => $thresholdLimits + ]; + } else { + $status = $this->getHealthStatus($value, $thresholds); + $statusColor = match($status) { + 'Alert' => 'red', + 'Attention' => 'orange', + 'Stable' => 'green' + }; - $transformedTelemetry[] = [ - 'display_name' => $displayNameMap[$key] ?? $key, - 'value' => $this->getTypeWiseValue($key, $value), - 'health_status' => !$isActive - ? 'Offline' - : (in_array($displayNameMap[$key], ['Speed', 'RPM']) ? 'Offline' : $status), - 'status_color' => !$isActive ? 'gray' : $statusColor, - 'thresholds' => $thresholds, - 'limit' => $thresholdLimits - ]; + $transformedTelemetry[] = [ + 'display_name' => $displayNameMap[$key] ?? $key, + 'value' => $this->getTypeWiseValue($key, $value), + 'health_status' => !$isActive + ? 'Offline' + : (in_array($displayNameMap[$key], ['Speed', 'RPM']) ? 'Offline' : $status), + 'status_color' => !$isActive ? 'gray' : $statusColor, + 'thresholds' => $thresholds, + 'limit' => $thresholdLimits + ]; + } } } }