-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nikiwycherley
committed
Oct 10, 2023
1 parent
e5d255b
commit af29cc0
Showing
9 changed files
with
437 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function getMinFromType (arr, type) { | ||
const filtered = arr.filter(item => item.threshold_type === type) | ||
if (filtered.length) { | ||
return filtered.reduce((min, curr) => parseFloat(curr.value) < parseFloat(min.value) ? curr : min) | ||
} | ||
return null | ||
} | ||
|
||
function findMinValueByLogic (arr, type) { | ||
if (type === 'A') { | ||
// Logic for Type A | ||
return getMinFromType(arr, 'FW RES FAL') || | ||
getMinFromType(arr, 'FW ACT FAL') || | ||
getMinFromType(arr, 'FW ATCON FAL') | ||
} else if (type === 'W') { | ||
// Logic for Type W | ||
return getMinFromType(arr, 'FW RES FW') || | ||
getMinFromType(arr, 'FW ACT FW') || | ||
getMinFromType(arr, 'FW ATCON FW') | ||
} | ||
return null | ||
} | ||
|
||
function filterImtdThresholds (imtdThresholds) { | ||
const typeA = imtdThresholds.filter(item => item.fwis_type === 'A') | ||
const typeW = imtdThresholds.filter(item => item.fwis_type === 'W') | ||
|
||
const minObjectA = findMinValueByLogic(typeA, 'A') | ||
const minObjectW = findMinValueByLogic(typeW, 'W') | ||
|
||
return { | ||
alert: minObjectA ? minObjectA.value : null, | ||
warning: minObjectW ? minObjectW.value : null | ||
} | ||
} | ||
|
||
module.exports = filterImtdThresholds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.