Developing api's for Cylinder specific & Peak pressure
This commit is contained in:
@@ -1320,6 +1320,31 @@ class TelemetryController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function getLiveDevice($deviceId){
|
||||
try {
|
||||
$deviceCount = $this->customerInfoService->getDevicesCount(["$deviceId"]);
|
||||
|
||||
if($deviceCount['activeDevices']){
|
||||
return response()->json(
|
||||
[
|
||||
'success' => true,
|
||||
'active' => true
|
||||
]
|
||||
);
|
||||
} else {
|
||||
return response()->json(
|
||||
[
|
||||
'success' => true,
|
||||
'active' => false
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
} catch(Exception $e){
|
||||
return response()->json(['success' => false, 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function getGlobalIndicators($deviceId){
|
||||
try{
|
||||
$token = readHeaderToken();
|
||||
@@ -1472,14 +1497,132 @@ class TelemetryController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function getCylinderSpecificIndicators(){
|
||||
public function getCylinderSpecificIndicators($deviceId) {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
|
||||
$device = Device::find($deviceId, ['device_profile_id', 'type']);
|
||||
$profileId = $device->device_profile_id;
|
||||
$isGasEngine = $device->type === 'Gas Engine Profile';
|
||||
|
||||
$cylindersToShow = ['Compression Condition','Injection Condition','Bearing Condition','Condition of Cyl Moving Parts'];
|
||||
if ($isGasEngine) {
|
||||
$cylindersToShow[] = 'Misfiring';
|
||||
}
|
||||
|
||||
$global = [
|
||||
0 => 'Compression_valueInPercent',
|
||||
1 => 'InjectionCondition_valueInPercent',
|
||||
2 => 'Bearing_valueInPercent',
|
||||
3 => 'BearingBis_valueInPercent',
|
||||
4 => 'Misfiring_valueInPercent'
|
||||
];
|
||||
|
||||
$firingOrderKeys = TimeseriesKeyMaster::where('display_firing_order', 1)
|
||||
->where('device_profile_xid', $profileId)
|
||||
->pluck('key_name')
|
||||
->toArray();
|
||||
|
||||
$firingOrderData = $this->customerInfoService->fetchTelemetryData($deviceId, implode(',', $firingOrderKeys));
|
||||
$data = [];
|
||||
|
||||
foreach ($cylindersToShow as $index => $title) {
|
||||
$cylinderKeys = TimeseriesKeyMaster::where('display_cylinder_specific', $index + 1)
|
||||
->where('device_profile_xid', $profileId)
|
||||
->pluck('key_name')
|
||||
->toArray();
|
||||
|
||||
$globalKey = $global[$index];
|
||||
$colorData = $this->customerInfoService->fetchTelemetryData($deviceId, implode(',', $cylinderKeys));
|
||||
$globalValue = $this->customerInfoService->fetchTelemetryData($deviceId, $globalKey);
|
||||
$globalValueColor = $globalValue[$global[$index]][0]['value'] > 70 ? 'green' : ($val > 30 ? 'orange' : 'red');
|
||||
|
||||
$response = [];
|
||||
$i = 1;
|
||||
foreach ($firingOrderData as $orderKey => $values) {
|
||||
$cylinderNum = $values[0]['value'] ?? 0;
|
||||
$name = 'Cyl' . $cylinderNum;
|
||||
|
||||
$prefixMap = [
|
||||
0 => 'Compression',
|
||||
1 => 'Injection',
|
||||
2 => 'Bearing',
|
||||
3 => 'InjectionCondition',
|
||||
4 => 'Misfiring'
|
||||
];
|
||||
|
||||
$prefix = $prefixMap[$index];
|
||||
$colorKey = "{$prefix}_cylinderHealth_" . $i++;
|
||||
|
||||
$val = $colorData[$colorKey][0]['value'] ?? null;
|
||||
|
||||
$color = is_null($val) ? 'grey' : ($val > 70 ? 'green' : ($val > 30 ? 'orange' : 'red'));
|
||||
|
||||
$response[] = [
|
||||
'name' => $name,
|
||||
'color' => $color,
|
||||
];
|
||||
}
|
||||
|
||||
$data[] = [
|
||||
'title' => $title,
|
||||
'global' => $globalValueColor,
|
||||
'data' => $response
|
||||
];
|
||||
}
|
||||
|
||||
return ['success' => true, 'data' => $data];
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPeakPressure($deviceId) {
|
||||
try {
|
||||
|
||||
$device = Device::find($deviceId, ['device_profile_id', 'type']);
|
||||
$profileId = $device->device_profile_id;
|
||||
$pressureValKey = 'Pressure_value';
|
||||
|
||||
$pressureVal = $this->customerInfoService->fetchTelemetryData($deviceId, $pressureValKey);
|
||||
if($pressureVal[$pressureValKey][0]['value'] == 0){
|
||||
return ['success' => false, 'message' => 'No data available'];
|
||||
}
|
||||
|
||||
$firingOrderKeys = TimeseriesKeyMaster::where('display_firing_order', 1)
|
||||
->where('device_profile_xid', $profileId)
|
||||
->pluck('key_name')
|
||||
->toArray();
|
||||
|
||||
$cylinderKeys = TimeseriesKeyMaster::where('display_cylinder_specific', 6)
|
||||
->where('device_profile_xid', $profileId)
|
||||
->pluck('key_name')
|
||||
->toArray();
|
||||
|
||||
$firingOrderData = $this->customerInfoService->fetchTelemetryData($deviceId, implode(',', $firingOrderKeys));
|
||||
$valData = $this->customerInfoService->fetchTelemetryData($deviceId, implode(',', $cylinderKeys));
|
||||
|
||||
$i = 1;
|
||||
foreach ($firingOrderData as $orderKey => $values) {
|
||||
$cylinderNum = $values[0]['value'] ?? 0;
|
||||
$name = 'Cyl' . $cylinderNum;
|
||||
|
||||
$valKey = "Pressure_cylinderHealth_" . $i++;
|
||||
|
||||
$val = $valData[$valKey][0]['value'] ?? null;
|
||||
|
||||
$response[] = [
|
||||
'name' => $name,
|
||||
'value' => $val,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch(Exception $e){
|
||||
return response()->json(['success' => false, 'message' => $e->getMessage()], 500);
|
||||
return ['success' => true, 'data' => $response];
|
||||
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,10 @@ Route::middleware(['customerApiBasicAuth'])->group(function () {
|
||||
Route::get('/user-assets', [TelemetryController::class, 'userAssetsNew']);
|
||||
Route::get('/customer-device-info', [TelemetryController::class, 'customerDeviceInfoNew']);
|
||||
Route::get('/get-device-indicators/{assetId}', [TelemetryController::class, 'getDeviceIndicators']);
|
||||
Route::get('/get-live-device/{deviceId}', [TelemetryController::class, 'getLiveDevice']);
|
||||
Route::get('/get-alerts/{deviceId}', [TelemetryController::class, 'getAlerts']);
|
||||
Route::get('/get-global-indicators/{deviceId}', [TelemetryController::class, 'getGlobalIndicators']);
|
||||
Route::get('/get-trends/{deviceId}', [TelemetryController::class, 'getTrends']);
|
||||
Route::get('/get-cylinder-specific-indicators/{deviceId}', [TelemetryController::class, 'getCylinderSpecificIndicators']);
|
||||
Route::get('/get-peak-pressure/{deviceId}', [TelemetryController::class, 'getPeakPressure']);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user