Implement second exception rule
This commit is contained in:
+31
-1
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user