Merge branch 'master'
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
export default function (cycleDays, tempEvalEndIndex) {
|
||||
const cervixDays = cycleDays.filter(day => day.cervix && !day.cervix.exclude)
|
||||
|
||||
for (let i = 0; i < cervixDays.length; i++) {
|
||||
const day = cervixDays[i]
|
||||
if (isClosedAndHard(day.cervix)) continue
|
||||
// the three following days must be with closed and hard cervix
|
||||
// AND no other cervix value may occur until temperature evaluation has
|
||||
// been completed
|
||||
const threeFollowingDays = cervixDays.slice(i + 1, i + 4)
|
||||
if (threeFollowingDays.length < 3) continue
|
||||
|
||||
const fertileCervixOccursIn3FollowingDays = threeFollowingDays.some(day => {
|
||||
return !isClosedAndHard(day.cervix)
|
||||
})
|
||||
if (fertileCervixOccursIn3FollowingDays) continue
|
||||
|
||||
const cycleDayIndex = cycleDays.indexOf(day)
|
||||
const relevantDays = cycleDays
|
||||
.slice(cycleDayIndex + 1, tempEvalEndIndex + 1)
|
||||
.filter(day => day.cervix && !day.cervix.exclude)
|
||||
|
||||
const onlyClosedAndHardUntilEndOfTempEval = relevantDays.every(day => {
|
||||
return isClosedAndHard(day.cervix)
|
||||
})
|
||||
|
||||
if (onlyClosedAndHardUntilEndOfTempEval) {
|
||||
return {
|
||||
detected: true,
|
||||
cervixPeak: day,
|
||||
evaluationCompleteDay: threeFollowingDays[threeFollowingDays.length - 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { detected: false }
|
||||
}
|
||||
|
||||
function isClosedAndHard (cervixValue) {
|
||||
return cervixValue.isClosed && cervixValue.isHard
|
||||
}
|
||||
+27
-11
@@ -1,11 +1,12 @@
|
||||
import getTemperatureShift from './temperature'
|
||||
import getMucusShift from './mucus'
|
||||
import getCervixShift from './cervix'
|
||||
import getPreOvulatoryPhase from './pre-ovulatory'
|
||||
import { LocalDate } from 'js-joda'
|
||||
import assert from 'assert'
|
||||
|
||||
export default function getSymptoThermalStatus(cycles) {
|
||||
const { cycle, previousCycle, earlierCycles = [] } = cycles
|
||||
export default function getSymptoThermalStatus(cycleInfo) {
|
||||
const { cycle, previousCycle, earlierCycles = [], secondarySymptom = 'mucus' } = cycleInfo
|
||||
throwIfArgsAreNotInRequiredFormat([cycle, ...earlierCycles])
|
||||
|
||||
const status = {
|
||||
@@ -48,20 +49,28 @@ export default function getSymptoThermalStatus(cycles) {
|
||||
}
|
||||
|
||||
const temperatureShift = getTemperatureShift(cycle)
|
||||
|
||||
if (!temperatureShift.detected) return status
|
||||
|
||||
const tempEvalEndIndex = cycle.indexOf(temperatureShift.evaluationCompleteDay)
|
||||
const mucusShift = getMucusShift(cycle, tempEvalEndIndex)
|
||||
if (!mucusShift.detected) return status
|
||||
|
||||
let secondaryShift
|
||||
if (secondarySymptom === 'mucus') {
|
||||
secondaryShift = getMucusShift(cycle, tempEvalEndIndex)
|
||||
} else if (secondarySymptom === 'cervix') {
|
||||
secondaryShift = getCervixShift(cycle, tempEvalEndIndex)
|
||||
}
|
||||
|
||||
if (!secondaryShift.detected) return status
|
||||
|
||||
let periOvulatoryEnd
|
||||
const tempOver = temperatureShift.evaluationCompleteDay.date
|
||||
const mucusOver = mucusShift.evaluationCompleteDay.date
|
||||
const secondarySymptomOver = secondaryShift.evaluationCompleteDay.date
|
||||
|
||||
if (tempOver > mucusOver) {
|
||||
if (tempOver > secondarySymptomOver) {
|
||||
periOvulatoryEnd = temperatureShift.evaluationCompleteDay
|
||||
} else {
|
||||
periOvulatoryEnd = mucusShift.evaluationCompleteDay
|
||||
periOvulatoryEnd = secondaryShift.evaluationCompleteDay
|
||||
}
|
||||
|
||||
const previousPeriDays = periPhase.cycleDays
|
||||
@@ -78,7 +87,12 @@ export default function getSymptoThermalStatus(cycles) {
|
||||
periPhase.cycleDays = previousPeriDays.slice(0, previousPeriEndIndex + 1)
|
||||
periPhase.end = status.phases.postOvulatory.start
|
||||
|
||||
status.mucusShift = mucusShift
|
||||
if (secondarySymptom === 'mucus') {
|
||||
status.mucusShift = secondaryShift
|
||||
} else if (secondarySymptom === 'cervix') {
|
||||
status.cervixShift = secondaryShift
|
||||
}
|
||||
|
||||
status.temperatureShift = temperatureShift
|
||||
|
||||
return status
|
||||
@@ -87,9 +101,9 @@ export default function getSymptoThermalStatus(cycles) {
|
||||
function throwIfArgsAreNotInRequiredFormat(cycles) {
|
||||
cycles.forEach(cycle => {
|
||||
assert.ok(Array.isArray(cycle))
|
||||
assert.ok(cycle.length > 0)
|
||||
assert.ok(cycle.length > 0) //what about 2 cycles of 1 day each?!
|
||||
assert.ok(cycle[0].bleeding !== null)
|
||||
assert.equal(typeof cycle[0].bleeding, 'object')
|
||||
assert.equal(typeof cycle[0].bleeding, 'object', "First cycle day must contain bleeding value")
|
||||
assert.equal(typeof cycle[0].bleeding.value, 'number')
|
||||
cycle.forEach(day => {
|
||||
assert.equal(typeof day.date, 'string')
|
||||
@@ -98,6 +112,8 @@ function throwIfArgsAreNotInRequiredFormat(cycles) {
|
||||
if (day.mucus) assert.equal(typeof day.mucus.value, 'number')
|
||||
if (day.mucus) assert.ok(day.mucus.value >= 0)
|
||||
if (day.mucus) assert.ok(day.mucus.value < 5)
|
||||
if (day.cervix) assert.equal(typeof day.cervix.isClosed, 'boolean')
|
||||
if (day.cervix) assert.equal(typeof day.cervix.isHard, 'boolean')
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user