Return potential high temps as well
This commit is contained in:
+24
-19
@@ -2,8 +2,6 @@ function detectTemperatureShift(temperaturesOfCycle) {
|
||||
// sensiplan rounds temps to the nearest 0.05
|
||||
const tempValues = temperaturesOfCycle.map(val => rounded(val, 0.05))
|
||||
|
||||
let detectingPotentialHighLevel = false
|
||||
|
||||
return tempValues.reduce((acc, curr) => {
|
||||
// if we don't yet have 6 lower temps, we just collect
|
||||
// if no shift has been detected, we collect low temps
|
||||
@@ -11,32 +9,23 @@ function detectTemperatureShift(temperaturesOfCycle) {
|
||||
// of the higher temperature phase
|
||||
if (acc.low.length < 6) {
|
||||
acc.low.push(curr)
|
||||
acc.ltl = Math.max(...acc.low.slice(-6))
|
||||
acc.ltl = Math.max(...acc.low)
|
||||
// TODO these are the same
|
||||
} else if (curr <= acc.ltl && !detectingPotentialHighLevel && !acc.shiftDetected) {
|
||||
} else if (curr <= acc.ltl && !acc.potentialHigh && !acc.shiftDetected) {
|
||||
acc.low.push(curr)
|
||||
acc.ltl = Math.max(...acc.low.slice(-6))
|
||||
acc.low.shift(curr)
|
||||
acc.ltl = Math.max(...acc.low)
|
||||
} else if (!acc.shiftDetected){
|
||||
if (!acc.potentialHigh) acc.potentialHigh = []
|
||||
acc.potentialHigh.push(curr)
|
||||
checkRules(acc, curr)
|
||||
} else {
|
||||
detectingPotentialHighLevel = true
|
||||
acc.high.push(curr)
|
||||
}
|
||||
|
||||
// regular rule
|
||||
// we round the difference because of JS decimal weirdness
|
||||
if (acc.high.length === 3 && rounded(curr - acc.ltl, 0.01) >= 0.2) {
|
||||
acc.shiftDetected = true
|
||||
detectingPotentialHighLevel = false
|
||||
}
|
||||
// 1st exception rule
|
||||
if (acc.high.length === 4 && curr > acc.ltl) {
|
||||
acc.shiftDetected = true
|
||||
detectingPotentialHighLevel = false
|
||||
}
|
||||
|
||||
return acc
|
||||
}, {
|
||||
low: [],
|
||||
high: [],
|
||||
ltl: null,
|
||||
shiftDetected: false
|
||||
})
|
||||
@@ -47,6 +36,22 @@ function rounded(val, step) {
|
||||
return Math.round(val * inverted) / inverted
|
||||
}
|
||||
|
||||
function checkRules(acc, curr) {
|
||||
function regularRuleApplies() {
|
||||
// we round the difference because of JS decimal weirdness
|
||||
return acc.potentialHigh.length === 3 && rounded(curr - acc.ltl, 0.01) >= 0.2
|
||||
}
|
||||
function firstExceptionRuleApplies() {
|
||||
return acc.potentialHigh.length === 4 && curr > acc.ltl
|
||||
}
|
||||
|
||||
if (regularRuleApplies() || firstExceptionRuleApplies()) {
|
||||
acc.shiftDetected = true
|
||||
acc.high = acc.potentialHigh
|
||||
delete acc.potentialHigh
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
detectTemperatureShift
|
||||
}
|
||||
Reference in New Issue
Block a user