Implement 5-day-rule
This commit is contained in:
+14
-7
@@ -1,5 +1,7 @@
|
||||
import getTemperatureShift from './temperature'
|
||||
import getMucusShift from './mucus'
|
||||
import getPreOvulatoryPhase from './pre-ovulatory'
|
||||
import { LocalDate } from 'js-joda'
|
||||
|
||||
export default function ({ cycle, previousCycle }) {
|
||||
// TODO check for basic stuff, throw if nonexistent
|
||||
@@ -8,8 +10,7 @@ export default function ({ cycle, previousCycle }) {
|
||||
phases: {
|
||||
periOvulatory: {
|
||||
start: {
|
||||
date: null,
|
||||
time: '00:00'
|
||||
date: null
|
||||
},
|
||||
cycleDays: null
|
||||
}
|
||||
@@ -18,13 +19,19 @@ export default function ({ cycle, previousCycle }) {
|
||||
|
||||
// if there was no first higher measurement in the previous cycle,
|
||||
// no infertile preovulatory phase may be assumed
|
||||
if (getTemperatureShift(previousCycle).detected && !cycle[0].mucus) {
|
||||
status.phases.preOvulatory = getPreOvulatoryPhase(cycle)
|
||||
}
|
||||
|
||||
if (getTemperatureShift(previousCycle).detected) {
|
||||
// add preOvulatory phase
|
||||
const periPhase = status.phases.periOvulatory
|
||||
if (status.phases.preOvulatory) {
|
||||
const prePhase = status.phases.preOvulatory
|
||||
periPhase.start.date = LocalDate.parse(prePhase.end.date).plusDays(1).toString()
|
||||
const lastPreDay = prePhase.cycleDays[prePhase.cycleDays.length - 1]
|
||||
periPhase.cycleDays = cycle.slice(cycle.indexOf(lastPreDay) + 1)
|
||||
} else {
|
||||
const first = cycle[0]
|
||||
status.phases.periOvulatory.start.date = first.date
|
||||
status.phases.periOvulatory.cycleDays = [...cycle]
|
||||
periPhase.start.date = cycle[0].date
|
||||
periPhase.cycleDays = [...cycle]
|
||||
}
|
||||
|
||||
const temperatureShift = getTemperatureShift(cycle)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
export default function(cycle) {
|
||||
const fiveDayRuleDays = cycle.slice(0, 5)
|
||||
const preOvulatoryDays = getDaysUntilFertileMucus(fiveDayRuleDays)
|
||||
return {
|
||||
cycleDays: preOvulatoryDays,
|
||||
start: {
|
||||
date: preOvulatoryDays[0].date
|
||||
},
|
||||
end: {
|
||||
date: preOvulatoryDays[preOvulatoryDays.length - 1].date,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getDaysUntilFertileMucus(days) {
|
||||
const firstFertileMucusDayIndex = days.findIndex(day => day.mucus && day.mucus.value > 1)
|
||||
if (firstFertileMucusDayIndex > -1) {
|
||||
return days.slice(0, firstFertileMucusDayIndex)
|
||||
}
|
||||
return days
|
||||
}
|
||||
Reference in New Issue
Block a user