CM69 - Bugfix graph cartest, CMXX - Healthindex update
This commit is contained in:
@@ -2591,47 +2591,16 @@ function storeMeasurementEquipment($serialnumber){
|
||||
}
|
||||
}
|
||||
//STORE RESULTS IN EQUIPMENT DATA
|
||||
foreach ($equipment_watchlist as $equipment => $data){
|
||||
foreach ($equipment_watchlist as $equipment => $data){
|
||||
|
||||
//GET the equipmentid and historyid from watchlist
|
||||
if (str_contains($equipment,'||')){
|
||||
$identification = explode('||',$equipment);
|
||||
//json_encode array
|
||||
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//Calculate healthindex
|
||||
$healthindex = 100;
|
||||
|
||||
//Check if record exists
|
||||
$sql = 'SELECT * FROM equipment_data WHERE equipmentid = ? and historyid =?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$identification[2],$identification[3]]);
|
||||
$equipment_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!empty($equipment_data)){
|
||||
//EXIST UPDATE
|
||||
$sql = 'UPDATE equipment_data SET measurement = ? WHERE equipmentid = ? and historyid =?';
|
||||
}
|
||||
else {
|
||||
//EXIST INSERT
|
||||
$sql = 'INSERT INTO equipment_data (measurement, equipmentid, historyid) VALUES (?,?,?)';
|
||||
}
|
||||
|
||||
//EXECUTE QUERY
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$data, $identification[2],$identification[3]]);
|
||||
$equipment_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// calculatehealthindex of asset ++++++++++
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function assetHealthIndex($prof,$pem,$healthdata){
|
||||
$healthindex = 100;
|
||||
//Allowed check
|
||||
if (isAllowed('equipment_data',$prof,$pem,'R') === 1 && !empty($healthdata)){
|
||||
//GET last data
|
||||
$last_data_measurement = end($healthdata);
|
||||
foreach (json_decode($last_data_measurement->measurement,true) as $data_measure){
|
||||
|
||||
foreach ($data as $data_measure){
|
||||
switch ($data_measure['deviation']) {
|
||||
case 1:
|
||||
$healthindex = $healthindex - $data_measure['deviation'];
|
||||
@@ -2643,7 +2612,72 @@ function assetHealthIndex($prof,$pem,$healthdata){
|
||||
$healthindex = $healthindex - ($data_measure['deviation']*3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//json_encode array
|
||||
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//Check if record exists
|
||||
$sql = 'SELECT * FROM equipment_data WHERE equipmentid = ? and historyid =?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$identification[2],$identification[3]]);
|
||||
$equipment_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!empty($equipment_data)){
|
||||
//EXIST UPDATE
|
||||
$sql = 'UPDATE equipment_data SET measurement = ?, healthindex = ? WHERE equipmentid = ? and historyid = ?';
|
||||
}
|
||||
else {
|
||||
//EXIST INSERT
|
||||
$sql = 'INSERT INTO equipment_data (measurement, , healthindex, equipmentid, historyid) VALUES (?,?,?,?)';
|
||||
}
|
||||
|
||||
//EXECUTE QUERY
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$data, $healthindex, $identification[2],$identification[3]]);
|
||||
$equipment_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// calculatehealthindex of asset ++++++++++
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function assetHealthIndex($prof,$pem,$healthdata,$type){
|
||||
|
||||
$healthindex = 100;
|
||||
//Allowed check
|
||||
if (isAllowed('equipment_data',$prof,$pem,'R') === 1 && !empty($healthdata)){
|
||||
|
||||
//GET last data based on type returned
|
||||
//Type
|
||||
// 0 = $healthdata per equipmentid
|
||||
// 1 = $healthdata per rowID of equipment_data
|
||||
switch ($type) {
|
||||
case 0:
|
||||
$last_data_measurement = end($healthdata);
|
||||
break;
|
||||
default:
|
||||
$last_data_measurement = $healthdata;
|
||||
|
||||
break;
|
||||
}
|
||||
//Ensure $last_data_measurement is an array
|
||||
$last_data_measurement = (is_object($last_data_measurement))? (array) $last_data_measurement : $last_data_measurement;
|
||||
|
||||
foreach (json_decode($last_data_measurement['measurement'],true) as $data_measure){
|
||||
|
||||
switch ($data_measure['deviation']) {
|
||||
case 1:
|
||||
$healthindex = $healthindex - $data_measure['deviation'];
|
||||
break;
|
||||
case 2:
|
||||
$healthindex = $healthindex - ($data_measure['deviation']*2);
|
||||
break;
|
||||
case 3:
|
||||
$healthindex = $healthindex - ($data_measure['deviation']*3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//Not allowed or no data return 100% health
|
||||
|
||||
Reference in New Issue
Block a user