Skip to content
Snippets Groups Projects
Commit 0179c458 authored by Julia Friesel's avatar Julia Friesel
Browse files

Detect pre- and postovulatory phase with no previous higher measurement

parent 77ad491d
No related branches found
No related tags found
No related merge requests found
import getTemperatureShift from './temperature' import getTemperatureShift from './temperature'
import getMucusShift from './mucus' import getMucusShift from './mucus'
export default function (cycleDays) { export default function ({ cycle, previousCycle }) {
const assumeFertileStatus = { assumeFertility: true } // TODO check for basic stuff, throw if nonexistent
// TODO second phase calculation const status = {
if (cycleDays.length) assumeFertileStatus.phases = [ assumeFertility: true,
{ phases: {
startDate: cycleDays[0].date, periOvulatory: {
startTime: '00:00' start: {
}, date: null,
'TODO' time: '00:00'
] },
cycleDays: null
const temperatureShift = getTemperatureShift(cycleDays) }
if (!temperatureShift.detected) return assumeFertileStatus }
}
const tempEvalEndIndex = cycleDays.indexOf(temperatureShift.evaluationCompleteDay) // if there was no first higher measurement in the previous cycle,
const mucusShift = getMucusShift(cycleDays, tempEvalEndIndex) // no infertile preovulatory phase may be assumed
if (!mucusShift.detected) return assumeFertileStatus
const phase2 = { if (getTemperatureShift(previousCycle).detected) {
startDate: temperatureShift.evaluationCompleteDay.date, // add preOvulatory phase
startTime: '18:00' } else {
const first = cycle[0]
status.phases.periOvulatory.start.date = first.date
status.phases.periOvulatory.cycleDays = [...cycle]
} }
return { const temperatureShift = getTemperatureShift(cycle)
assumeFertility: false, if (!temperatureShift.detected) return status
temperatureShift,
mucusShift, const tempEvalEndIndex = cycle.indexOf(temperatureShift.evaluationCompleteDay)
phases: assumeFertileStatus.phases.concat(phase2) 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'
},
cycleDays: prevPeriOvulatoryDays.slice(periOvulatoryEndIndex)
} }
status.phases.periOvulatory.cycleDays = prevPeriOvulatoryDays.slice(0, periOvulatoryEndIndex + 1)
status.mucusShift = mucusShift
status.temperatureShift = temperatureShift
return status
} }
\ No newline at end of file
...@@ -11,48 +11,117 @@ function convertToSymptoFormat(val, i) { ...@@ -11,48 +11,117 @@ function convertToSymptoFormat(val, i) {
return sympto return sympto
} }
const cycleWithTempShift = [36.6, 36.6, 36.6, 36.6, 36.6, 36.6, 36.8, 36.8, 36.8]
.map(num => ({ temperature: num }))
.map(convertToSymptoFormat)
const cycleWithoutTempShift = [36.6, 36.6, 36.6, 36.6, 36.6, 36.6, 36.8, 36.8]
.map(num => ({ temperature: num }))
.map(convertToSymptoFormat)
const cycleWithTempAndMucusShift = [
{ temperature: 36.6, bleeding: 2 },
{ temperature: 36.65 },
{ temperature: 36.5 },
{ temperature: 36.6 },
{ temperature: 36.55 },
{ temperature: 36.7, mucus: 0 },
{ temperature: 36.75, mucus: 0 },
{ temperature: 36.45, mucus: 1 },
{ temperature: 36.5, mucus: 4 },
{ temperature: 36.4, mucus: 2 },
{ temperature: 36.5, mucus: 3 },
{ temperature: 36.55, mucus: 3 },
{ temperature: 36.45, mucus: 3 },
{ temperature: 36.5, mucus: 4 },
{ temperature: 36.55, mucus: 4 },
{ temperature: 36.7, mucus: 3 },
{ temperature: 36.65, mucus: 3 },
{ temperature: 36.75, mucus: 4 },
{ temperature: 36.8, mucus: 1 },
{ temperature: 36.85, mucus: 2 },
{ temperature: 36.8, mucus: 2 },
{ temperature: 36.9, mucus: 2 },
{ temperature: 36.9, mucus: 1 },
{ temperature: 36.85, mucus: 1 },
{ temperature: 36.9, mucus: 1 },
{ temperature: 36.8, mucus: 1 },
{ temperature: 36.9, mucus: 1 }
].map(convertToSymptoFormat)
describe('sympto', () => { describe('sympto', () => {
describe('evaluating mucus and temperature shift together', () => { describe('evaluating mucus and temperature shift together', () => {
it('reports fertile when mucus reaches best quality again within temperature evaluation phase', function () { describe('with no previous higher measurement', () => {
const values = [ it('with no shifts detects only periovulatory', function () {
{ temperature: 36.6 , bleeding: 2 }, const values = [
{ temperature: 36.65 }, { temperature: 36.6, bleeding: 2 },
{ temperature: 36.5 }, { temperature: 36.65 },
{ temperature: 36.6 }, { temperature: 36.5 },
{ temperature: 36.55 }, { temperature: 36.6 },
{ temperature: 36.7, mucus: 0 }, { temperature: 36.55 },
{ temperature: 36.75, mucus: 0 }, { temperature: 36.7, mucus: 0 },
{ temperature: 36.45, mucus: 1 }, { temperature: 36.75, mucus: 0 },
{ temperature: 36.5, mucus: 4 }, { temperature: 36.45, mucus: 1 }
{ temperature: 36.4, mucus: 2 }, ]
{ temperature: 36.5, mucus: 3 },
{ temperature: 36.55, mucus: 3 }, const cycle = values.map(convertToSymptoFormat)
{ temperature: 36.45, mucus: 3 }, const status = getSensiplanStatus({
{ temperature: 36.5, mucus: 4 }, cycle,
{ temperature: 36.55, mucus: 4 }, previousCycle: cycleWithoutTempShift
{ temperature: 36.7, mucus: 3 }, })
{ temperature: 36.65, mucus: 3 },
{ temperature: 36.75, mucus: 4 }, expect(status).to.eql({
{ temperature: 36.8, mucus: 1 }, assumeFertility: true,
{ temperature: 36.85, mucus: 2 }, phases: {
{ temperature: 36.8, mucus: 2 }, periOvulatory: {
{ temperature: 36.9, mucus: 2 }, start: {
{ temperature: 36.9, mucus: 1 }, date: 0,
{ temperature: 36.85, mucus: 1 }, time: '00:00'
{ temperature: 36.9, mucus: 1 }, },
{ temperature: 36.8, mucus: 1 }, cycleDays: cycle
{ temperature: 36.9, mucus: 1 } }
] },
})
})
it('with shifts detects only periovulatory and postovulatory', function () {
const status = getSensiplanStatus({
cycle: cycleWithTempAndMucusShift,
previousCycle: cycleWithoutTempShift
})
const temperatures = values.map(convertToSymptoFormat) expect(status.temperatureShift).to.be.an('object')
expect(status.mucusShift).to.be.an('object')
expect(status.assumeFertility).to.be.true()
expect(Object.keys(status.phases)).to.eql(['periOvulatory', 'postOvulatory'])
expect(status.phases.periOvulatory).to.eql({
start: {
date: 0,
time: '00:00'
},
cycleDays: cycleWithTempAndMucusShift.slice(0, 21)
})
expect(status.phases.postOvulatory).to.eql({
start: {
date: 20,
time: '18:00'
},
cycleDays: cycleWithTempAndMucusShift.slice(20)
})
})
})
})
describe('with shifts', () => {
it.skip('reports fertile when mucus reaches best quality again within temperature evaluation phase', function () {
const status = getSensiplanStatus(temperatures) const status = getSensiplanStatus(temperatures)
expect(status).to.eql({ expect(status).to.eql({
assumeFertility: false, assumeFertility: false,
phases: [ phases: {
{ startDate: 0, startTime: '00:00'}, preOvulatory:
'TODO', { startDate: 0, startTime: '00:00' },
{ startDate: 17, startTime: '18:00'} periOvulatory: 'TODO',
], postOvulatory: { startDate: 17, startTime: '18:00' }
},
temperatureShift: { temperatureShift: {
detected: true, detected: true,
ltl: 36.55, ltl: 36.55,
...@@ -78,5 +147,6 @@ describe('sympto', () => { ...@@ -78,5 +147,6 @@ describe('sympto', () => {
} }
}) })
}) })
}) })
}) })
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment