Skip to content
Snippets Groups Projects
Commit e1f473de authored by Julia Friesel's avatar Julia Friesel
Browse files

Detect missing shifts

parent 9e92f072
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
[{
"date": "2018-06-04",
"temperature": {
"value": 36.7,
"exclude": null
}
}, {
"date": "2018-06-05",
"temperature": {
"value": 36.57,
"exclude": null
}
}, {
"date": "2018-06-06",
"temperature": {
"value": 36.47,
"exclude": null
}
}, {
"date": "2018-06-07",
"temperature": {
"value": 36.49,
"exclude": null
}
}, {
"date": "2018-06-09",
"temperature": {
"value": 36.57,
"exclude": null
}
}, {
"date": "2018-06-10",
"temperature": {
"value": 36.62,
"exclude": null
}
}, {
"date": "2018-06-11",
"temperature": {
"value": 36.55,
"exclude": null
}
}, {
"date": "2018-06-12",
"temperature": {
"value": 36.8,
"exclude": null
}
}, {
"date": "2018-06-13",
"temperature": {
"value": 36.86,
"exclude": null
}
}, {
"date": "2018-06-14",
"temperature": {
"value": 36.77,
"exclude": null
}
}, {
"date": "2018-06-15",
"temperature": {
"value": 36.57,
"exclude": null
}
}]
\ No newline at end of file
[{
"date": "2018-06-04",
"temperature": {
"value": 36.7,
"exclude": null
}
}, {
"date": "2018-06-05",
"temperature": {
"value": 36.57,
"exclude": null
}
}, {
"date": "2018-06-06",
"temperature": {
"value": 36.47,
"exclude": null
}
}, {
"date": "2018-06-07",
"temperature": {
"value": 36.49,
"exclude": null
}
}, {
"date": "2018-06-09",
"temperature": {
"value": 36.57,
"exclude": null
}
}, {
"date": "2018-06-10",
"temperature": {
"value": 36.62,
"exclude": null
}
}, {
"date": "2018-06-11",
"temperature": {
"value": 36.55,
"exclude": null
}
}, {
"date": "2018-06-12",
"temperature": {
"value": 36.8,
"exclude": null
}
}, {
"date": "2018-06-13",
"temperature": {
"value": 36.86,
"exclude": null
}
}, {
"date": "2018-06-14",
"temperature": {
"value": 36.77,
"exclude": null
}
}]
\ No newline at end of file
import chai from 'chai'
import { getTemperatureStatus } from '../lib/sensiplan'
import tempShift from './fixtures/regular-rule.json'
import tempShift from './fixtures/regular-rule-shift.json'
import noTempShift from './fixtures/regular-rule-no-shift.json'
import lowerTempDays from './fixtures/lower-temps.json'
import firstException from './fixtures/first-exception-rule.json'
import firstExceptionNoShift from './fixtures/first-exception-rule-no-shift.json'
const expect = chai.expect
describe.only('sensiplan', () => {
describe('getTemperatureStatus', () => {
it('reports lower temperature status before shift', function () {
const status = getTemperatureStatus('2018-06-09', lowerTempDays)
expect(status).to.eql({
low: [36.7, 36.55, 36.45, 36.5, 36.55],
ltl: 36.7,
high: [],
shiftDetected: false
describe('regular rule', () => {
it('reports lower temperature status before shift', function () {
const status = getTemperatureStatus('2018-06-09', lowerTempDays)
expect(status).to.eql({
low: [36.7, 36.55, 36.45, 36.5, 36.55],
ltl: 36.7,
high: [],
shiftDetected: false
})
})
it('detects temperature shift correctly', function () {
const status = getTemperatureStatus('2018-06-14', tempShift)
expect(status).to.eql({
low: [36.7, 36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
ltl: 36.6,
high: [36.8, 36.85, 36.8],
shiftDetected: true
})
})
})
it('detects temperature shift according to regular rule', function () {
const status = getTemperatureStatus('2018-06-14', tempShift)
expect(status).to.eql({
low: [36.7, 36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
ltl: 36.6,
high: [36.8, 36.85, 36.8],
shiftDetected: true
it('detects missing temperature shift correctly', function () {
const status = getTemperatureStatus('2018-06-14', noTempShift)
expect(status).to.eql({
low: [36.7, 36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
ltl: 36.6,
high: [36.8, 36.85, 36.75],
shiftDetected: false
})
})
})
it('detects temperature shift according to 1st exception rule', function () {
const status = getTemperatureStatus('2018-06-14', firstException)
expect(status).to.eql({
low: [36.7, 36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
ltl: 36.6,
high: [36.8, 36.85, 36.75, 36.65],
shiftDetected: true
describe('1st exception rule', () => {
it('detects temperature shift', function () {
const status = getTemperatureStatus('2018-06-14', firstException)
expect(status).to.eql({
low: [36.7, 36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
ltl: 36.6,
high: [36.8, 36.85, 36.75, 36.65],
shiftDetected: true
})
})
it('detects missing temperature shift correctly', function () {
const status = getTemperatureStatus('2018-06-14', firstExceptionNoShift)
expect(status).to.eql({
low: [36.7, 36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
ltl: 36.6,
high: [36.8, 36.85, 36.75, 36.55],
shiftDetected: false
})
})
})
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment