-
-
Save izonder/fcbeb42badef6f58a9c1a1f57dff970d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const sparseMap = { | |
'O2': { | |
'ExposureAlarm': { | |
read: () => _.random(9, 19), | |
isExposureAlarm: () => true | |
}, | |
'ExposureWarning': { | |
read: () => _.random(24, 27), | |
isExposureWarning: () => true | |
} | |
}, | |
'COMB': { | |
'ExposureAlarm': { | |
read: () => _.random(21, 24), | |
isExposureAlarm: () => true | |
}, | |
'ExposureWarning': { | |
read: () => _.random(14, 18), | |
isExposureWarning: () => true | |
} | |
}, | |
'H2S': { | |
'ExposureAlarm': { | |
read: () => _.random(15, 20), | |
isExposureAlarm: () => true | |
}, | |
'ExposureWarning': { | |
read: () => _.random(12, 15), | |
isExposureWarning: () => true | |
} | |
} | |
}, | |
sparseMapProbe = (gasName, alarmType) => (sparseMap[gasName] || {})[alarmType] || {read: () => 0}, | |
findByName = (statusConfig, gasName) => statusConfig.sensStatus.find((x) => x.name === gasName); | |
function Handler(statusConfig, gasName, alarmType) { | |
const probe = sparseMapProbe(gasName, alarmType), | |
ref = findByName(statusConfig, gasName) || {}; //TODO: make sure the object exists; | |
Object.keys(probe).forEach((key) => ref[key] = probe[key]()); | |
return statusConfig; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment