Detect pre- and postovulatory phase with no previous higher measurement
This commit is contained in:
+51
-26
@@ -1,33 +1,58 @@
|
||||
import getTemperatureShift from './temperature'
|
||||
import getMucusShift from './mucus'
|
||||
|
||||
export default function (cycleDays) {
|
||||
const assumeFertileStatus = { assumeFertility: true }
|
||||
// TODO second phase calculation
|
||||
if (cycleDays.length) assumeFertileStatus.phases = [
|
||||
{
|
||||
startDate: cycleDays[0].date,
|
||||
startTime: '00:00'
|
||||
export default function ({ cycle, previousCycle }) {
|
||||
// TODO check for basic stuff, throw if nonexistent
|
||||
const status = {
|
||||
assumeFertility: true,
|
||||
phases: {
|
||||
periOvulatory: {
|
||||
start: {
|
||||
date: null,
|
||||
time: '00:00'
|
||||
},
|
||||
cycleDays: null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if there was no first higher measurement in the previous cycle,
|
||||
// no infertile preovulatory phase may be assumed
|
||||
|
||||
if (getTemperatureShift(previousCycle).detected) {
|
||||
// add preOvulatory phase
|
||||
} else {
|
||||
const first = cycle[0]
|
||||
status.phases.periOvulatory.start.date = first.date
|
||||
status.phases.periOvulatory.cycleDays = [...cycle]
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
const periOvulatoryEnd =
|
||||
temperatureShift.evaluationCompleteDay.date > mucusShift.evaluationCompleteDay.date ?
|
||||
temperatureShift.evaluationCompleteDay : mucusShift.evaluationCompleteDay
|
||||
|
||||
const prevPeriOvulatoryDays = status.phases.periOvulatory.cycleDays
|
||||
const periOvulatoryEndIndex = prevPeriOvulatoryDays.indexOf(periOvulatoryEnd)
|
||||
|
||||
status.phases.postOvulatory = {
|
||||
start: {
|
||||
date: periOvulatoryEnd.date,
|
||||
time: '18:00'
|
||||
},
|
||||
'TODO'
|
||||
]
|
||||
|
||||
const temperatureShift = getTemperatureShift(cycleDays)
|
||||
if (!temperatureShift.detected) return assumeFertileStatus
|
||||
|
||||
const tempEvalEndIndex = cycleDays.indexOf(temperatureShift.evaluationCompleteDay)
|
||||
const mucusShift = getMucusShift(cycleDays, tempEvalEndIndex)
|
||||
if (!mucusShift.detected) return assumeFertileStatus
|
||||
|
||||
const phase2 = {
|
||||
startDate: temperatureShift.evaluationCompleteDay.date,
|
||||
startTime: '18:00'
|
||||
cycleDays: prevPeriOvulatoryDays.slice(periOvulatoryEndIndex)
|
||||
}
|
||||
|
||||
return {
|
||||
assumeFertility: false,
|
||||
temperatureShift,
|
||||
mucusShift,
|
||||
phases: assumeFertileStatus.phases.concat(phase2)
|
||||
}
|
||||
status.phases.periOvulatory.cycleDays = prevPeriOvulatoryDays.slice(0, periOvulatoryEndIndex + 1)
|
||||
|
||||
status.mucusShift = mucusShift
|
||||
status.temperatureShift = temperatureShift
|
||||
|
||||
return status
|
||||
}
|
||||
Reference in New Issue
Block a user