From 574e7ed85429979ff3a83344cac082bf180056d3 Mon Sep 17 00:00:00 2001 From: Julia Friesel <julia.friesel@gmail.com> Date: Wed, 1 Aug 2018 16:45:41 +0200 Subject: [PATCH] Ignore highest quality after end of eval --- lib/sympto/mucus.js | 13 +++++++++---- test/periode-length.spec.js | 2 +- test/sympto/fixtures.js | 23 +++++++++++++++++++++++ test/sympto/index.spec.js | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/lib/sympto/mucus.js b/lib/sympto/mucus.js index 9eb37efb..cc788f87 100644 --- a/lib/sympto/mucus.js +++ b/lib/sympto/mucus.js @@ -1,10 +1,15 @@ export default function (cycleDays, tempEvalEndIndex) { const mucusDays = cycleDays.filter(day => day.mucus && !day.mucus.exclude) - const bestQuality = Math.max(...mucusDays.map(day => day.mucus.value)) + let currentBestQuality = 0 for (let i = 0; i < mucusDays.length; i++) { const day = mucusDays[i] - if (day.mucus.value !== bestQuality) continue + + if (day.mucus.value > currentBestQuality) { + currentBestQuality = day.mucus.value + } + + 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 @@ -13,7 +18,7 @@ export default function (cycleDays, tempEvalEndIndex) { if (threeFollowingDays.length < 3) continue const bestQualityOccursIn3FollowingDays = threeFollowingDays.some(day => { - return day.mucus.value >= bestQuality + return day.mucus.value >= currentBestQuality }) if (bestQualityOccursIn3FollowingDays) continue @@ -23,7 +28,7 @@ export default function (cycleDays, tempEvalEndIndex) { .filter(day => day.mucus && !day.mucus.exclude) const noBestQualityUntilEndOfTempEval = relevantDays.every(day => { - return day.mucus.value < bestQuality + return day.mucus.value < currentBestQuality }) if (noBestQualityUntilEndOfTempEval) { diff --git a/test/periode-length.spec.js b/test/periode-length.spec.js index 0b9b200b..f10fb185 100644 --- a/test/periode-length.spec.js +++ b/test/periode-length.spec.js @@ -5,7 +5,7 @@ import periodInfo from '../lib/period-length' const expect = chai.expect -describe.only('getPeriodLengthStats', () => { +describe('getPeriodLengthStats', () => { it('works for a simple odd-numbered array', () => { const periodLengths = [99, 5, 1, 2, 100] const result = periodInfo(periodLengths) diff --git a/test/sympto/fixtures.js b/test/sympto/fixtures.js index 6b614928..0bb4f9fb 100644 --- a/test/sympto/fixtures.js +++ b/test/sympto/fixtures.js @@ -298,4 +298,27 @@ export const mucusPeakSlightlyBeforeTempShift = [ { date: '2018-06-20', temperature: 36.75, mucus: 1}, { date: '2018-06-21', temperature: 36.8, mucus: 1}, { date: '2018-06-22', temperature: 36.8, mucus: 1} +].map(convertToSymptoFormat) + + +export const highestMucusQualityAfterEndOfEval = [ + { 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-07', temperature: 36.4, mucus: 1 }, + { date: '2018-06-08', temperature: 36.35, mucus: 2}, + { date: '2018-06-09', temperature: 36.4, mucus: 2}, + { date: '2018-06-10', temperature: 36.45, mucus: 2}, + { date: '2018-06-11', temperature: 36.4, mucus: 2}, + { date: '2018-06-12', temperature: 36.45, mucus: 2}, + { date: '2018-06-13', temperature: 36.45, mucus: 3}, + { date: '2018-06-14', temperature: 36.55, mucus: 2}, + { date: '2018-06-15', temperature: 36.6, mucus: 2}, + { date: '2018-06-16', temperature: 36.6, mucus: 2}, + { date: '2018-06-17', temperature: 36.55, mucus: 2}, + { date: '2018-06-18', temperature: 36.6, mucus: 1}, + { date: '2018-06-19', temperature: 36.7, mucus: 4}, + { date: '2018-06-20', temperature: 36.75, mucus: 1}, + { date: '2018-06-21', temperature: 36.8, mucus: 1}, + { date: '2018-06-22', temperature: 36.8, mucus: 1} ].map(convertToSymptoFormat) \ No newline at end of file diff --git a/test/sympto/index.spec.js b/test/sympto/index.spec.js index 7f653191..8f1df471 100644 --- a/test/sympto/index.spec.js +++ b/test/sympto/index.spec.js @@ -17,7 +17,8 @@ import { mucusPeakTwoDaysBeforeFhm, fhmOnDay12, fhmOnDay15, - mucusPeakSlightlyBeforeTempShift + mucusPeakSlightlyBeforeTempShift, + highestMucusQualityAfterEndOfEval } from './fixtures' const expect = chai.expect @@ -360,6 +361,40 @@ describe('sympto', () => { .filter(({date}) => date >= '2018-06-21') }) }) + + it('with highest quality after end of eval', () => { + const status = getSensiplanStatus({ + cycle: highestMucusQualityAfterEndOfEval, + previousCycle: cycleWithFhm + }) + + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: highestMucusQualityAfterEndOfEval + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-17', time: '18:00' }, + cycleDays: highestMucusQualityAfterEndOfEval + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-17' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-17', + time: '18:00' + }, + cycleDays: highestMucusQualityAfterEndOfEval + .filter(({date}) => date >= '2018-06-17') + }) + }) }) describe('applying the minus-8 rule', () => { -- GitLab