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

Return evaluation completed day from mucus eval

parent 9102bce7
No related branches found
No related tags found
No related merge requests found
...@@ -2,31 +2,37 @@ export default function (cycleDays, tempEvalEndIndex) { ...@@ -2,31 +2,37 @@ export default function (cycleDays, tempEvalEndIndex) {
const mucusDays = cycleDays.filter(day => day.mucus && !day.mucus.exclude) const mucusDays = cycleDays.filter(day => day.mucus && !day.mucus.exclude)
const bestQuality = Math.max(...mucusDays.map(day => day.mucus.value)) const bestQuality = Math.max(...mucusDays.map(day => day.mucus.value))
const mucusPeak = cycleDays.find((day, i) => { for (let i = 0; i < mucusDays.length; i++) {
if (!mucusDays.includes(day) || day.mucus.value !== bestQuality) return false const day = mucusDays[i]
if (day.mucus.value !== bestQuality) continue
// sensiplan says the three following days must be of lower quality // sensiplan says the three following days must be of lower quality
// AND no best quality day may occur until temperature evaluation has // AND no best quality day may occur until temperature evaluation has
// been completed // been completed
const mucusDaysIndex = mucusDays.indexOf(day) const threeFollowingDays = mucusDays.slice(i + 1, i + 4)
const threeFollowingDays = mucusDays.slice(mucusDaysIndex + 1, mucusDaysIndex + 4) if (threeFollowingDays.length < 3) continue
if (threeFollowingDays.length < 3) return false
const bestQualityOccurringIn3FollowingDays = threeFollowingDays.some(day => day.mucus.value >= bestQuality) const bestQualityOccurringIn3FollowingDays = threeFollowingDays.some(day => day.mucus.value >= bestQuality)
if (bestQualityOccurringIn3FollowingDays) return false if (bestQualityOccurringIn3FollowingDays) continue
// FIXME mucus peak can be same day as first higher measurement
const cycleDayIndex = cycleDays.indexOf(day)
const relevantDays = cycleDays const relevantDays = cycleDays
.slice(i + 1, tempEvalEndIndex + 1) .slice(cycleDayIndex + 1, tempEvalEndIndex + 1)
.filter(day => day.mucus && !day.mucus.exclude) .filter(day => day.mucus && !day.mucus.exclude)
return relevantDays.every(day => day.mucus.value < bestQuality) const evaluationCompleteDay = relevantDays.length > 3 ?
}) relevantDays[relevantDays.length - 1] : threeFollowingDays[threeFollowingDays.length - 1]
if (!mucusPeak) return { detected: false } if (relevantDays.every(day => day.mucus.value < bestQuality)) {
return {
return { detected: true,
detected: true, mucusPeak: day,
mucusPeak evaluationCompleteDay
}
}
} }
return { detected: false }
} }
...@@ -16,12 +16,16 @@ describe('sympto', () => { ...@@ -16,12 +16,16 @@ describe('sympto', () => {
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, 30) const status = getMucusStatus(values, 12)
expect(status).to.eql({ expect(status).to.eql({
detected: true, detected: true,
mucusPeak: { mucusPeak: {
date: 10, date: 10,
mucus: { value: 3 } mucus: { value: 3 }
},
evaluationCompleteDay: {
date: 13,
mucus: { value: 0 }
} }
}) })
}) })
......
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