From 5b4eeff6d48e7633252a2d441c5e473be9dce103 Mon Sep 17 00:00:00 2001 From: Nikhil Kadam Date: Fri, 2 May 2025 19:31:02 +0530 Subject: [PATCH] Error handling --- .../APIS/CustomerApi/TelemetryController.php | 26 +++++++++++++---- ..._02_132531_add_sensor_to_devices_table.php | 28 +++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 database/migrations/2025_05_02_132531_add_sensor_to_devices_table.php diff --git a/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php b/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php index 71a6297..0d9e02c 100644 --- a/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php +++ b/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php @@ -1007,7 +1007,7 @@ class TelemetryController extends Controller return [ 'assetName' => $asset->name, - 'assetHealth' => $this->getAssetHealth($deviceHealthStatuses), + 'assetHealth' => $deviceHealthStatuses ? $this->getAssetHealth($deviceHealthStatuses) : null, 'devices' => $devicesData ]; @@ -1126,19 +1126,33 @@ class TelemetryController extends Controller foreach ($data as $key => $items) { foreach ($items as $item) { + + $ts['startTs'] = Carbon::now()->subHours(6)->timestamp * 1000; + $ts['endTs'] = Carbon::now()->timestamp * 1000; + $pastValues = $this->customerInfoService->fetchTelemetryData($device->id, $key, $ts); + $pastValTotal = 1; + // $itemTotal + foreach($pastValues as $past){ + // $pastValTotal + } + + // echo "$i -".count($pastValues)."\n"; $transformedTelemetry[] = [ 'display_name' => $displayNameMap[$key] ?? $key, - 'value' => $item['value'] + 'value' => $item['value'], + 'pastValue' => $pastValues ? $pastValues[$key] : [] ]; } + // exit; } } return [ - 'deviceId' => $device->id, - 'deviceName' => $device->name, - 'deviceType' => $deviceProfileName, - 'indicator' => $transformedTelemetry + 'deviceId' => $device->id, + 'deviceName' => $device->name, + 'deviceType' => $deviceProfileName, + 'deviceSensor' => $device->sensor, + 'indicator' => $transformedTelemetry ]; })->values(); diff --git a/database/migrations/2025_05_02_132531_add_sensor_to_devices_table.php b/database/migrations/2025_05_02_132531_add_sensor_to_devices_table.php new file mode 100644 index 0000000..bf19094 --- /dev/null +++ b/database/migrations/2025_05_02_132531_add_sensor_to_devices_table.php @@ -0,0 +1,28 @@ +string('sensor')->after('type')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('devices', function (Blueprint $table) { + $table->dropColumn('sensor'); + }); + } +};