Implement second exception rule

This commit is contained in:
Julia Friesel
2018-07-02 13:37:11 +02:00
parent 8db92e96f3
commit 03a0f1fb75
2 changed files with 87 additions and 1 deletions
+31 -1
View File
@@ -42,6 +42,7 @@ function detectTemperatureShift(temperaturesOfCycle) {
}
function rounded(val, step) {
// we round the difference because of JS decimal weirdness
const inverted = 1 / step
return Math.round(val * inverted) / inverted
}
@@ -73,6 +74,16 @@ function checkIfFirstHighMeasurement(temp, i, temps, ltl) {
}
}
if (secondExceptionRuleApplies(temp, nextTemps, ltl)) {
return {
isFirstHighMeasurement: true,
rules: {
secondException: true,
},
ltl
}
}
return {
isFirstHighMeasurement: false
}
@@ -81,18 +92,37 @@ function checkIfFirstHighMeasurement(temp, i, temps, ltl) {
function regularRuleApplies(temp, nextTemps, ltl) {
if (!nextTemps.every(temp => temp > ltl)) return false
const thirdTemp = nextTemps[1]
// we round the difference because of JS decimal weirdness
if (rounded(thirdTemp - ltl, 0.1) < 0.2) return false
return true
}
function firstExceptionRuleApplies(temp, nextTemps, ltl) {
if (nextTemps.length < 3) return false
if (!nextTemps.every(temp => temp > ltl)) return false
const fourthTemp = nextTemps[2]
if (fourthTemp > ltl) return true
return false
}
function secondExceptionRuleApplies(temp, nextTemps, ltl) {
if (nextTemps.length < 3) return false
if (secondOrThirdTempIsAtOrBelowLtl(nextTemps, ltl)) {
const fourthTemp = nextTemps[2]
if (rounded(fourthTemp - ltl, 0.1) >= 0.2) return true
}
return false
}
function secondOrThirdTempIsAtOrBelowLtl(nextTemps, ltl) {
const secondIsLow = nextTemps[0] <= ltl
const thirdIsLow = nextTemps[1] <= ltl
if ((secondIsLow || thirdIsLow) && !(secondIsLow && thirdIsLow)) {
return true
} else {
return false
}
}
export {
detectTemperatureShift
}