Detect missing shifts

This commit is contained in:
Julia Friesel
2018-06-30 16:01:12 +02:00
parent 9e92f072de
commit e1f473de3b
5 changed files with 187 additions and 24 deletions
+10 -1
View File
@@ -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