Detect missing shifts
This commit is contained in:
+10
-1
@@ -3,15 +3,22 @@ function getTemperatureStatus(targetDateString, previousDaysInCycle) {
|
||||
.filter(day => day.temperature)
|
||||
.map(day => !day.temperature.exclude && rounded(day.temperature.value, 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
|
||||
// after the shift has been detected, we count them as part
|
||||
// of the higher temperature phase
|
||||
if (acc.low.length < 6 || (!acc.shiftDetected && curr <= acc.ltl)) {
|
||||
if (acc.low.length < 7) {
|
||||
acc.low.push(curr)
|
||||
acc.ltl = Math.max(...acc.low.slice(-6))
|
||||
// TODO these are the same
|
||||
} else if (curr <= acc.ltl && !detectingPotentialHighLevel && !acc.shiftDetected) {
|
||||
acc.low.push(curr)
|
||||
acc.ltl = Math.max(...acc.low.slice(-6))
|
||||
} else {
|
||||
detectingPotentialHighLevel = true
|
||||
acc.high.push(curr)
|
||||
}
|
||||
|
||||
@@ -19,10 +26,12 @@ function getTemperatureStatus(targetDateString, previousDaysInCycle) {
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user