From fa3a6fb2e77a0cc3be4b3ff0d326ec9665dbf542 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Fri, 28 Sep 2018 08:45:52 +0200 Subject: [PATCH 1/6] Ignore secondary symptom peak after end of temperature evaluation --- lib/sympto/cervix.js | 10 ++++-- lib/sympto/mucus.js | 9 ++++-- test/sympto/cervix-temp-fixtures.js | 35 ++++++++++++++++++--- test/sympto/cervix-temp.spec.js | 30 +++++++++++++++++- test/sympto/cervix.spec.js | 30 ++++-------------- test/sympto/mucus-temp-fixtures.js | 33 +++++++++++++++++--- test/sympto/mucus-temp.spec.js | 47 +++++++++++++++++++++++------ 7 files changed, 145 insertions(+), 49 deletions(-) diff --git a/lib/sympto/cervix.js b/lib/sympto/cervix.js index 2578381..1f012b3 100644 --- a/lib/sympto/cervix.js +++ b/lib/sympto/cervix.js @@ -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) diff --git a/lib/sympto/mucus.js b/lib/sympto/mucus.js index 12e23b8..727f76a 100644 --- a/lib/sympto/mucus.js +++ b/lib/sympto/mucus.js @@ -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) diff --git a/test/sympto/cervix-temp-fixtures.js b/test/sympto/cervix-temp-fixtures.js index 18adfe6..8924249 100644 --- a/test/sympto/cervix-temp-fixtures.js +++ b/test/sympto/cervix-temp-fixtures.js @@ -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) diff --git a/test/sympto/cervix-temp.spec.js b/test/sympto/cervix-temp.spec.js index 964b1d6..b7c599b 100644 --- a/test/sympto/cervix-temp.spec.js +++ b/test/sympto/cervix-temp.spec.js @@ -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({ diff --git a/test/sympto/cervix.spec.js b/test/sympto/cervix.spec.js index f8bbc3e..a328d6c 100644 --- a/test/sympto/cervix.spec.js +++ b/test/sympto/cervix.spec.js @@ -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) diff --git a/test/sympto/mucus-temp-fixtures.js b/test/sympto/mucus-temp-fixtures.js index d6463c0..29e0cf3 100644 --- a/test/sympto/mucus-temp-fixtures.js +++ b/test/sympto/mucus-temp-fixtures.js @@ -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) diff --git a/test/sympto/mucus-temp.spec.js b/test/sympto/mucus-temp.spec.js index c2a2563..ddc0bcb 100644 --- a/test/sympto/mucus-temp.spec.js +++ b/test/sympto/mucus-temp.spec.js @@ -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', () => { From 32e6b2da78b439c1aef79835d42b2f20c6f90ecd Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Fri, 28 Sep 2018 18:05:17 +0200 Subject: [PATCH 2/6] Add back cervix value filter --- lib/sympto/cervix.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/sympto/cervix.js b/lib/sympto/cervix.js index 1f012b3..15c990a 100644 --- a/lib/sympto/cervix.js +++ b/lib/sympto/cervix.js @@ -2,6 +2,7 @@ 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 From d76fbf3f26ac7142bd0bf94ff12c59cf63ca5ead Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Fri, 28 Sep 2018 18:44:40 +0200 Subject: [PATCH 3/6] Add comment --- lib/sympto/cervix.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/sympto/cervix.js b/lib/sympto/cervix.js index 15c990a..e09205c 100644 --- a/lib/sympto/cervix.js +++ b/lib/sympto/cervix.js @@ -7,6 +7,7 @@ export default function (cycleDays, tempEvalEndIndex) { // we search for the day of cervix peak, which must: // * have fertile cervix values // * be followed by at least 3 days + // * must happen prior to end of temperature evaluation // these 3 following days must all show infertile cervix values // if everything applies we must check the days until the end of temperature evaluation // during these relevantDays no fertile cervix must occur From 562b1f2069c1f4a41f9e17109c0e0da1ad7923c6 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Fri, 28 Sep 2018 19:48:18 +0200 Subject: [PATCH 4/6] Fix copypasta --- lib/sympto/mucus.js | 2 +- test/sympto/cervix-temp.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sympto/mucus.js b/lib/sympto/mucus.js index 727f76a..0c44cc7 100644 --- a/lib/sympto/mucus.js +++ b/lib/sympto/mucus.js @@ -27,7 +27,7 @@ export default function (cycleDays, tempEvalEndIndex) { const cycleDayIndex = cycleDays.indexOf(day) // if temperature evaluation has been completed an we still haven't found - // a candidate, there is no cervix shift + // a candidate, there is no mucus shift if (cycleDayIndex > tempEvalEndIndex) return notDetected // no best quality day may occur until temperature evaluation has diff --git a/test/sympto/cervix-temp.spec.js b/test/sympto/cervix-temp.spec.js index b7c599b..2748124 100644 --- a/test/sympto/cervix-temp.spec.js +++ b/test/sympto/cervix-temp.spec.js @@ -232,7 +232,7 @@ describe('sympto', () => { }) expect(status.temperatureShift).to.be.undefined() - expect(status.mucusShift).to.be.undefined() + expect(status.cervixShift).to.be.undefined() expect(Object.keys(status.phases).length).to.eql(2) expect(status.phases.preOvulatory).to.eql({ From 855b69a3499134f0009c784d009b185246e125f8 Mon Sep 17 00:00:00 2001 From: emelko Date: Mon, 1 Oct 2018 08:57:22 +0200 Subject: [PATCH 5/6] Adds test for: * latest valid cervix shift * late and therefore invalid cervix shift --- test/sympto/cervix-temp-fixtures.js | 26 +++++++++++- test/sympto/cervix-temp.spec.js | 64 +++++++++++++++++++---------- 2 files changed, 67 insertions(+), 23 deletions(-) diff --git a/test/sympto/cervix-temp-fixtures.js b/test/sympto/cervix-temp-fixtures.js index 8924249..e4c6230 100644 --- a/test/sympto/cervix-temp-fixtures.js +++ b/test/sympto/cervix-temp-fixtures.js @@ -143,7 +143,7 @@ export const tempShift3DaysAfterCervixShift = [ { date: '2018-05-29', bleeding: 2 } ].map(convertToSymptoFormat) -export const cervixShift2DaysAfterTempShift = [ +export const cervixShift3DaysAfterTempShift = [ { date: '2018-04-05', bleeding: 3 }, { date: '2018-04-06', bleeding: 2 }, { date: '2018-04-07', bleeding: 2 }, @@ -156,7 +156,7 @@ export const cervixShift2DaysAfterTempShift = [ { date: '2018-04-14', temperature: 36.35, cervix: { opening: 1, firmness: 1 } }, { date: '2018-04-15', temperature: 36.6, cervix: { opening: 1, firmness: 1 } }, { date: '2018-04-16', temperature: 36.8, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-04-17', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-04-17', temperature: 36.8, cervix: { opening: 1, firmness: 0 } }, { date: '2018-04-18', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, { date: '2018-04-19', temperature: 36.85, cervix: { opening: 0, firmness: 0 } }, { date: '2018-04-20', temperature: 37.0, cervix: { opening: 0, firmness: 0 } }, @@ -165,6 +165,28 @@ export const cervixShift2DaysAfterTempShift = [ { date: '2018-04-24', temperature: 36.75, cervix: { opening: 0, firmness: 0 } } ].map(convertToSymptoFormat) +export const cervixShift4DaysAfterTempShift = [ + { date: '2018-04-05', bleeding: 3 }, + { date: '2018-04-06', bleeding: 2 }, + { date: '2018-04-07', bleeding: 2 }, + { date: '2018-04-08', bleeding: 1 }, + { date: '2018-04-09', temperature: 36.5 }, + { date: '2018-04-10', temperature: 36.5, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-04-11', temperature: 36.55, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-04-12', temperature: 36.5, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-04-13', temperature: 36.35, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-04-14', temperature: 36.35, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-04-15', temperature: 36.6, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-04-16', temperature: 36.8, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-04-17', temperature: 36.8, cervix: { opening: 1, firmness: 0 } }, + { date: '2018-04-18', temperature: 36.8, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-04-19', temperature: 36.85, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-04-20', temperature: 37.0, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-04-22', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-04-23', temperature: 37.1, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-04-24', temperature: 36.75, cervix: { opening: 0, firmness: 0 } } +].map(convertToSymptoFormat) + export const noOvulationDetected = [ { date: '2018-03-08', bleeding: 3 }, { date: '2018-03-09', bleeding: 3 }, diff --git a/test/sympto/cervix-temp.spec.js b/test/sympto/cervix-temp.spec.js index 2748124..3680f22 100644 --- a/test/sympto/cervix-temp.spec.js +++ b/test/sympto/cervix-temp.spec.js @@ -8,7 +8,8 @@ import { longCycleWithoutAnyShifts, longAndComplicatedCycle, tempShift3DaysAfterCervixShift, - cervixShift2DaysAfterTempShift, + cervixShift3DaysAfterTempShift, + cervixShift4DaysAfterTempShift, noOvulationDetected, fiveDayCycle, fhmOnDay12, @@ -173,57 +174,59 @@ describe('sympto', () => { .filter(({date}) => date >= '2018-05-21') }) }) - it('with cervix shift 2 days after temperature shift detects all 3 phases', () => { + it('with cervix shift 3 days after temperature shift detects all 3 phases', () => { const status = getSensiplanStatus({ - cycle: cervixShift2DaysAfterTempShift, + cycle: cervixShift3DaysAfterTempShift, previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) expect(status.temperatureShift.rule).to.eql(0) expect(status.temperatureShift.evaluationCompleteDay.date).to.eql('2018-04-17') - expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-04-19') + expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-04-20') expect(status.phases.preOvulatory).to.eql({ - cycleDays: cervixShift2DaysAfterTempShift + cycleDays: cervixShift3DaysAfterTempShift .filter(({date}) => date <= '2018-04-09'), start: { date: '2018-04-05' }, end: { date: '2018-04-09' } }) expect(status.phases.periOvulatory).to.eql({ - cycleDays: cervixShift2DaysAfterTempShift + cycleDays: cervixShift3DaysAfterTempShift .filter(({date}) => { - return date >= '2018-04-10' && date <= '2018-04-19' + return date >= '2018-04-10' && date <= '2018-04-20' }), start: { date: '2018-04-10' }, - end: { date: '2018-04-19', time: '18:00' } + end: { date: '2018-04-20', time: '18:00'} }) expect(status.phases.postOvulatory).to.eql({ - cycleDays: cervixShift2DaysAfterTempShift - .filter(({date}) => date >= '2018-04-19'), - start: { date: '2018-04-19', time: '18:00' } + cycleDays: cervixShift3DaysAfterTempShift + .filter(({date}) => date >= '2018-04-20'), + start: { date: '2018-04-20', time: '18:00' } }) }) - it('with no shifts no ovulation is found detects only pre and peri-ovulatory phase', () => { + it('with cervix shift 4 days after temperature shift detects no post-ovulatory phase', () => { const status = getSensiplanStatus({ - cycle: noOvulationDetected, + cycle: cervixShift4DaysAfterTempShift, previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.preOvulatory).to.eql({ - cycleDays: noOvulationDetected - .filter(({date}) => date <= '2018-03-12'), - start: { date: '2018-03-08' }, - end: { date: '2018-03-12' } + cycleDays: cervixShift4DaysAfterTempShift + .filter(({date}) => date <= '2018-04-09'), + start: { date: '2018-04-05' }, + end: { date: '2018-04-09' } }) expect(status.phases.periOvulatory).to.eql({ - cycleDays: noOvulationDetected - .filter(({date}) => date > '2018-03-12'), - start: { date: '2018-03-13' } + cycleDays: cervixShift4DaysAfterTempShift + .filter(({date}) => { + return date >= '2018-04-10' + }), + start: { date: '2018-04-10' } }) }) - it('with fertile cervix only occurring after end of temperature evaluation ignores it', () => { const status = getSensiplanStatus({ cycle: fertileCervixOnlyAfterEndOfTempEval, @@ -249,6 +252,25 @@ describe('sympto', () => { }) }) }) + it('with no shifts no ovulation is found detects only pre and peri-ovulatory phase', () => { + const status = getSensiplanStatus({ + cycle: noOvulationDetected, + previousCycle: cervixShiftAndFhmOnSameDay, + secondarySymptom: 'cervix' + }) + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.preOvulatory).to.eql({ + cycleDays: noOvulationDetected + .filter(({date}) => date <= '2018-03-12'), + start: { date: '2018-03-08' }, + end: { date: '2018-03-12' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: noOvulationDetected + .filter(({date}) => date > '2018-03-12'), + start: { date: '2018-03-13' } + }) + }) }) describe('applying the minus-8 rule', () => { From a1eddb3cbec934d792040767e5d9a4b7732c9442 Mon Sep 17 00:00:00 2001 From: emelko Date: Mon, 1 Oct 2018 11:42:22 +0200 Subject: [PATCH 6/6] Adds test for mucus and temp tracking: * late mucus shift and therefore no postovu phase --- test/sympto/mucus-temp-fixtures.js | 44 ++++++++++++++++++++++++++++++ test/sympto/mucus-temp.spec.js | 42 +++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/test/sympto/mucus-temp-fixtures.js b/test/sympto/mucus-temp-fixtures.js index 29e0cf3..45e0b98 100644 --- a/test/sympto/mucus-temp-fixtures.js +++ b/test/sympto/mucus-temp-fixtures.js @@ -191,6 +191,50 @@ export const mucusPeakOnLastDayOfTempEval = [ { date: '2018-06-26', temperature: 36.8, mucus: 1 }, ].map(convertToSymptoFormat) +export const mucusPeakAfterLastDayOfTempEval = [ + { 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, mucus: 0 }, + { date: '2018-06-09', temperature: 36.5, mucus: 1 }, + { date: '2018-06-10', temperature: 36.4, mucus: 2 }, + { date: '2018-06-13', temperature: 36.45, mucus: 2 }, + { date: '2018-06-14', temperature: 36.5, mucus: 2 }, + { date: '2018-06-15', temperature: 36.55, mucus: 1 }, + { 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: 2 }, + { date: '2018-06-20', temperature: 36.9, mucus: 2 }, + { date: '2018-06-21', temperature: 36.8, mucus: 3 }, + { 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 }, +].map(convertToSymptoFormat) + +export const mucusPeakOnAndAfterLastDayOfTempEval = [ + { 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, mucus: 0 }, + { date: '2018-06-09', temperature: 36.5, mucus: 1 }, + { date: '2018-06-10', temperature: 36.4, mucus: 2 }, + { date: '2018-06-13', temperature: 36.45, mucus: 2 }, + { date: '2018-06-14', temperature: 36.5, mucus: 2 }, + { date: '2018-06-15', temperature: 36.55, mucus: 1 }, + { 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: 2 }, + { date: '2018-06-20', temperature: 36.9, mucus: 3 }, + { date: '2018-06-21', temperature: 36.8, mucus: 3 }, + { 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 }, +].map(convertToSymptoFormat) + export const mucusPeakTwoDaysBeforeFhm = [ { date: '2018-06-01', temperature: 36.6, bleeding: 2 }, { date: '2018-06-02', temperature: 36.65 }, diff --git a/test/sympto/mucus-temp.spec.js b/test/sympto/mucus-temp.spec.js index ddc0bcb..598c33f 100644 --- a/test/sympto/mucus-temp.spec.js +++ b/test/sympto/mucus-temp.spec.js @@ -12,6 +12,8 @@ import { cycleWithMucusOnFirstDay, mucusPeakAndFhmOnSameDay, mucusPeakOnLastDayOfTempEval, + mucusPeakAfterLastDayOfTempEval, + mucusPeakOnAndAfterLastDayOfTempEval, fhm5DaysAfterMucusPeak, mucusPeak5DaysAfterFhm, mucusPeakTwoDaysBeforeFhm, @@ -174,7 +176,7 @@ describe('sympto', () => { }) }) - it('with fhM 2 days before mucus peak waits for end of mucus eval', () => { + it('with mucus peak 3 days after fhM waits for end of mucus eval', () => { const status = getSensiplanStatus({ cycle: mucusPeakOnLastDayOfTempEval, previousCycle: cycleWithFhm @@ -207,6 +209,44 @@ describe('sympto', () => { .filter(({date}) => date >= '2018-06-25') }) }) + it('with mucus peak 4 days after fhM detects no postovu phase', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakAfterLastDayOfTempEval, + previousCycle: cycleWithFhm + }) + + 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: mucusPeakAfterLastDayOfTempEval + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + cycleDays: mucusPeakAfterLastDayOfTempEval + .filter(({date}) => date > '2018-06-05') + }) + }) + it('with mucus peak 3 and 4 days after fhM detects no postovu phase', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakOnAndAfterLastDayOfTempEval, + previousCycle: cycleWithFhm + }) + + 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: mucusPeakOnAndAfterLastDayOfTempEval + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + cycleDays: mucusPeakOnAndAfterLastDayOfTempEval + .filter(({date}) => date > '2018-06-05') + }) + }) it('another example for mucus peak before temp shift', () => { const status = getSensiplanStatus({ cycle: mucusPeakSlightlyBeforeTempShift,