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

Add 1st exception rule

parent 3a090c5d
No related branches found
No related tags found
No related merge requests found
...@@ -15,10 +15,15 @@ function getTemperatureStatus(targetDateString, previousDaysInCycle) { ...@@ -15,10 +15,15 @@ function getTemperatureStatus(targetDateString, previousDaysInCycle) {
acc.high.push(curr) acc.high.push(curr)
} }
// regular rule
// we round the difference because of JS decimal weirdness // we round the difference because of JS decimal weirdness
if (acc.high.length === 3 && rounded(curr - acc.ltl, 0.01) >= 0.2) { if (acc.high.length === 3 && rounded(curr - acc.ltl, 0.01) >= 0.2) {
acc.shiftDetected = true acc.shiftDetected = true
} }
// 1st exception rule
if (acc.high.length === 4 && curr > acc.ltl) {
acc.shiftDetected = true
}
return acc 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.63,
"exclude": null
}
}]
\ No newline at end of file
File moved
import chai from 'chai' import chai from 'chai'
import { getTemperatureStatus } from '../lib/sensiplan' import { getTemperatureStatus } from '../lib/sensiplan'
import tempShift from './fixtures/temp-shift.json' import tempShift from './fixtures/regular-rule.json'
import lowerTempDays from './fixtures/lower-temps.json' import lowerTempDays from './fixtures/lower-temps.json'
import firstException from './fixtures/first-exception-rule.json'
const expect = chai.expect const expect = chai.expect
...@@ -17,7 +18,7 @@ describe.only('sensiplan', () => { ...@@ -17,7 +18,7 @@ describe.only('sensiplan', () => {
}) })
}) })
it('detects temperature shift', function () { it('detects temperature shift according to regular rule', function () {
const status = getTemperatureStatus('2018-06-14', tempShift) const status = getTemperatureStatus('2018-06-14', tempShift)
expect(status).to.eql({ expect(status).to.eql({
low: [36.7, 36.55, 36.45, 36.5, 36.55, 36.6, 36.55], low: [36.7, 36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
...@@ -26,5 +27,15 @@ describe.only('sensiplan', () => { ...@@ -26,5 +27,15 @@ describe.only('sensiplan', () => {
shiftDetected: true shiftDetected: true
}) })
}) })
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
})
})
}) })
}) })
\ No newline at end of file
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