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

Add mucus shift detection

parent e4bae38d
No related branches found
No related tags found
No related merge requests found
......@@ -4,4 +4,9 @@ import getMucusStatus from './mucus'
export default function (cycleDays) {
const temperatureStatus = getTemperatureStatus(cycleDays)
const mucusStatus = getMucusStatus(cycleDays)
return {
assumeFertility: true,
temperatureStatus,
mucusStatus
}
}
\ No newline at end of file
export default function (cycleDays) {
const mucusDays = cycleDays.filter(day => day.mucus && !day.mucus.exclude)
const bestQuality = Math.max(...mucusDays.map(day => day.mucus.value))
const mucusPeak = mucusDays.find((day, i) => {
if (day.mucus.value !== bestQuality) return false
const threeFollowingDays = cycleDays.slice(i + 1, i + 4)
if (threeFollowingDays.length < 3) return false
return threeFollowingDays.every(day => day.mucus.value < bestQuality)
})
if (!mucusPeak) return { detected: false }
return {
detected: true,
mucusPeak
}
}
import chai from 'chai'
import getMucusStatus from '../../lib/sympto/mucus'
const expect = chai.expect
function turnIntoCycleDayObject(value, fakeDate) {
return {
mucus : { value },
date: fakeDate
}
}
describe('sympto', () => {
describe('detect mucus shift', () => {
describe('regular rule', () => {
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]
.map(turnIntoCycleDayObject)
const status = getMucusStatus(values)
expect(status).to.eql({
detected: true,
mucusPeak: {
date: 10,
mucus: { value: 3 }
}
})
})
it('detects no mucus shift when there are less than 3 days of lower quality', function () {
const values = [0, 1, 1, 2, 0, 0, 1, 2, 3, 2, 3, 3, 3, 2, 2]
.map(turnIntoCycleDayObject)
const status = getMucusStatus(values)
expect(status).to.eql({ detected: false })
})
it('detects no mucus shift when there are no mucus values', function () {
const status = getMucusStatus(Array(10).fill({date: 1, temperature: { value: 35}}))
expect(status).to.eql({ detected: false })
})
it('detects no mucus shift when the mucus values are all the same', function () {
const values = [2, 2, 2, 2, 2, 2, 2, 2]
.map(turnIntoCycleDayObject)
const status = getMucusStatus(values)
expect(status).to.eql({ detected: false })
})
})
})
})
\ 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