Ignore secondary symptom peak after end of temperature evaluation
This commit is contained in:
@@ -2,7 +2,6 @@ export default function (cycleDays, tempEvalEndIndex) {
|
||||
const notDetected = { detected: false }
|
||||
const cervixDays = cycleDays
|
||||
.filter(day => day.cervix && !day.cervix.exclude)
|
||||
.filter(day => typeof day.cervix.opening === 'number' && typeof day.cervix.firmness === 'number')
|
||||
|
||||
// we search for the day of cervix peak, which must:
|
||||
// * have fertile cervix values
|
||||
@@ -19,14 +18,19 @@ export default function (cycleDays, tempEvalEndIndex) {
|
||||
const threeFollowingDays = cervixDays.slice(i + 1, i + 4)
|
||||
if (threeFollowingDays.length < 3) continue
|
||||
|
||||
// no other fertile cervix value may occur until temperature evaluation has
|
||||
// been completed
|
||||
const fertileCervixOccursIn3FollowingDays = threeFollowingDays.some(day => {
|
||||
return !isClosedAndHard(day.cervix)
|
||||
})
|
||||
if (fertileCervixOccursIn3FollowingDays) continue
|
||||
|
||||
const cycleDayIndex = cycleDays.indexOf(day)
|
||||
|
||||
// if temperature evaluation has been completed an we still haven't found
|
||||
// a candidate, there is no cervix shift
|
||||
if (cycleDayIndex > tempEvalEndIndex) return notDetected
|
||||
|
||||
// no other fertile cervix value may occur until temperature evaluation has
|
||||
// been completed
|
||||
const relevantDays = cycleDays
|
||||
.slice(cycleDayIndex + 1, tempEvalEndIndex + 1)
|
||||
.filter(day => day.cervix && !day.cervix.exclude)
|
||||
|
||||
+7
-2
@@ -16,8 +16,6 @@ export default function (cycleDays, tempEvalEndIndex) {
|
||||
if (day.mucus.value !== currentBestQuality) continue
|
||||
|
||||
// the three following days must be of lower quality
|
||||
// AND no best quality day may occur until temperature evaluation has
|
||||
// been completed
|
||||
const threeFollowingDays = mucusDays.slice(i + 1, i + 4)
|
||||
if (threeFollowingDays.length < 3) continue
|
||||
|
||||
@@ -27,6 +25,13 @@ export default function (cycleDays, tempEvalEndIndex) {
|
||||
if (bestQualityOccursIn3FollowingDays) continue
|
||||
|
||||
const cycleDayIndex = cycleDays.indexOf(day)
|
||||
|
||||
// if temperature evaluation has been completed an we still haven't found
|
||||
// a candidate, there is no cervix shift
|
||||
if (cycleDayIndex > tempEvalEndIndex) return notDetected
|
||||
|
||||
// no best quality day may occur until temperature evaluation has
|
||||
// been completed
|
||||
const relevantDays = cycleDays
|
||||
.slice(cycleDayIndex + 1, tempEvalEndIndex + 1)
|
||||
.filter(day => day.mucus && !day.mucus.exclude)
|
||||
|
||||
@@ -102,15 +102,15 @@ export const longAndComplicatedCycle = [
|
||||
{ date: '2018-06-07', temperature: 36.5, cervix: { opening: 0, firmness: 0 } },
|
||||
{ date: '2018-06-08', temperature: 36.52, cervix: { opening: 0, firmness: 0 } },
|
||||
{ date: '2018-06-09', temperature: 36.5, cervix: { opening: 2, firmness: 1 } },
|
||||
{ date: '2018-06-10', temperature: 36.4, cervix: { opening: 2, firmness: 1 } },
|
||||
{ date: '2018-06-10', temperature: 36.7, cervix: { opening: 2, firmness: 1 } },
|
||||
{ date: '2018-06-13', temperature: 36.45, cervix: { opening: 1, firmness: 1 } },
|
||||
{ date: '2018-06-14', temperature: 36.5, cervix: { opening: 1, firmness: 1 } },
|
||||
{ date: '2018-06-15', temperature: 36.55, cervix: { opening: 1, firmness: 1 } },
|
||||
{ date: '2018-06-16', temperature: 36.7, cervix: { opening: 2, firmness: 1 } },
|
||||
{ date: '2018-06-17', temperature: 36.65, cervix: { opening: 2, firmness: 1 } },
|
||||
{ date: '2018-06-18', temperature: 36.75, cervix: { opening: 1, firmness: 1 } },
|
||||
{ date: '2018-06-16', temperature: 36.5, cervix: { opening: 2, firmness: 1 } },
|
||||
{ date: '2018-06-17', temperature: 36.5, cervix: { opening: 2, firmness: 1 } },
|
||||
{ date: '2018-06-18', temperature: 36.5, cervix: { opening: 1, firmness: 1 } },
|
||||
{ date: '2018-06-19', temperature: 36.8, cervix: { opening: 0, firmness: 0 } },
|
||||
{ date: '2018-06-20', temperature: 36.85, cervix: { opening: 1, firmness: 1 } },
|
||||
{ date: '2018-06-20', temperature: 36.85, cervix: { opening: 0, firmness: 0 } },
|
||||
{ date: '2018-06-21', temperature: 36.8, cervix: { opening: 1, firmness: 1 } },
|
||||
{ date: '2018-06-22', temperature: 36.9, cervix: { opening: 0, firmness: 0 } },
|
||||
{ date: '2018-06-25', temperature: 36.9, cervix: { opening: 0, firmness: 0 } },
|
||||
@@ -265,3 +265,28 @@ export const cycleWithCervixOnFirstDay = [
|
||||
{ date: '2018-06-26', temperature: 36.8, cervix: { opening: 1, firmness: 1 } },
|
||||
{ date: '2018-06-27', temperature: 36.9, cervix: { opening: 1, firmness: 1 } }
|
||||
].map(convertToSymptoFormat)
|
||||
|
||||
export const fertileCervixOnlyAfterEndOfTempEval = [
|
||||
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||
{ date: '2018-06-02', temperature: 36.65 },
|
||||
{ date: '2018-06-04', temperature: 36.6 },
|
||||
{ date: '2018-06-05', temperature: 36.55 },
|
||||
{ date: '2018-06-06', temperature: 36.7 },
|
||||
{ date: '2018-06-09', temperature: 36.5 },
|
||||
{ date: '2018-06-10', temperature: 36.4 },
|
||||
{ date: '2018-06-13', temperature: 36.45 },
|
||||
{ date: '2018-06-14', temperature: 36.5 },
|
||||
{ date: '2018-06-15', temperature: 36.55 },
|
||||
{ date: '2018-06-16', temperature: 36.7 },
|
||||
{ date: '2018-06-17', temperature: 36.65 },
|
||||
{ date: '2018-06-18', temperature: 36.60 },
|
||||
{ date: '2018-06-19', temperature: 36.8 },
|
||||
{ date: '2018-06-20', temperature: 36.85 },
|
||||
{ date: '2018-06-21', temperature: 36.8 },
|
||||
{ date: '2018-06-22', temperature: 36.9 },
|
||||
{ date: '2018-06-25', temperature: 36.9, cervix: { opening: 1, firmness: 1 }},
|
||||
{ date: '2018-06-26', temperature: 36.8, cervix: { opening: 0, firmness: 0 }},
|
||||
{ date: '2018-06-30', temperature: 36.9, cervix: { opening: 0, firmness: 0 }},
|
||||
{ date: '2018-07-01', temperature: 36.9, cervix: { opening: 0, firmness: 0 }},
|
||||
{ date: '2018-07-02', temperature: 36.9, cervix: { opening: 0, firmness: 0 }}
|
||||
].map(convertToSymptoFormat)
|
||||
|
||||
@@ -14,7 +14,8 @@ import {
|
||||
fhmOnDay12,
|
||||
fhmOnDay15,
|
||||
cycleWithEarlyCervix,
|
||||
cycleWithCervixOnFirstDay
|
||||
cycleWithCervixOnFirstDay,
|
||||
fertileCervixOnlyAfterEndOfTempEval
|
||||
} from './cervix-temp-fixtures'
|
||||
|
||||
const expect = chai.expect
|
||||
@@ -222,7 +223,34 @@ describe('sympto', () => {
|
||||
start: { date: '2018-03-13' }
|
||||
})
|
||||
})
|
||||
|
||||
it('with fertile cervix only occurring after end of temperature evaluation ignores it', () => {
|
||||
const status = getSensiplanStatus({
|
||||
cycle: fertileCervixOnlyAfterEndOfTempEval,
|
||||
previousCycle: cervixShiftAndFhmOnSameDay,
|
||||
secondarySymptom: 'cervix'
|
||||
})
|
||||
|
||||
expect(status.temperatureShift).to.be.undefined()
|
||||
expect(status.mucusShift).to.be.undefined()
|
||||
|
||||
expect(Object.keys(status.phases).length).to.eql(2)
|
||||
expect(status.phases.preOvulatory).to.eql({
|
||||
start: { date: '2018-06-01' },
|
||||
end: { date: '2018-06-05' },
|
||||
cycleDays: fertileCervixOnlyAfterEndOfTempEval
|
||||
.filter(({date}) => date <= '2018-06-05')
|
||||
})
|
||||
expect(status.phases.periOvulatory).to.eql({
|
||||
start: { date: '2018-06-06' },
|
||||
cycleDays: fertileCervixOnlyAfterEndOfTempEval
|
||||
.filter(({date}) => {
|
||||
return date > '2018-06-05'
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('applying the minus-8 rule', () => {
|
||||
it('shortens the pre-ovu phase if there is a previous < 13 fhm', () => {
|
||||
const status = getSensiplanStatus({
|
||||
|
||||
@@ -105,30 +105,6 @@ describe('sympto', () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
it('when the cervix shift is happening after tempEvalEnd', () => {
|
||||
const values = [1,1,1,1,1,2,3,3,3,3,1,1,1,1,0,0,0,0,0,0,0]
|
||||
.map(turnIntoCycleDayObject)
|
||||
const status = getCervixStatus(values, 10)
|
||||
expect(status).to.eql({
|
||||
detected: true,
|
||||
cervixPeakBeforeShift: {
|
||||
date: 13,
|
||||
cervix: {
|
||||
opening: 1,
|
||||
firmness: 0,
|
||||
exclude: false
|
||||
}
|
||||
},
|
||||
evaluationCompleteDay: {
|
||||
date: 16,
|
||||
cervix: {
|
||||
opening: 0,
|
||||
firmness: 0,
|
||||
exclude: false
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('detects no cervix shift', () => {
|
||||
@@ -144,6 +120,12 @@ describe('sympto', () => {
|
||||
const status = getCervixStatus(values, 17)
|
||||
expect(status).to.eql({ detected: false })
|
||||
})
|
||||
it('when the cervix shift is happening after tempEvalEnd', () => {
|
||||
const values = [1,1,1,1,1,2,3,3,3,3,1,1,1,1,0,0,0,0,0,0,0]
|
||||
.map(turnIntoCycleDayObject)
|
||||
const status = getCervixStatus(values, 10)
|
||||
expect(status).to.eql({ detected: false })
|
||||
})
|
||||
it('if no days indicate fertile cervix which could be cervix peak', () => {
|
||||
const values = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]
|
||||
.map(turnIntoCycleDayObject)
|
||||
|
||||
@@ -169,7 +169,7 @@ export const mucusPeakAndFhmOnSameDay = [
|
||||
{ date: '2018-06-27', temperature: 36.9, mucus: 1 }
|
||||
].map(convertToSymptoFormat)
|
||||
|
||||
export const fhmTwoDaysBeforeMucusPeak = [
|
||||
export const mucusPeakOnLastDayOfTempEval = [
|
||||
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||
{ date: '2018-06-02', temperature: 36.65 },
|
||||
{ date: '2018-06-04', temperature: 36.6 },
|
||||
@@ -183,9 +183,9 @@ export const fhmTwoDaysBeforeMucusPeak = [
|
||||
{ date: '2018-06-16', temperature: 36.7, mucus: 2 },
|
||||
{ date: '2018-06-17', temperature: 36.65, mucus: 2 },
|
||||
{ date: '2018-06-18', temperature: 36.75, mucus: 2 },
|
||||
{ date: '2018-06-19', temperature: 36.8, mucus: 3 },
|
||||
{ date: '2018-06-20', temperature: 36.85, mucus: 2 },
|
||||
{ date: '2018-06-21', temperature: 36.8, mucus: 4 },
|
||||
{ date: '2018-06-19', temperature: 36.8, mucus: 2 },
|
||||
{ date: '2018-06-20', temperature: 36.85, mucus: 3 },
|
||||
{ date: '2018-06-21', temperature: 36.8, mucus: 2 },
|
||||
{ date: '2018-06-22', temperature: 36.9, mucus: 2 },
|
||||
{ date: '2018-06-25', temperature: 36.9, mucus: 1 },
|
||||
{ date: '2018-06-26', temperature: 36.8, mucus: 1 },
|
||||
@@ -332,3 +332,28 @@ export const mucusPeakSlightlyBeforeTempShift = [
|
||||
{ date: '2018-06-21', temperature: 36.8, mucus: 1},
|
||||
{ date: '2018-06-22', temperature: 36.8, mucus: 1}
|
||||
].map(convertToSymptoFormat)
|
||||
|
||||
export const mucusOnlyAfterEndOfTempEval = [
|
||||
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||
{ date: '2018-06-02', temperature: 36.65 },
|
||||
{ date: '2018-06-04', temperature: 36.6 },
|
||||
{ date: '2018-06-05', temperature: 36.55 },
|
||||
{ date: '2018-06-06', temperature: 36.7 },
|
||||
{ date: '2018-06-09', temperature: 36.5 },
|
||||
{ date: '2018-06-10', temperature: 36.4 },
|
||||
{ date: '2018-06-13', temperature: 36.45 },
|
||||
{ date: '2018-06-14', temperature: 36.5 },
|
||||
{ date: '2018-06-15', temperature: 36.55 },
|
||||
{ date: '2018-06-16', temperature: 36.7 },
|
||||
{ date: '2018-06-17', temperature: 36.65 },
|
||||
{ date: '2018-06-18', temperature: 36.60 },
|
||||
{ date: '2018-06-19', temperature: 36.8 },
|
||||
{ date: '2018-06-20', temperature: 36.85 },
|
||||
{ date: '2018-06-21', temperature: 36.8 },
|
||||
{ date: '2018-06-22', temperature: 36.9 },
|
||||
{ date: '2018-06-25', temperature: 36.9, mucus: 4 },
|
||||
{ date: '2018-06-26', temperature: 36.8, mucus: 1 },
|
||||
{ date: '2018-06-30', temperature: 36.9, mucus: 1 },
|
||||
{ date: '2018-07-01', temperature: 36.9, mucus: 1 },
|
||||
{ date: '2018-07-02', temperature: 36.9, mucus: 1 }
|
||||
].map(convertToSymptoFormat)
|
||||
|
||||
@@ -11,13 +11,14 @@ import {
|
||||
cycleWithEarlyMucus,
|
||||
cycleWithMucusOnFirstDay,
|
||||
mucusPeakAndFhmOnSameDay,
|
||||
fhmTwoDaysBeforeMucusPeak,
|
||||
mucusPeakOnLastDayOfTempEval,
|
||||
fhm5DaysAfterMucusPeak,
|
||||
mucusPeak5DaysAfterFhm,
|
||||
mucusPeakTwoDaysBeforeFhm,
|
||||
fhmOnDay12,
|
||||
fhmOnDay15,
|
||||
mucusPeakSlightlyBeforeTempShift
|
||||
mucusPeakSlightlyBeforeTempShift,
|
||||
mucusOnlyAfterEndOfTempEval
|
||||
} from './mucus-temp-fixtures'
|
||||
|
||||
const expect = chai.expect
|
||||
@@ -172,9 +173,10 @@ describe('sympto', () => {
|
||||
.filter(({date}) => date >= '2018-06-21')
|
||||
})
|
||||
})
|
||||
|
||||
it('with fhM 2 days before mucus peak waits for end of mucus eval', () => {
|
||||
const status = getSensiplanStatus({
|
||||
cycle: fhmTwoDaysBeforeMucusPeak,
|
||||
cycle: mucusPeakOnLastDayOfTempEval,
|
||||
previousCycle: cycleWithFhm
|
||||
})
|
||||
|
||||
@@ -185,24 +187,24 @@ describe('sympto', () => {
|
||||
expect(status.phases.preOvulatory).to.eql({
|
||||
start: { date: '2018-06-01' },
|
||||
end: { date: '2018-06-05' },
|
||||
cycleDays: fhmTwoDaysBeforeMucusPeak
|
||||
cycleDays: mucusPeakOnLastDayOfTempEval
|
||||
.filter(({date}) => date <= '2018-06-05')
|
||||
})
|
||||
expect(status.phases.periOvulatory).to.eql({
|
||||
start: { date: '2018-06-06' },
|
||||
end: { date: '2018-06-26', time: '18:00' },
|
||||
cycleDays: fhmTwoDaysBeforeMucusPeak
|
||||
end: { date: '2018-06-25', time: '18:00' },
|
||||
cycleDays: mucusPeakOnLastDayOfTempEval
|
||||
.filter(({date}) => {
|
||||
return date > '2018-06-05' && date <= '2018-06-26'
|
||||
return date > '2018-06-05' && date <= '2018-06-25'
|
||||
})
|
||||
})
|
||||
expect(status.phases.postOvulatory).to.eql({
|
||||
start: {
|
||||
date: '2018-06-26',
|
||||
date: '2018-06-25',
|
||||
time: '18:00'
|
||||
},
|
||||
cycleDays: fhmTwoDaysBeforeMucusPeak
|
||||
.filter(({date}) => date >= '2018-06-26')
|
||||
cycleDays: mucusPeakOnLastDayOfTempEval
|
||||
.filter(({date}) => date >= '2018-06-25')
|
||||
})
|
||||
})
|
||||
it('another example for mucus peak before temp shift', () => {
|
||||
@@ -334,6 +336,31 @@ describe('sympto', () => {
|
||||
.filter(({date}) => date >= '2018-06-21')
|
||||
})
|
||||
})
|
||||
|
||||
it('with mucus only occurring after end of temperature evaluation ignores it', () => {
|
||||
const status = getSensiplanStatus({
|
||||
cycle: mucusOnlyAfterEndOfTempEval,
|
||||
previousCycle: cycleWithFhm
|
||||
})
|
||||
|
||||
expect(status.temperatureShift).to.be.undefined()
|
||||
expect(status.mucusShift).to.be.undefined()
|
||||
|
||||
expect(Object.keys(status.phases).length).to.eql(2)
|
||||
expect(status.phases.preOvulatory).to.eql({
|
||||
start: { date: '2018-06-01' },
|
||||
end: { date: '2018-06-05' },
|
||||
cycleDays: fhm5DaysAfterMucusPeak
|
||||
.filter(({date}) => date <= '2018-06-05')
|
||||
})
|
||||
expect(status.phases.periOvulatory).to.eql({
|
||||
start: { date: '2018-06-06' },
|
||||
cycleDays: mucusOnlyAfterEndOfTempEval
|
||||
.filter(({date}) => {
|
||||
return date > '2018-06-05'
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('applying the minus-8 rule', () => {
|
||||
it('shortens the pre-ovu phase if there is a previous <13 fhm', () => {
|
||||
|
||||
Reference in New Issue
Block a user