Ignore 0 -> 1 mucus shift

This commit is contained in:
Julia Friesel
2018-08-01 16:21:50 +02:00
parent 6ac642b91c
commit 8bbf122d12
2 changed files with 34 additions and 3 deletions
+5 -1
View File
@@ -1,4 +1,5 @@
export default function (cycleDays, tempEvalEndIndex) { export default function (cycleDays, tempEvalEndIndex) {
const notDetected = { detected: false}
const mucusDays = cycleDays.filter(day => day.mucus && !day.mucus.exclude) const mucusDays = cycleDays.filter(day => day.mucus && !day.mucus.exclude)
let currentBestQuality = 0 let currentBestQuality = 0
@@ -9,6 +10,9 @@ export default function (cycleDays, tempEvalEndIndex) {
currentBestQuality = day.mucus.value currentBestQuality = day.mucus.value
} }
// if mucus only changes from dry to nothing, it doesn't constitute a shift
if (currentBestQuality < 2) continue
if (day.mucus.value !== currentBestQuality) continue if (day.mucus.value !== currentBestQuality) continue
// the three following days must be of lower quality // the three following days must be of lower quality
@@ -40,6 +44,6 @@ export default function (cycleDays, tempEvalEndIndex) {
} }
} }
return { detected: false } return notDetected
} }
+29 -2
View File
@@ -14,7 +14,7 @@ describe('sympto', () => {
describe('detect mucus shift', () => { describe('detect mucus shift', () => {
describe('regular rule', () => { describe('regular rule', () => {
it('detects mucus shift correctly', function () { it('detects mucus shift correctly', function () {
const values = [0, 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 2, 2, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0] const values = [0,0,0,1,1,2,2,2,3,3,3,2,2,0,1,1,1,1,0,0,0,0,0]
.map(turnIntoCycleDayObject) .map(turnIntoCycleDayObject)
const status = getMucusStatus(values, 12) const status = getMucusStatus(values, 12)
expect(status).to.eql({ expect(status).to.eql({
@@ -38,7 +38,10 @@ describe('sympto', () => {
}) })
it('detects no mucus shift when there are no mucus values', function () { it('detects no mucus shift when there are no mucus values', function () {
const status = getMucusStatus(Array(10).fill({date: 1, temperature: { value: 35}})) const status = getMucusStatus(Array(10).fill({
date: 1,
temperature: { value: 35 }
}))
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
@@ -48,6 +51,30 @@ describe('sympto', () => {
const status = getMucusStatus(values, 30) const status = getMucusStatus(values, 30)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
it('detects no mucus shift when mucus only changes from dry to nothing', function () {
const values = [0,0,0,1,0,0,0,0,0,0,0]
.map(turnIntoCycleDayObject)
const status = getMucusStatus(values, 30)
expect(status).to.eql({ detected: false })
})
it('ignores an early seeming shift from 0 to 1', function () {
const values = [0,0,0,1,0,0,0,2,3,3,3,2,2,0,1,1,1,1,0,0,0,0,0]
.map(turnIntoCycleDayObject)
const status = getMucusStatus(values, 12)
expect(status).to.eql({
detected: true,
mucusPeak: {
date: 10,
mucus: { value: 3 }
},
evaluationCompleteDay: {
date: 13,
mucus: { value: 0 }
}
})
})
}) })
}) })
}) })