-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmucus.js
56 lines (44 loc) · 1.59 KB
/
mucus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
module.exports = function (cycleDays, tempEvalEndIndex) {
const notDetected = { detected: false }
const mucusDays = cycleDays.filter(day => typeof day.mucus === 'number')
let currentBestQuality = 0
for (let i = 0; i < mucusDays.length; i++) {
let print
if (i === 13) {
print = true
} else {
print === false
}
const day = mucusDays[i]
if (day.mucus > currentBestQuality) {
currentBestQuality = day.mucus
}
// if mucus only changes from dry to nothing, it doesn't constitute a shift
if (currentBestQuality < 2) continue
if (day.mucus !== currentBestQuality) continue
// the three following days must be of lower quality
const threeFollowingDays = mucusDays.slice(i + 1, i + 4)
if (threeFollowingDays.length < 3) continue
const bestQualityOccursIn3FollowingDays = threeFollowingDays.some(day => {
return day.mucus >= currentBestQuality
})
if (bestQualityOccursIn3FollowingDays) continue
const cycleDayIndex = cycleDays.indexOf(day)
// no best quality day may occur until temperature evaluation has
// been completed
const relevantDays = cycleDays
.slice(cycleDayIndex + 1, tempEvalEndIndex + 1)
.filter(day => typeof day.mucus === 'number')
const noBestQualityUntilEndOfTempEval = relevantDays.every(day => {
return day.mucus < currentBestQuality
})
if (noBestQualityUntilEndOfTempEval) {
return {
detected: true,
mucusPeak: day,
evaluationCompleteDay: threeFollowingDays[threeFollowingDays.length - 1]
}
}
}
return notDetected
}