Combine temp and mucus evaluation
This commit is contained in:
+18
-5
@@ -1,13 +1,25 @@
|
||||
export default function (cycleDays) {
|
||||
export default function (cycleDays, tempEvalEndIndex) {
|
||||
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 = mucusDays.slice(i + 1, i + 4)
|
||||
const mucusPeak = cycleDays.find((day, i) => {
|
||||
if (!mucusDays.includes(day) || day.mucus.value !== bestQuality) return false
|
||||
|
||||
// sensiplan says the three following days must be of lower quality
|
||||
// AND no best quality day may occur until temperature evaluation has
|
||||
// been completed
|
||||
const mucusDaysIndex = mucusDays.indexOf(day)
|
||||
const threeFollowingDays = mucusDays.slice(mucusDaysIndex + 1, mucusDaysIndex + 4)
|
||||
if (threeFollowingDays.length < 3) return false
|
||||
|
||||
return threeFollowingDays.every(day => day.mucus.value < bestQuality)
|
||||
const bestQualityOccurringIn3FollowingDays = threeFollowingDays.some(day => day.mucus.value >= bestQuality)
|
||||
if (bestQualityOccurringIn3FollowingDays) return false
|
||||
|
||||
const relevantDays = cycleDays
|
||||
.slice(i + 1, tempEvalEndIndex + 1)
|
||||
.filter(day => day.mucus && !day.mucus.exclude)
|
||||
|
||||
return relevantDays.every(day => day.mucus.value < bestQuality)
|
||||
})
|
||||
|
||||
if (!mucusPeak) return { detected: false }
|
||||
@@ -17,3 +29,4 @@ export default function (cycleDays) {
|
||||
mucusPeak
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user