From 9102bce7ce059483f5ba30790f1f8e75e089ad90 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Thu, 5 Jul 2018 14:28:21 +0200 Subject: [PATCH] Return cycle phase starts --- lib/sympto/index.js | 22 ++++++++++++++++++---- test/sympto/index.spec.js | 21 +++++++++++++-------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/lib/sympto/index.js b/lib/sympto/index.js index b468f36..a4952bd 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -2,18 +2,32 @@ import getTemperatureShift from './temperature' import getMucusShift from './mucus' export default function (cycleDays) { - const assumeFertile = { assumeFertility: true } + const assumeFertileStatus = { assumeFertility: true } + // TODO second phase calculation + if (cycleDays.length) assumeFertileStatus.phases = [ + { + startDate: cycleDays[0].date, + startTime: '00:00' + }, + 'TODO' + ] const temperatureShift = getTemperatureShift(cycleDays) - if (!temperatureShift.detected) return assumeFertile + if (!temperatureShift.detected) return assumeFertileStatus const tempEvalEndIndex = cycleDays.indexOf(temperatureShift.evaluationCompleteDay) const mucusShift = getMucusShift(cycleDays, tempEvalEndIndex) - if (!mucusShift.detected) return assumeFertile + if (!mucusShift.detected) return assumeFertileStatus + + const phase2 = { + startDate: temperatureShift.evaluationCompleteDay.date, + startTime: '18:00' + } return { assumeFertility: false, temperatureShift, - mucusShift + mucusShift, + phases: assumeFertileStatus.phases.concat(phase2) } } \ No newline at end of file diff --git a/test/sympto/index.spec.js b/test/sympto/index.spec.js index bbea1ae..65550a0 100644 --- a/test/sympto/index.spec.js +++ b/test/sympto/index.spec.js @@ -4,18 +4,18 @@ import getSensiplanStatus from '../../lib/sympto' const expect = chai.expect function convertToSymptoFormat(val, i) { - return { - date: i, - temperature: val.temperature ? { value: val.temperature } : null, - mucus: val.mucus ? { value: val.mucus } : null - } + const sympto = { date: i } + if (val.temperature) sympto.temperature = { value: val.temperature } + if (val.mucus) sympto.mucus = { value: val.mucus } + if (val.bleeding) sympto.bleeding = { value: val.bleeding } + return sympto } describe('sympto', () => { describe('evaluating mucus and temperature shift together', () => { it('reports fertile when mucus reaches best quality again within temperature evaluation phase', function () { const values = [ - { temperature: 36.6 }, + { temperature: 36.6 , bleeding: 2 }, { temperature: 36.65 }, { temperature: 36.5 }, { temperature: 36.6 }, @@ -48,6 +48,11 @@ describe('sympto', () => { const status = getSensiplanStatus(temperatures) expect(status).to.eql({ assumeFertility: false, + phases: [ + { startDate: 0, startTime: '00:00'}, + 'TODO', + { startDate: 17, startTime: '18:00'} + ], temperatureShift: { detected: true, ltl: 36.55, @@ -60,7 +65,7 @@ describe('sympto', () => { evaluationCompleteDay: { date: 17, temperature: { value: 36.75 }, - mucus: { value: 4 } + mucus: { value: 4 }, } }, mucusShift: { @@ -68,7 +73,7 @@ describe('sympto', () => { mucusPeak: { date: 17, mucus: { value: 4 }, - temperature: { value: 36.75 } + temperature: { value: 36.75 }, } } })