From 60c61894666aa5128954e5b1046293a5dd0916ba Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Tue, 10 Jul 2018 17:04:54 +0200 Subject: [PATCH] Shorten pre-ovu phase when early mucus --- lib/sympto/pre-ovulatory.js | 9 ++++++++- test/sympto/fixtures.js | 26 +++++++++++++++++++++++++- test/sympto/index.spec.js | 25 ++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/lib/sympto/pre-ovulatory.js b/lib/sympto/pre-ovulatory.js index 5aa3c6a..8cc86b9 100644 --- a/lib/sympto/pre-ovulatory.js +++ b/lib/sympto/pre-ovulatory.js @@ -5,13 +5,20 @@ export default function(cycle) { const fiveDayEndDate = startDate.plusDays(4).toString() const fiveDayRuleDays = cycle.slice(0, 5).filter(d => d.date <= fiveDayEndDate) const preOvulatoryDays = getDaysUntilFertileMucus(fiveDayRuleDays) + let endDate + if (preOvulatoryDays.length === fiveDayRuleDays.length) { + endDate = fiveDayEndDate + } else { + endDate = preOvulatoryDays[preOvulatoryDays.length - 1].date + } + return { cycleDays: preOvulatoryDays, start: { date: preOvulatoryDays[0].date }, end: { - date: fiveDayEndDate + date: endDate } } } diff --git a/test/sympto/fixtures.js b/test/sympto/fixtures.js index 4304f82..45ab578 100644 --- a/test/sympto/fixtures.js +++ b/test/sympto/fixtures.js @@ -63,6 +63,29 @@ const cycleWithTempAndNoMucusShift = [ { date: '2018-06-27', temperature: 36.9, mucus: 4 } ].map(convertToSymptoFormat) +const cycleWithEarlyMucus = [ + { date: '2018-06-01', temperature: 36.6, bleeding: 2 }, + { date: '2018-06-02', temperature: 36.65, mucus: 3 }, + { date: '2018-06-05', temperature: 36.55 }, + { date: '2018-06-06', temperature: 36.7, mucus: 0 }, + { date: '2018-06-08', temperature: 36.45, mucus: 1 }, + { date: '2018-06-09', temperature: 36.5, mucus: 4 }, + { date: '2018-06-10', temperature: 36.4, mucus: 2 }, + { date: '2018-06-11', temperature: 36.5, mucus: 3 }, + { date: '2018-06-13', temperature: 36.45, mucus: 3 }, + { date: '2018-06-14', temperature: 36.5, mucus: 4 }, + { date: '2018-06-15', temperature: 36.55, mucus: 4 }, + { date: '2018-06-16', temperature: 36.7, mucus: 3 }, + { date: '2018-06-17', temperature: 36.65, mucus: 3 }, + { date: '2018-06-18', temperature: 36.75, mucus: 4 }, + { date: '2018-06-19', temperature: 36.8, mucus: 4 }, + { date: '2018-06-20', temperature: 36.85, mucus: 4 }, + { date: '2018-06-23', temperature: 36.9, mucus: 3 }, + { date: '2018-06-24', temperature: 36.85, mucus: 4 }, + { date: '2018-06-26', temperature: 36.8, mucus: 4 }, + { date: '2018-06-27', temperature: 36.9, mucus: 4 } +].map(convertToSymptoFormat) + const cycleWithoutAnyShifts = [ { date: '2018-06-01', temperature: 36.6, bleeding: 2 }, { date: '2018-06-02', temperature: 36.65 }, @@ -84,5 +107,6 @@ export { cycleWithTempAndNoMucusShift, cycleWithTempShift, cycleWithoutAnyShifts, - fiveDayCycle + fiveDayCycle, + cycleWithEarlyMucus } \ No newline at end of file diff --git a/test/sympto/index.spec.js b/test/sympto/index.spec.js index e950280..6bc56e7 100644 --- a/test/sympto/index.spec.js +++ b/test/sympto/index.spec.js @@ -1,7 +1,13 @@ import chai from 'chai' import getSensiplanStatus from '../../lib/sympto' import { - cycleWithoutTempShift, cycleWithTempAndMucusShift, cycleWithTempAndNoMucusShift, cycleWithTempShift, cycleWithoutAnyShifts, fiveDayCycle + cycleWithoutTempShift, + cycleWithTempAndMucusShift, + cycleWithTempAndNoMucusShift, + cycleWithTempShift, + cycleWithoutAnyShifts, + fiveDayCycle, + cycleWithEarlyMucus } from './fixtures' const expect = chai.expect @@ -86,7 +92,24 @@ describe('sympto', () => { start: { date: '2018-06-06' } }) }) + it('according to 5-day-rule with shortened pre-phase', function () { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: cycleWithTempShift + }) + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.assumeFertility).to.be.true() + expect(status.phases.preOvulatory).to.eql({ + cycleDays: [cycleWithEarlyMucus[0]], + start: { date: '2018-06-01' }, + end: { date: '2018-06-01' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: cycleWithEarlyMucus.slice(1), + start: { date: '2018-06-02' } + }) + }) }) describe('with shifts detects pre- and peri-ovulatory phase', function () { it('according to 5-day-rule', function () {