From 3ff7dd734080ec9db7087b0f1a3109ce1c8b419e Mon Sep 17 00:00:00 2001 From: emelko Date: Fri, 31 Aug 2018 00:36:19 +0200 Subject: [PATCH 01/28] Merge branch 'master' --- README.md | 3 + components/chart/day-column.js | 3 +- components/chart/styles.js | 5 + components/home.js | 14 +- db/fixtures.js | 28 +- db/index.js | 34 +- lib/sympto/cervix.js | 41 ++ lib/sympto/index.js | 38 +- test/sympto/cervix-temp-fixtures.js | 215 ++++++ test/sympto/cervix-temp.spec.js | 199 ++++++ test/sympto/cervix.spec.js | 114 +++ test/sympto/index.spec.js | 660 ----------------- .../{fixtures.js => mucus-temp-fixtures.js} | 50 +- test/sympto/mucus-temp.spec.js | 661 ++++++++++++++++++ 14 files changed, 1359 insertions(+), 706 deletions(-) create mode 100644 lib/sympto/cervix.js create mode 100644 test/sympto/cervix-temp-fixtures.js create mode 100644 test/sympto/cervix-temp.spec.js create mode 100644 test/sympto/cervix.spec.js delete mode 100644 test/sympto/index.spec.js rename test/sympto/{fixtures.js => mucus-temp-fixtures.js} (92%) create mode 100644 test/sympto/mucus-temp.spec.js diff --git a/README.md b/README.md index a186717..466431e 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,6 @@ You can run the tests with `npm test`. ## Debugging When running into an old version of the app try to run the following command first: `react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res` + +## NFP rules +More information about how the app calculates fertility status and bleeding predictions in the [wiki on Gitlab](https://gitlab.com/bloodyhealth/drip/wikis/home) diff --git a/components/chart/day-column.js b/components/chart/day-column.js index 268df06..20fbcf8 100644 --- a/components/chart/day-column.js +++ b/components/chart/day-column.js @@ -29,6 +29,7 @@ export default class DayColumn extends Component { temperatureExclude, bleeding, mucus, + cervix, drawFhmLine, drawLtlAt, rightY, @@ -135,4 +136,4 @@ export default class DayColumn extends Component { ) } -} \ No newline at end of file +} diff --git a/components/chart/styles.js b/components/chart/styles.js index d7ab484..0b8a49c 100644 --- a/components/chart/styles.js +++ b/components/chart/styles.js @@ -61,6 +61,11 @@ const styles = { '#a64ca6', '#993299' ], + cervixIcon: { + width: 12, + height: 12, + borderRadius: 50 + }, yAxis: { width: config.columnWidth, borderRightWidth: 0.5, diff --git a/components/home.js b/components/home.js index 6f4ab05..1fa051d 100644 --- a/components/home.js +++ b/components/home.js @@ -8,7 +8,7 @@ import { import { LocalDate, ChronoUnit } from 'js-joda' import styles from '../styles/index' import cycleModule from '../lib/cycle' -import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithDummyData, deleteAll } from '../db' +import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithMucusDummyData, fillWithCervixDummyData, deleteAll } from '../db' import {bleedingPrediction as labels} from './labels' const getCycleDayNumber = cycleModule().getCycleDayNumber @@ -62,8 +62,14 @@ export default class Home extends Component { + + + @@ -107,4 +113,4 @@ function determinePredictionText() { } else { return labels.predictionStartedXDaysLeft(daysToEnd) } -} \ No newline at end of file +} diff --git a/db/fixtures.js b/db/fixtures.js index a9075f7..321c6df 100644 --- a/db/fixtures.js +++ b/db/fixtures.js @@ -1,6 +1,9 @@ function convertToSymptoFormat(val) { const sympto = { date: val.date } - if (val.temperature) sympto.temperature = { value: val.temperature, exclude: false } + if (val.temperature) sympto.temperature = { + value: val.temperature, + exclude: false + } if (val.mucus) sympto.mucus = { value: val.mucus, exclude: false, @@ -11,7 +14,7 @@ function convertToSymptoFormat(val) { return sympto } -export const cycleWithFhm = [ +export const cycleWithFhmMucus = [ { date: '2018-07-01', bleeding: 2 }, { date: '2018-07-02', bleeding: 1 }, { date: '2018-07-06', temperature: 36.2}, @@ -26,6 +29,27 @@ export const cycleWithFhm = [ { date: '2018-07-18', temperature: 36.9, mucus: 2 } ].map(convertToSymptoFormat).reverse() +export const cycleWithFhmCervix = [ + { date: '2018-08-01', bleeding: 2 }, + { date: '2018-08-02', bleeding: 1 }, + { date: '2018-08-03', bleeding: 0 }, + { date: '2018-08-04', bleeding: 0 }, + { date: '2018-08-05', temperature: 36.07 }, + { date: '2018-08-06', temperature: 36.2 }, + { date: '2018-08-07', temperature: 36.35 }, + { date: '2018-08-08', temperature: 36.4 }, + { date: '2018-08-09', temperature: 36.3 }, + { date: '2018-08-10', temperature: 36.45 }, + { date: '2018-08-11', temperature: 36.45 }, + { date: '2018-08-12', temperature: 36.7, cervix: { isClosed: false, isHard: false } }, + { date: '2018-08-13', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, + { date: '2018-08-14', temperature: 36.75, cervix: { isClosed: true, isHard: true } }, + { date: '2018-08-15', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, + { date: '2018-08-16', temperature: 36.95, cervix: { isClosed: true, isHard: true } }, + { date: '2018-08-17', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, + { date: '2018-08-18', temperature: 36.9, cervix: { isClosed: false, isHard: true } } +].map(convertToSymptoFormat).reverse() + export const longAndComplicatedCycle = [ { date: '2018-06-01', temperature: 36.6, bleeding: 2 }, { date: '2018-06-02', temperature: 36.65 }, diff --git a/db/index.js b/db/index.js index 1845674..433d000 100644 --- a/db/index.js +++ b/db/index.js @@ -2,7 +2,8 @@ import Realm from 'realm' import { LocalDate, ChronoUnit } from 'js-joda' import { cycleWithTempAndNoMucusShift, - cycleWithFhm, + cycleWithFhmMucus, + cycleWithFhmCervix, longAndComplicatedCycle } from './fixtures' @@ -179,9 +180,9 @@ function getCycleDay(localDate) { return db.objectForPrimaryKey('CycleDay', localDate) } -function fillWithDummyData() { +function fillWithMucusDummyData() { const dummyCycles = [ - cycleWithFhm, + cycleWithFhmMucus, longAndComplicatedCycle, cycleWithTempAndNoMucusShift ] @@ -204,6 +205,30 @@ function fillWithDummyData() { }) } +function fillWithCervixDummyData() { + const dummyCycles = [ + cycleWithFhmCervix + ] + + db.write(() => { + db.deleteAll() + dummyCycles.forEach(cycle => { + cycle.forEach(day => { + const existing = getCycleDay(day.date) + if (existing) { + Object.keys(day).forEach(key => { + if (key === 'date') return + existing[key] = day[key] + }) + } else { + db.create('CycleDay', day) + } + }) + }) + }) +} + + function deleteAll() { db.write(() => { db.deleteAll() @@ -266,7 +291,8 @@ export { bleedingDaysSortedByDate, temperatureDaysSortedByDate, cycleDaysSortedByDate, - fillWithDummyData, + fillWithMucusDummyData, + fillWithCervixDummyData, deleteAll, getPreviousTemperature, getCycleDay, diff --git a/lib/sympto/cervix.js b/lib/sympto/cervix.js new file mode 100644 index 0000000..01abe36 --- /dev/null +++ b/lib/sympto/cervix.js @@ -0,0 +1,41 @@ +export default function (cycleDays, tempEvalEndIndex) { + const cervixDays = cycleDays.filter(day => day.cervix && !day.cervix.exclude) + + for (let i = 0; i < cervixDays.length; i++) { + const day = cervixDays[i] + if (isClosedAndHard(day.cervix)) continue + // the three following days must be with closed and hard cervix + // AND no other cervix value may occur until temperature evaluation has + // been completed + const threeFollowingDays = cervixDays.slice(i + 1, i + 4) + if (threeFollowingDays.length < 3) continue + + const fertileCervixOccursIn3FollowingDays = threeFollowingDays.some(day => { + return !isClosedAndHard(day.cervix) + }) + if (fertileCervixOccursIn3FollowingDays) continue + + const cycleDayIndex = cycleDays.indexOf(day) + const relevantDays = cycleDays + .slice(cycleDayIndex + 1, tempEvalEndIndex + 1) + .filter(day => day.cervix && !day.cervix.exclude) + + const onlyClosedAndHardUntilEndOfTempEval = relevantDays.every(day => { + return isClosedAndHard(day.cervix) + }) + + if (onlyClosedAndHardUntilEndOfTempEval) { + return { + detected: true, + cervixPeak: day, + evaluationCompleteDay: threeFollowingDays[threeFollowingDays.length - 1] + } + } + } + + return { detected: false } +} + +function isClosedAndHard (cervixValue) { + return cervixValue.isClosed && cervixValue.isHard +} diff --git a/lib/sympto/index.js b/lib/sympto/index.js index c85b3ca..ccfbf32 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -1,11 +1,12 @@ import getTemperatureShift from './temperature' import getMucusShift from './mucus' +import getCervixShift from './cervix' import getPreOvulatoryPhase from './pre-ovulatory' import { LocalDate } from 'js-joda' import assert from 'assert' -export default function getSymptoThermalStatus(cycles) { - const { cycle, previousCycle, earlierCycles = [] } = cycles +export default function getSymptoThermalStatus(cycleInfo) { + const { cycle, previousCycle, earlierCycles = [], secondarySymptom = 'mucus' } = cycleInfo throwIfArgsAreNotInRequiredFormat([cycle, ...earlierCycles]) const status = { @@ -48,20 +49,28 @@ export default function getSymptoThermalStatus(cycles) { } const temperatureShift = getTemperatureShift(cycle) + if (!temperatureShift.detected) return status const tempEvalEndIndex = cycle.indexOf(temperatureShift.evaluationCompleteDay) - const mucusShift = getMucusShift(cycle, tempEvalEndIndex) - if (!mucusShift.detected) return status + + let secondaryShift + if (secondarySymptom === 'mucus') { + secondaryShift = getMucusShift(cycle, tempEvalEndIndex) + } else if (secondarySymptom === 'cervix') { + secondaryShift = getCervixShift(cycle, tempEvalEndIndex) + } + + if (!secondaryShift.detected) return status let periOvulatoryEnd const tempOver = temperatureShift.evaluationCompleteDay.date - const mucusOver = mucusShift.evaluationCompleteDay.date + const secondarySymptomOver = secondaryShift.evaluationCompleteDay.date - if (tempOver > mucusOver) { + if (tempOver > secondarySymptomOver) { periOvulatoryEnd = temperatureShift.evaluationCompleteDay } else { - periOvulatoryEnd = mucusShift.evaluationCompleteDay + periOvulatoryEnd = secondaryShift.evaluationCompleteDay } const previousPeriDays = periPhase.cycleDays @@ -78,7 +87,12 @@ export default function getSymptoThermalStatus(cycles) { periPhase.cycleDays = previousPeriDays.slice(0, previousPeriEndIndex + 1) periPhase.end = status.phases.postOvulatory.start - status.mucusShift = mucusShift + if (secondarySymptom === 'mucus') { + status.mucusShift = secondaryShift + } else if (secondarySymptom === 'cervix') { + status.cervixShift = secondaryShift + } + status.temperatureShift = temperatureShift return status @@ -87,9 +101,9 @@ export default function getSymptoThermalStatus(cycles) { function throwIfArgsAreNotInRequiredFormat(cycles) { cycles.forEach(cycle => { assert.ok(Array.isArray(cycle)) - assert.ok(cycle.length > 0) + assert.ok(cycle.length > 0) //what about 2 cycles of 1 day each?! assert.ok(cycle[0].bleeding !== null) - assert.equal(typeof cycle[0].bleeding, 'object') + assert.equal(typeof cycle[0].bleeding, 'object', "First cycle day must contain bleeding value") assert.equal(typeof cycle[0].bleeding.value, 'number') cycle.forEach(day => { assert.equal(typeof day.date, 'string') @@ -98,6 +112,8 @@ function throwIfArgsAreNotInRequiredFormat(cycles) { if (day.mucus) assert.equal(typeof day.mucus.value, 'number') if (day.mucus) assert.ok(day.mucus.value >= 0) if (day.mucus) assert.ok(day.mucus.value < 5) + if (day.cervix) assert.equal(typeof day.cervix.isClosed, 'boolean') + if (day.cervix) assert.equal(typeof day.cervix.isHard, 'boolean') }) }) -} \ No newline at end of file +} diff --git a/test/sympto/cervix-temp-fixtures.js b/test/sympto/cervix-temp-fixtures.js new file mode 100644 index 0000000..0d6d42c --- /dev/null +++ b/test/sympto/cervix-temp-fixtures.js @@ -0,0 +1,215 @@ + +function convertToSymptoFormat(val) { + const sympto = { date: val.date } + if (val.temperature) sympto.temperature = { + value: val.temperature, + exclude: false + } + if (val.cervix) sympto.cervix = { + value: val.cervix, + exclude: false + } + if (val.bleeding) sympto.bleeding = { + value: val.bleeding, + exclude: false + } + return sympto +} + +export const idealCycle = [ + { date: '2018-08-01', bleeding: 1, cervix: { isClosed: false, isHard: false } }, + { date: '2018-08-02', bleeding: 2, cervix: { isClosed: false, isHard: false } }, + { date: '2018-08-03', temperature: 36.6, bleeding: 2, cervix: { isClosed: false, isHard: false } }, + { date: '2018-08-04', temperature: 36.55, bleeding: 1, cervix: { isClosed: false, isHard: true } }, + { date: '2018-08-05', temperature: 36.6, bleeding: null, cervix: { isClosed: true, isHard: false } }, + { date: '2018-08-06', temperature: 36.65, bleeding: null, cervix: { isClosed: true, isHard: false } }, + { date: '2018-08-07', temperature: 36.7, bleeding: null, cervix: { isClosed: false, isHard: true } }, + { date: '2018-08-08', temperature: 36.6, bleeding: null, cervix: { isClosed: true, isHard: false } }, + { date: '2018-08-09', temperature: 36.8, bleeding: null, cervix: { isClosed: true, isHard: true } }, + { date: '2018-08-10', temperature: 36.75, bleeding: null, cervix: { isClosed: true, isHard: true } }, + { date: '2018-08-11', temperature: 36.9, bleeding: null, cervix: { isClosed: true, isHard: true } }, + { date: '2018-08-12', temperature: 36.95, bleeding: null, cervix: { isClosed: true, isHard: true } }, + { date: '2018-08-13', temperature: 36.95, bleeding: null, cervix: { isClosed: true, isHard: true } } +].map(convertToSymptoFormat) + +export const cycleWithFhmNoCervixShift = [ + { 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-08', temperature: 36.7 }, + { date: '2018-06-09', temperature: 36.7 }, + { date: '2018-06-10', temperature: 36.7 }, + { date: '2018-06-11', temperature: 36.7 }, + { date: '2018-06-12', temperature: 36.7 }, + { date: '2018-06-13', temperature: 36.8 }, + { date: '2018-06-15', temperature: 36.9 }, + { date: '2018-06-16', temperature: 36.9 }, + { date: '2018-06-17', temperature: 36.9 }, + { date: '2018-06-18', temperature: 36.9 } +].map(convertToSymptoFormat) + +export const cycleWithoutFhm = [ + { date: '2018-06-02', temperature: 36.6, bleeding: 2 }, + { date: '2018-06-03', temperature: 36.65 }, + { date: '2018-06-04', temperature: 36.6 }, + { date: '2018-06-05', temperature: 36.55 }, + { date: '2018-06-06', temperature: 36.7, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-09', temperature: 36.8, cervix: { isClosed: true, isHard: false } }, + { date: '2018-06-10', temperature: 36.9, cervix: { isClosed: false, isHard: true } }, + { date: '2018-06-13', temperature: 36.9, cervix: { isClosed: false, isHard: false } } +].map(convertToSymptoFormat) + +export const cycleWithoutAnyShifts = [ + { date: '2018-07-01', temperature: 36.65, bleeding: 2, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-02', temperature: 36.45, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-03', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-04', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-05', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-06', temperature: 36.85, cervix: { isClosed: true, isHard: false } }, + { date: '2018-07-07', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-08', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-09', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-10', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-11', temperature: 36.35, cervix: { isClosed: true, isHard: true } }, + { date: '2018-07-12', temperature: 36.65, cervix: { isClosed: true, isHard: true } }, + { date: '2018-07-13', temperature: 36.25, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-14', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-15', temperature: 36.65, cervix: { isClosed: false, isHard: true } }, + { date: '2018-07-16', temperature: 36.15, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-17', temperature: 36.65, cervix: { isClosed: true, isHard: false } }, + { date: '2018-07-18', temperature: 36.25, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-19', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-20', temperature: 36.45, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-21', temperature: 36.5, cervix: { isClosed: true, isHard: true } }, + { date: '2018-07-22', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-23', temperature: 36.75, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-24', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-25', temperature: 36.65, cervix: { isClosed: true, isHard: false } }, + { date: '2018-07-26', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, +].map(convertToSymptoFormat) + +export const longAndComplicatedCycle = [ + { 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, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-09', temperature: 36.5, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-10', temperature: 36.4, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-13', temperature: 36.45, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-14', temperature: 36.5, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-15', temperature: 36.55, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-16', temperature: 36.7, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-17', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-18', temperature: 36.75, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-19', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-20', temperature: 36.85, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-21', temperature: 36.8, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-22', temperature: 36.9, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-25', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-26', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-27', temperature: 36.9, cervix: { isClosed: true, isHard: true } } +].map(convertToSymptoFormat) + +export const tempAndCervixEvalEndOnSameDay = [ + { date: '2018-06-01', bleeding: 2 }, + { date: '2018-06-02', bleeding: 1 }, + { date: '2018-06-03', bleeding: 1 }, + { date: '2018-06-04', bleeding: 2 }, + { date: '2018-06-05', bleeding: 1 }, + { date: '2018-06-06', bleeding: 1 }, + { date: '2018-06-07', cervix: { isClosed: false, isHard: true } }, + { date: '2018-06-08', temperature: 36.45, cervix: { isClosed: true, isHard: false } }, + { date: '2018-06-09', temperature: 36.5, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-10', temperature: 36.30, cervix: { isClosed: true, isHard: false } }, + { date: '2018-06-11', temperature: 36.30, cervix: { isClosed: false, isHard: true } }, + { date: '2018-06-12', temperature: 36.4, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-13', temperature: 36.3, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-14', temperature: 36.4, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-15', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-16', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-17', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-18', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-19', temperature: 36.95, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-20', temperature: 37.0, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-21', temperature: 37.0, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-22', temperature: 37.0, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-23', cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-24', cervix: { isClosed: true, isHard: true }}, + { date: '2018-06-25', cervix: { isClosed: false, isHard: false } } +].map(convertToSymptoFormat) + +export const cervixShiftWaitsForTempShift = [ + { date: '2018-05-08', bleeding: 3 }, + { date: '2018-05-09', bleeding: 2 }, + { date: '2018-05-10', bleeding: 2 }, + { date: '2018-05-11', bleeding: 1 }, + { date: '2018-05-12', temperature: 36.3, cervix: { isClosed: false, isHard: false } }, + { date: '2018-05-13', temperature: 36.4, cervix: { isClosed: false, isHard: false } }, + { date: '2018-05-14', temperature: 36.3, cervix: { isClosed: false, isHard: false } }, + { date: '2018-05-15', temperature: 36.2, cervix: { isClosed: false, isHard: false } }, + { date: '2018-05-16', temperature: 36.3, cervix: { isClosed: true, isHard: true } }, + { date: '2018-05-17', temperature: 36.3, cervix: { isClosed: true, isHard: true } }, + { date: '2018-05-18', temperature: 36.55, cervix: { isClosed: true, isHard: true } }, + { date: '2018-05-19', temperature: 36.65, cervix: { isClosed: true, isHard: true } }, + { date: '2018-05-20', temperature: 36.7, cervix: { isClosed: true, isHard: true } }, + { date: '2018-05-21', temperature: 36.6, cervix: { isClosed: true, isHard: true } }, + { date: '2018-05-22', temperature: 36.85, cervix: { isClosed: true, isHard: true } }, + { date: '2018-05-23', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, + { date: '2018-05-24', temperature: 36.85, cervix: { isClosed: true, isHard: true } }, + { date: '2018-05-25', temperature: 36.95, cervix: { isClosed: true, isHard: true } }, + { date: '2018-05-26', temperature: 36.85, cervix: { isClosed: true, isHard: false } }, + { date: '2018-05-27', temperature: 36.8, cervix: { isClosed: false, isHard: true } }, + { date: '2018-05-28', temperature: 36.6, cervix: { isClosed: false, isHard: true } }, + { date: '2018-05-29', bleeding: 2 } +].map(convertToSymptoFormat) + +export const tempShiftWaitsForCervixShift = [ + { 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, cervix: { isClosed: false, isHard: false } }, + { date: '2018-04-10', temperature: 36.5, cervix: { isClosed: false, isHard: false } }, + { date: '2018-04-11', temperature: 36.55, cervix: { isClosed: false, isHard: false } }, + { date: '2018-04-12', temperature: 36.5, cervix: { isClosed: false, isHard: false } }, + { date: '2018-04-13', temperature: 36.35, cervix: { isClosed: false, isHard: false } }, + { date: '2018-04-14', temperature: 36.35, cervix: { isClosed: false, isHard: false } }, + { date: '2018-04-15', temperature: 36.6, cervix: { isClosed: false, isHard: false } }, + { date: '2018-04-16', temperature: 36.8, cervix: { isClosed: false, isHard: false } }, + { date: '2018-04-17', cervix: { isClosed: false, isHard: false } }, + { date: '2018-04-18', temperature: 36.8, cervix: { isClosed: false, isHard: true } }, + { date: '2018-04-19', temperature: 36.85, cervix: { isClosed: true, isHard: true } }, + { date: '2018-04-20', temperature: 37.0, cervix: { isClosed: true, isHard: true } }, + { date: '2018-04-21', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, + { date: '2018-04-22', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, + { date: '2018-04-23', temperature: 37.1, cervix: { isClosed: true, isHard: true } }, + { date: '2018-04-24', temperature: 36.75, cervix: { isClosed: false, isHard: false } } +].map(convertToSymptoFormat) + +export const noInfertilePhaseDetected = [ + { date: '2018-03-08', bleeding: 3 }, + { date: '2018-03-09', bleeding: 3 }, + { date: '2018-03-10', bleeding: 3 }, + { date: '2018-03-11', bleeding: 3 }, + { date: '2018-03-12', temperature: 36.3, cervix: { isClosed: true, isHard: false } }, + { date: '2018-03-13', temperature: 36.5, cervix: { isClosed: false, isHard: false } }, + { date: '2018-03-14', temperature: 36.45, cervix: { isClosed: false, isHard: false } }, + { date: '2018-03-15', temperature: 36.4, cervix: { isClosed: false, isHard: false } }, + { date: '2018-03-16', temperature: 36.2, cervix: { isClosed: false, isHard: false } }, + { date: '2018-03-17', temperature: 36.5, cervix: { isClosed: false, isHard: false } }, + { date: '2018-03-18', temperature: 36.6, cervix: { isClosed: false, isHard: false } }, + { date: '2018-03-19', temperature: 36.35, cervix: { isClosed: false, isHard: true } }, + { date: '2018-03-20', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, + { date: '2018-03-21', temperature: 36.7, cervix: { isClosed: true, isHard: true } }, + { date: '2018-03-22', temperature: 36.7, cervix: { isClosed: true, isHard: false } }, + { date: '2018-03-23', temperature: 36.7, cervix: { isClosed: true, isHard: true } } +].map(convertToSymptoFormat) + +export const fiveDayCycle = [ + { date: '2018-08-01', bleeding: 2 }, + { date: '2018-08-03', bleeding: 3 }, + { date: '2018-08-05', bleeding: 0 } +].map(convertToSymptoFormat) diff --git a/test/sympto/cervix-temp.spec.js b/test/sympto/cervix-temp.spec.js new file mode 100644 index 0000000..a610d65 --- /dev/null +++ b/test/sympto/cervix-temp.spec.js @@ -0,0 +1,199 @@ +import chai from 'chai' +import getSensiplanStatus from '../../lib/sympto' +import { + idealCycle, + cycleWithFhmNoCervixShift, + cycleWithoutFhm, + cycleWithoutAnyShifts, + tempAndCervixEvalEndOnSameDay, + cervixShiftWaitsForTempShift, + tempShiftWaitsForCervixShift, + noInfertilePhaseDetected, + fiveDayCycle +} from './cervix-temp-fixtures' + +const expect = chai.expect + +describe('sympto', () => { + describe('combining temperature and cervix tracking', () => { + describe('with no previous higher temp measurement', () => { + + it('with no temp or cervix shifts detects only peri-ovulatory', function () { + const status = getSensiplanStatus({ + cycle: cycleWithoutAnyShifts, + previousCycle: cycleWithoutFhm, + secondarySymptom: 'cervix' + }) + expect(Object.keys(status.phases).length).to.eql(1) + expect(status).to.eql({ + phases: { + periOvulatory: { + start: { date: '2018-07-01' }, + cycleDays: cycleWithoutAnyShifts + } + } + }) + }) + + it('with temp but no cervix shift detects only peri-ovulatory', function () { + const status = getSensiplanStatus({ + cycle: cycleWithFhmNoCervixShift, + previousCycle: cycleWithoutFhm, + secondarySymptom: 'cervix' + }) + expect(Object.keys(status.phases).length).to.eql(1) + expect(status).to.eql({ + phases: { + periOvulatory: { + start: { date: '2018-06-01' }, + cycleDays: cycleWithFhmNoCervixShift + } + } + }) + }) + + it('with temp and cervix shifts detects only peri- and post-ovulatory phases', function () { + const status = getSensiplanStatus({ + cycle: idealCycle, + previousCycle: cycleWithoutFhm, + secondarySymptom: 'cervix' + }) + + expect(status.temperatureShift).to.be.an('object') + expect(status.cervixShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-08-01' }, + end: { date: '2018-08-11', time: '18:00' }, + cycleDays: idealCycle + .filter(({date}) => date <= '2018-08-11') + }) + expect(status.phases.postOvulatory).to.eql({ + start: { date: '2018-08-11', time: '18:00' }, + cycleDays: idealCycle + .filter(({date}) => date >= '2018-08-11') + }) + }) + + }) + describe('with previous higher temp measurement', () => { + + describe('with no shifts detects only peri-ovulatory', function () { + it.skip('according to 5-day rule', function () { + const status = getSensiplanStatus({ + cycle: fiveDayCycle, + previousCycle: cycleWithFhmNoCervixShift + }) + + expect(Object.keys(status.phases).length).to.eql(1) + expect(status.phases.preOvulatory).to.eql({ + cycleDays: fiveDayCycle, + start: { date: '2018-08-01' }, + end: { date: '2018-08-05' } + }) + }) + }) + + describe('with no shifts detects pre- and peri-ovulatory phase', () => { + it.skip('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: cycleWithoutAnyShifts, + previousCycle: cycleWithFhmNoCervixShift + }) + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.preOvulatory).to.eql({ + cycleDays: cycleWithoutAnyShifts + .filter(({date}) => date <= '2018-07-05'), + start: { date: '2018-07-01' }, + end: { date: '2018-07-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: cycleWithoutAnyShifts + .filter(({date}) => date > '2018-07-05'), + start: { date: '2018-07-06' } + }) + }) + }) + + it('with evaluation of temperature and cervix end on same day', () => { + const status = getSensiplanStatus({ + cycle: tempAndCervixEvalEndOnSameDay, + previousCycle: cycleWithFhmNoCervixShift, + secondarySymptom: 'cervix' + }) + 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: tempAndCervixEvalEndOnSameDay + .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: tempAndCervixEvalEndOnSameDay + .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: tempAndCervixEvalEndOnSameDay + .filter(({date}) => date >= '2018-06-17') + }) + expect(status.cervixShift.detected).to.be.true() + expect(status.cervixShift.cervixPeak.date).to.eql('2018-06-14') + expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-06-17') + }) + + + it('when cervix shift waits for temperature shift', () => { + const status = getSensiplanStatus({ + cycle: cervixShiftWaitsForTempShift, + previousCycle: cycleWithFhmNoCervixShift, + secondarySymptom: 'cervix' + }) + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.cervixShift.detected).to.be.true() + }) + + it('when temperature shift waits for cervix shift', () => { + const status = getSensiplanStatus({ + cycle: tempShiftWaitsForCervixShift, + previousCycle: cycleWithFhmNoCervixShift, + secondarySymptom: 'cervix' + }) + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.cervixShift.detected).to.be.true() + }) + + it('when no infertile phase can be detected', () => { + const status = getSensiplanStatus({ + cycle: noInfertilePhaseDetected, + previousCycle: cycleWithFhmNoCervixShift, + secondarySymptom: 'cervix' + }) + expect(Object.keys(status.phases).length).to.eql(2) + }) + + }) + + it('', function () { + const status = getSensiplanStatus({ + cycle: idealCycle, + previousCycle: idealCycle, + secondarySymptom: 'cervix' + }) + + expect(Object.keys(status.phases).length).to.eql() + expect(status).to.eql({ + phases: { + + } + }) + }) + + }) +}) diff --git a/test/sympto/cervix.spec.js b/test/sympto/cervix.spec.js new file mode 100644 index 0000000..9bcc2a2 --- /dev/null +++ b/test/sympto/cervix.spec.js @@ -0,0 +1,114 @@ +import chai from 'chai' +import getCervixStatus from '../../lib/sympto/cervix' + +const expect = chai.expect + +function turnIntoCycleDayObject(value, fakeDate) { + const hardAndClosed = { + isHard: true, + isClosed: true + } + const hardAndOpen = { + isHard: true, + isClosed: false + } + const softAndClosed = { + isHard: false, + isClosed: true + } + const softAndOpen = { + isHard: false, + isClosed: false + } + const cervixStates = [hardAndClosed, hardAndOpen, softAndClosed, softAndOpen] + return { + cervix : cervixStates[value], + date: fakeDate + } +} + +describe('sympto', () => { + describe('detects cervix shift', () => { + it('when an ideal cycle happens', function () { + const values = [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 0, 0, 0, 0] + .map(turnIntoCycleDayObject) + const status = getCervixStatus(values) + expect(status).to.eql({ + detected: true, + cervixPeak: { + date: 13, + cervix: { + isHard: true, + isClosed: false + } + }, + evaluationCompleteDay: { + date: 16, + cervix: { + isHard: true, + isClosed: true + } + } + }) + }) + + it('at the very first day of cycle days even if later shift happens again', function () { + const values = [2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + .map(turnIntoCycleDayObject) + const status = getCervixStatus(values) + expect(status).to.eql({ + detected: true, + cervixPeak: { + date: 0, + cervix: { + isHard: false, + isClosed: true + } + }, + evaluationCompleteDay: { + date: 3, + cervix: { + isHard: true, + isClosed: true + } + } + }) + }) + }) + + describe('detects no cervix shift', () => { + it('if there are less than 3 days closed and hard cervix', function () { + const values = [0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 3, 1, 1, 1, 0, 0, 2, 0] + .map(turnIntoCycleDayObject) + const status = getCervixStatus(values) + expect(status).to.eql({ detected: false }) + }) + + it('if there are no cervix values', function () { + const values = [].map(turnIntoCycleDayObject) + const status = getCervixStatus(values) + expect(status).to.eql({ detected: false }) + }) + + it('when the cervix values are all the same', function () { + const values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + .map(turnIntoCycleDayObject) + const status = getCervixStatus(values) + expect(status).to.eql({ detected: false }) + }) + + it('if no days of hard and closed cervix are tracked', function () { + const values = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1] + .map(turnIntoCycleDayObject) + const status = getCervixStatus(values) + expect(status).to.eql({ detected: false }) + }) + + it('if days of hard and closed cervix are fewer than 3', function () { + const values = [1, 3, 2, 1, 0, 2, 1, 3, 2, 0, 0, 2, 1, 3, 2, 1] + .map(turnIntoCycleDayObject) + const status = getCervixStatus(values) + expect(status).to.eql({ detected: false }) + }) + }) +}) diff --git a/test/sympto/index.spec.js b/test/sympto/index.spec.js deleted file mode 100644 index 8f1df47..0000000 --- a/test/sympto/index.spec.js +++ /dev/null @@ -1,660 +0,0 @@ -import chai from 'chai' -import getSensiplanStatus from '../../lib/sympto' -import { AssertionError } from 'assert' -import { - cycleWithoutFhm, - longAndComplicatedCycle, - cycleWithTempAndNoMucusShift, - cycleWithFhm, - cycleWithoutAnyShifts, - fiveDayCycle, - cycleWithEarlyMucus, - cycleWithMucusOnFirstDay, - mucusPeakAndFhmOnSameDay, - fhmTwoDaysBeforeMucusPeak, - fhm5DaysAfterMucusPeak, - mucusPeak5DaysAfterFhm, - mucusPeakTwoDaysBeforeFhm, - fhmOnDay12, - fhmOnDay15, - mucusPeakSlightlyBeforeTempShift, - highestMucusQualityAfterEndOfEval -} from './fixtures' - -const expect = chai.expect - -describe('sympto', () => { - describe('with no previous higher measurement', () => { - it('with no shifts detects only peri-ovulatory', function () { - const status = getSensiplanStatus({ - cycle: cycleWithoutAnyShifts, - previousCycle: cycleWithoutFhm - }) - - expect(status).to.eql({ - - phases: { - periOvulatory: { - start: { date: '2018-06-01' }, - cycleDays: cycleWithoutAnyShifts - } - }, - }) - }) - - it('with shifts detects only peri-ovulatory and post-ovulatory', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm - }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-21') - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - describe('with previous higher measurement', () => { - describe('with no shifts detects pre-ovulatory phase', function () { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: fiveDayCycle, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(1) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: fiveDayCycle, - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - }) - - }) - describe('with no shifts detects pre- and peri-ovulatory phase', () => { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: cycleWithTempAndNoMucusShift, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date > '2018-06-05'), - start: { date: '2018-06-06' } - }) - }) - it('according to 5-day-rule with shortened pre-phase', function () { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - - 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 () { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(3) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00'} - }) - expect(status.phases.postOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21'), - start: { date: '2018-06-21', time: '18:00'} - }) - }) - - }) - }) - - describe('combining first higher measurment and mucus peak', () => { - it('with fhM + mucus peak on same day finds start of postovu phase', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakAndFhmOnSameDay, - 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: mucusPeakAndFhmOnSameDay - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: mucusPeakAndFhmOnSameDay - .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, - 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: fhmTwoDaysBeforeMucusPeak - .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 - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-26' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-26', - time: '18:00' - }, - cycleDays: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => date >= '2018-06-26') - }) - }) - - it('another example for mucus peak before temp shift', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakSlightlyBeforeTempShift, - 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: mucusPeakSlightlyBeforeTempShift - .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: mucusPeakSlightlyBeforeTempShift - .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: mucusPeakSlightlyBeforeTempShift - .filter(({date}) => date >= '2018-06-17') - }) - }) - - it('with another mucus peak 5 days after fHM ignores it', () => { - const status = getSensiplanStatus({ - cycle: mucusPeak5DaysAfterFhm, - 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-01' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - end: { date: '2018-06-22', time: '18:00' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => { - return date > '2018-06-01' && date <= '2018-06-22' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-22', - time: '18:00' - }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date >= '2018-06-22') - }) - }) - - it('with mucus peak 2 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakTwoDaysBeforeFhm, - 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-04' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-07-03', time: '18:00' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-07-03' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-07-03', - time: '18:00' - }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date >= '2018-07-03') - }) - }) - - it('with mucus peak 5 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: fhm5DaysAfterMucusPeak, - 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: fhm5DaysAfterMucusPeak - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: fhm5DaysAfterMucusPeak - .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', () => { - it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] - }) - - 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-04' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - it('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - 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-04' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - it('shortens the pre-ovu phase if mucus occurs', () => { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-01' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => { - return date > '2018-06-01' - }) - }) - }) - - it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { - const status = getSensiplanStatus({ - cycle: cycleWithMucusOnFirstDay, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - - expect(Object.keys(status.phases).length).to.eql(1) - - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - cycleDays: cycleWithMucusOnFirstDay - }) - }) - - it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(11).fill(fhmOnDay15) - }) - - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-07' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-07') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-08' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-07' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('does not lengthen the pre-ovu phase if < 12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(10).fill(fhmOnDay15) - }) - - - 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: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm, - earlierCycles: [...Array(12).fill(fhmOnDay15)] - }) - - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date >= '2018-06-01' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - - describe('when args are wrong', () => { - it('throws when arg object is not in right format', () => { - const wrongObject = { hello: 'world' } - expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) - }) - it('throws if cycle array is empty', () => { - expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) - }) - it('throws if cycle days are not in right format', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - hello: 'world', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2018-04-13', - temperature: {value: '35'}, - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '09-14-2017', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - }) - it('throws if first cycle day does not have bleeding value', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2017-01-01', - bleeding: { - value: 'medium' - } - }], - earlierCycles: [[ - { - date: '2017-09-23', - } - ]] - })).to.throw(AssertionError) - }) - }) -}) \ No newline at end of file diff --git a/test/sympto/fixtures.js b/test/sympto/mucus-temp-fixtures.js similarity index 92% rename from test/sympto/fixtures.js rename to test/sympto/mucus-temp-fixtures.js index 0bb4f9f..c313629 100644 --- a/test/sympto/fixtures.js +++ b/test/sympto/mucus-temp-fixtures.js @@ -15,7 +15,7 @@ export const cycleWithFhm = [ { date: '2018-06-06', temperature: 36.7, mucus: 0 }, { date: '2018-06-13', temperature: 36.8, mucus: 4 }, { date: '2018-06-15', temperature: 36.9, mucus: 2 }, - { date: '2018-06-17', temperature: 36.9, mucus: 2 }, + { date: '2018-06-16', temperature: 36.9, mucus: 2 }, { date: '2018-06-17', temperature: 36.9, mucus: 2 }, { date: '2018-06-18', temperature: 36.9, mucus: 2 } ].map(convertToSymptoFormat) @@ -227,6 +227,31 @@ export const mucusPeak5DaysAfterFhm = [ { date: '2018-07-02', temperature: 36.9, mucus: 1 } ].map(convertToSymptoFormat) +export const highestMucusQualityAfterEndOfEval = [ + { date: '2018-06-01', temperature: 36.6, bleeding: 2 }, + { date: '2018-06-02', temperature: 36.65, mucus: 2 }, + { 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: 3 }, + { date: '2018-06-14', temperature: 36.5, mucus: 3 }, + { date: '2018-06-15', temperature: 36.55, mucus: 3 }, + { date: '2018-06-16', temperature: 36.7, mucus: 3 }, + { date: '2018-06-17', temperature: 36.65, mucus: 3 }, + { date: '2018-06-18', temperature: 36.60, mucus: 2 }, + { date: '2018-06-19', temperature: 36.8, mucus: 3 }, + { date: '2018-06-20', temperature: 36.85, mucus: 3 }, + { date: '2018-06-21', temperature: 36.8, mucus: 3 }, + { date: '2018-06-22', temperature: 36.9, mucus: 1 }, + { date: '2018-06-25', temperature: 36.9, mucus: 1 }, + { 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: 4 }, + { date: '2018-07-02', temperature: 36.9, mucus: 1 } +].map(convertToSymptoFormat) + export const fhm5DaysAfterMucusPeak = [ { date: '2018-06-01', temperature: 36.6, bleeding: 2 }, { date: '2018-06-02', temperature: 36.65 }, @@ -299,26 +324,3 @@ 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 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/mucus-temp.spec.js b/test/sympto/mucus-temp.spec.js new file mode 100644 index 0000000..92f346d --- /dev/null +++ b/test/sympto/mucus-temp.spec.js @@ -0,0 +1,661 @@ +import chai from 'chai' +import getSensiplanStatus from '../../lib/sympto' +import { AssertionError } from 'assert' +import { + cycleWithoutFhm, + longAndComplicatedCycle, + cycleWithTempAndNoMucusShift, + cycleWithFhm, + cycleWithoutAnyShifts, + fiveDayCycle, + cycleWithEarlyMucus, + cycleWithMucusOnFirstDay, + mucusPeakAndFhmOnSameDay, + fhmTwoDaysBeforeMucusPeak, + fhm5DaysAfterMucusPeak, + mucusPeak5DaysAfterFhm, + mucusPeakTwoDaysBeforeFhm, + fhmOnDay12, + fhmOnDay15, + mucusPeakSlightlyBeforeTempShift, + highestMucusQualityAfterEndOfEval +} from './mucus-temp-fixtures' + +const expect = chai.expect + +describe('sympto', () => { + describe('combining temperature and mucus tracking', () => { + describe('with no previous higher temp measurement', () => { + + it('with no shifts detects only peri-ovulatory', function () { + const status = getSensiplanStatus({ + cycle: cycleWithoutAnyShifts, + previousCycle: cycleWithoutFhm + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + cycleDays: cycleWithoutAnyShifts + }) + }) + + it('with temp and mucus shifts detects only peri-ovulatory and post-ovulatory', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm + }) + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-21') + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + + }) + }) + + describe('with previous higher measurement', () => { + describe('with no shifts detects pre-ovulatory phase', function () { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: fiveDayCycle, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(1) + expect(status.phases.preOvulatory).to.eql({ + cycleDays: fiveDayCycle, + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + }) + }) + describe('with no shifts detects pre- and peri-ovulatory phase', () => { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: cycleWithTempAndNoMucusShift, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(2) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date <= '2018-06-05'), + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date > '2018-06-05'), + start: { date: '2018-06-06' } + }) + }) + it('according to 5-day-rule with shortened pre-phase', function () { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(2) + + 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 () { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(3) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05'), + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00'} + }) + expect(status.phases.postOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21'), + start: { date: '2018-06-21', time: '18:00'} + }) + }) + + }) + }) + + describe('combining first higher measurment and mucus peak', () => { + it('with fhM + mucus peak on same day finds start of postovu phase', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakAndFhmOnSameDay, + 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: mucusPeakAndFhmOnSameDay + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: mucusPeakAndFhmOnSameDay + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: mucusPeakAndFhmOnSameDay + .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, + 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: fhmTwoDaysBeforeMucusPeak + .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 + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-26' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-26', + time: '18:00' + }, + cycleDays: fhmTwoDaysBeforeMucusPeak + .filter(({date}) => date >= '2018-06-26') + }) + }) + + it('another example for mucus peak before temp shift', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakSlightlyBeforeTempShift, + 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: mucusPeakSlightlyBeforeTempShift + .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: mucusPeakSlightlyBeforeTempShift + .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: mucusPeakSlightlyBeforeTempShift + .filter(({date}) => date >= '2018-06-17') + }) + }) + + it('with another mucus peak 5 days after fHM ignores it', () => { + const status = getSensiplanStatus({ + cycle: mucusPeak5DaysAfterFhm, + 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-01' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + end: { date: '2018-06-22', time: '18:00' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => { + return date > '2018-06-01' && date <= '2018-06-22' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-22', + time: '18:00' + }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date >= '2018-06-22') + }) + }) + + it('with mucus peak 2 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakTwoDaysBeforeFhm, + 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-04' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-07-03', time: '18:00' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-07-03' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-07-03', + time: '18:00' + }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date >= '2018-07-03') + }) + }) + + it('with mucus peak 5 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: fhm5DaysAfterMucusPeak, + 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: fhm5DaysAfterMucusPeak + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) + + describe('applying the minus-8 rule', () => { + it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] + }) + + 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-04' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + // #TODO + it.only('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + 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: fhm5DaysAfterMucusPeak + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date >= '2018-06-21') + }) + }) + + // #TODO + 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-26', time: '18:00' }, + cycleDays: highestMucusQualityAfterEndOfEval + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-26' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-26', + time: '18:00' + }, + cycleDays: highestMucusQualityAfterEndOfEval + .filter(({date}) => date >= '2018-06-26') + }) + }) + }) + + describe('something', () => { + + it('shortens the pre-ovu phase if mucus occurs', () => { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-01' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => { + return date > '2018-06-01' + }) + }) + }) + + it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { + const status = getSensiplanStatus({ + cycle: cycleWithMucusOnFirstDay, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + + expect(Object.keys(status.phases).length).to.eql(1) + + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + cycleDays: cycleWithMucusOnFirstDay + }) + }) + + it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(11).fill(fhmOnDay15) + }) + + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-07' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-07') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-08' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-07' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + + it('does not lengthen the pre-ovu phase if < 12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(10).fill(fhmOnDay15) + }) + + + 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: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + + it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm, + earlierCycles: [...Array(12).fill(fhmOnDay15)] + }) + + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date >= '2018-06-01' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) + + describe('when args are wrong', () => { + it('throws when arg object is not in right format', () => { + const wrongObject = { hello: 'world' } + expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) + }) + it('throws if cycle array is empty', () => { + expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) + }) + it('throws if cycle days are not in right format', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + hello: 'world', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2018-04-13', + temperature: {value: '35'}, + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '09-14-2017', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + }) + it('throws if first cycle day does not have bleeding value', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2017-01-01', + bleeding: { + value: 'medium' + } + }], + earlierCycles: [[ + { + date: '2017-09-23', + } + ]] + })).to.throw(AssertionError) + }) + }) + }) +}) From 60d6e21c5706be65a680425916407a0f0eb9c45d Mon Sep 17 00:00:00 2001 From: emelko Date: Wed, 25 Jul 2018 15:50:41 +0200 Subject: [PATCH 03/28] Detects cervix shift in one happy path; including test --- test/sympto/index.spec.js | 660 +++++++++++++++++++++++++++++ test/sympto/mucus-temp-fixtures.js | 8 + 2 files changed, 668 insertions(+) create mode 100644 test/sympto/index.spec.js diff --git a/test/sympto/index.spec.js b/test/sympto/index.spec.js new file mode 100644 index 0000000..88ada86 --- /dev/null +++ b/test/sympto/index.spec.js @@ -0,0 +1,660 @@ +import chai from 'chai' +import getSensiplanStatus from '../../lib/sympto' +import { AssertionError } from 'assert' +import { + cycleWithoutFhm, + longAndComplicatedCycle, + cycleWithTempAndNoMucusShift, + cycleWithFhm, + cycleWithoutAnyShifts, + fiveDayCycle, + cycleWithEarlyMucus, + cycleWithMucusOnFirstDay, + mucusPeakAndFhmOnSameDay, + fhmTwoDaysBeforeMucusPeak, + fhm5DaysAfterMucusPeak, + mucusPeak5DaysAfterFhm, + mucusPeakTwoDaysBeforeFhm, + fhmOnDay12, + fhmOnDay15, + mucusPeakSlightlyBeforeTempShift, + tempAndCervixEvalEndOnSameDay +} from './fixtures' + +const expect = chai.expect + +describe('sympto', () => { + describe('with no previous higher measurement', () => { + it('with no shifts detects only peri-ovulatory', function () { + const status = getSensiplanStatus({ + cycle: cycleWithoutAnyShifts, + previousCycle: cycleWithoutFhm + }) + + expect(status).to.eql({ + + phases: { + periOvulatory: { + start: { date: '2018-06-01' }, + cycleDays: cycleWithoutAnyShifts + } + }, + }) + }) + + it('with shifts detects only peri-ovulatory and post-ovulatory', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm + }) + + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-21') + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) + describe('with previous higher measurement', () => { + describe('with no shifts detects pre-ovulatory phase', function () { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: fiveDayCycle, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(1) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: fiveDayCycle, + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + }) + + }) + describe('with no shifts detects pre- and peri-ovulatory phase', () => { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: cycleWithTempAndNoMucusShift, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(2) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date <= '2018-06-05'), + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date > '2018-06-05'), + start: { date: '2018-06-06' } + }) + }) + it('according to 5-day-rule with shortened pre-phase', function () { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(2) + + 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 () { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(3) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05'), + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00'} + }) + expect(status.phases.postOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21'), + start: { date: '2018-06-21', time: '18:00'} + }) + }) + + }) + }) + + describe('combining first higher measurment and mucus peak', () => { + it('with fhM + mucus peak on same day finds start of postovu phase', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakAndFhmOnSameDay, + 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: mucusPeakAndFhmOnSameDay + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: mucusPeakAndFhmOnSameDay + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: mucusPeakAndFhmOnSameDay + .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, + 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: fhmTwoDaysBeforeMucusPeak + .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 + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-26' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-26', + time: '18:00' + }, + cycleDays: fhmTwoDaysBeforeMucusPeak + .filter(({date}) => date >= '2018-06-26') + }) + }) + + it('another example for mucus peak before temp shift', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakSlightlyBeforeTempShift, + 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: mucusPeakSlightlyBeforeTempShift + .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: mucusPeakSlightlyBeforeTempShift + .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: mucusPeakSlightlyBeforeTempShift + .filter(({date}) => date >= '2018-06-17') + }) + }) + + it('with another mucus peak 5 days after fHM ignores it', () => { + const status = getSensiplanStatus({ + cycle: mucusPeak5DaysAfterFhm, + 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-01' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + end: { date: '2018-06-22', time: '18:00' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => { + return date > '2018-06-01' && date <= '2018-06-22' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-22', + time: '18:00' + }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date >= '2018-06-22') + }) + }) + + it('with mucus peak 2 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakTwoDaysBeforeFhm, + 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-04' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-07-03', time: '18:00' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-07-03' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-07-03', + time: '18:00' + }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date >= '2018-07-03') + }) + }) + + it('with mucus peak 5 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: fhm5DaysAfterMucusPeak, + 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: fhm5DaysAfterMucusPeak + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) + + describe('combining temperature and cervix measurment', () => { + it('with evaluation of temperature and cervix end on same day', () => { + const status = getSensiplanStatus({ + cycle: tempAndCervixEvalEndOnSameDay, + previousCycle: cycleWithFhm, + secondarySymptom: 'cervix' + }) + 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: tempAndCervixEvalEndOnSameDay + .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: tempAndCervixEvalEndOnSameDay + .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: tempAndCervixEvalEndOnSameDay + .filter(({date}) => date >= '2018-06-17') + }) + expect(status.cervixShift.detected).to.be.true() + expect(status.cervixShift.cervixPeak.date).to.eql('2018-06-14') + expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-06-17') + + }) + }) + + describe('applying the minus-8 rule', () => { + it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] + }) + + 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-04' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + it('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + 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-04' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + it('shortens the pre-ovu phase if mucus occurs', () => { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-01' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => { + return date > '2018-06-01' + }) + }) + }) + + it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { + const status = getSensiplanStatus({ + cycle: cycleWithMucusOnFirstDay, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + + expect(Object.keys(status.phases).length).to.eql(1) + + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + cycleDays: cycleWithMucusOnFirstDay + }) + }) + + it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(11).fill(fhmOnDay15) + }) + + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-07' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-07') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-08' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-07' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + + it('does not lengthen the pre-ovu phase if < 12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(10).fill(fhmOnDay15) + }) + + + 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: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + + it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm, + earlierCycles: [...Array(12).fill(fhmOnDay15)] + }) + + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date >= '2018-06-01' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) + + describe('when args are wrong', () => { + it('throws when arg object is not in right format', () => { + const wrongObject = { hello: 'world' } + expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) + }) + it('throws if cycle array is empty', () => { + expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) + }) + it('throws if cycle days are not in right format', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + hello: 'world', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2018-04-13', + temperature: {value: '35'}, + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '09-14-2017', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + }) + it('throws if first cycle day does not have bleeding value', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2017-01-01', + bleeding: { + value: 'medium' + } + }], + earlierCycles: [[ + { + date: '2017-09-23', + } + ]] + })).to.throw(AssertionError) + }) + }) +}) \ No newline at end of file diff --git a/test/sympto/mucus-temp-fixtures.js b/test/sympto/mucus-temp-fixtures.js index c313629..705e6dc 100644 --- a/test/sympto/mucus-temp-fixtures.js +++ b/test/sympto/mucus-temp-fixtures.js @@ -4,6 +4,14 @@ function convertToSymptoFormat(val) { if (val.temperature) sympto.temperature = { value: val.temperature } if (val.mucus) sympto.mucus = { value: val.mucus } if (val.bleeding) sympto.bleeding = { value: val.bleeding } + if (val.cervix) { + sympto.cervix = {} + if (val.cervix === 'firm & closed') { + sympto.cervix.firmAndClosed = true + } else { + sympto.cervix.firmAndClosed = false + } + } return sympto } From 9e1393766ad8ffca5ffa89d2d1795966bba95fd0 Mon Sep 17 00:00:00 2001 From: emelko Date: Mon, 30 Jul 2018 14:42:00 +0200 Subject: [PATCH 05/28] Split fixtures into temp & mucus and temp & cervix files Add first blueprint for temp&cervix tests --- test/sympto/index.spec.js | 660 --------------- test/sympto/mucus-temp-fixtures.js | 8 - test/sympto/mucus-temp.spec.js | 1208 +++++++++++++-------------- test/sympto/mucus-temp.spec.js~HEAD | 661 +++++++++++++++ 4 files changed, 1247 insertions(+), 1290 deletions(-) delete mode 100644 test/sympto/index.spec.js create mode 100644 test/sympto/mucus-temp.spec.js~HEAD diff --git a/test/sympto/index.spec.js b/test/sympto/index.spec.js deleted file mode 100644 index 88ada86..0000000 --- a/test/sympto/index.spec.js +++ /dev/null @@ -1,660 +0,0 @@ -import chai from 'chai' -import getSensiplanStatus from '../../lib/sympto' -import { AssertionError } from 'assert' -import { - cycleWithoutFhm, - longAndComplicatedCycle, - cycleWithTempAndNoMucusShift, - cycleWithFhm, - cycleWithoutAnyShifts, - fiveDayCycle, - cycleWithEarlyMucus, - cycleWithMucusOnFirstDay, - mucusPeakAndFhmOnSameDay, - fhmTwoDaysBeforeMucusPeak, - fhm5DaysAfterMucusPeak, - mucusPeak5DaysAfterFhm, - mucusPeakTwoDaysBeforeFhm, - fhmOnDay12, - fhmOnDay15, - mucusPeakSlightlyBeforeTempShift, - tempAndCervixEvalEndOnSameDay -} from './fixtures' - -const expect = chai.expect - -describe('sympto', () => { - describe('with no previous higher measurement', () => { - it('with no shifts detects only peri-ovulatory', function () { - const status = getSensiplanStatus({ - cycle: cycleWithoutAnyShifts, - previousCycle: cycleWithoutFhm - }) - - expect(status).to.eql({ - - phases: { - periOvulatory: { - start: { date: '2018-06-01' }, - cycleDays: cycleWithoutAnyShifts - } - }, - }) - }) - - it('with shifts detects only peri-ovulatory and post-ovulatory', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm - }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-21') - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - describe('with previous higher measurement', () => { - describe('with no shifts detects pre-ovulatory phase', function () { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: fiveDayCycle, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(1) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: fiveDayCycle, - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - }) - - }) - describe('with no shifts detects pre- and peri-ovulatory phase', () => { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: cycleWithTempAndNoMucusShift, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date > '2018-06-05'), - start: { date: '2018-06-06' } - }) - }) - it('according to 5-day-rule with shortened pre-phase', function () { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - - 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 () { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(3) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00'} - }) - expect(status.phases.postOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21'), - start: { date: '2018-06-21', time: '18:00'} - }) - }) - - }) - }) - - describe('combining first higher measurment and mucus peak', () => { - it('with fhM + mucus peak on same day finds start of postovu phase', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakAndFhmOnSameDay, - 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: mucusPeakAndFhmOnSameDay - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: mucusPeakAndFhmOnSameDay - .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, - 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: fhmTwoDaysBeforeMucusPeak - .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 - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-26' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-26', - time: '18:00' - }, - cycleDays: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => date >= '2018-06-26') - }) - }) - - it('another example for mucus peak before temp shift', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakSlightlyBeforeTempShift, - 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: mucusPeakSlightlyBeforeTempShift - .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: mucusPeakSlightlyBeforeTempShift - .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: mucusPeakSlightlyBeforeTempShift - .filter(({date}) => date >= '2018-06-17') - }) - }) - - it('with another mucus peak 5 days after fHM ignores it', () => { - const status = getSensiplanStatus({ - cycle: mucusPeak5DaysAfterFhm, - 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-01' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - end: { date: '2018-06-22', time: '18:00' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => { - return date > '2018-06-01' && date <= '2018-06-22' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-22', - time: '18:00' - }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date >= '2018-06-22') - }) - }) - - it('with mucus peak 2 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakTwoDaysBeforeFhm, - 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-04' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-07-03', time: '18:00' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-07-03' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-07-03', - time: '18:00' - }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date >= '2018-07-03') - }) - }) - - it('with mucus peak 5 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: fhm5DaysAfterMucusPeak, - 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: fhm5DaysAfterMucusPeak - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - - describe('combining temperature and cervix measurment', () => { - it('with evaluation of temperature and cervix end on same day', () => { - const status = getSensiplanStatus({ - cycle: tempAndCervixEvalEndOnSameDay, - previousCycle: cycleWithFhm, - secondarySymptom: 'cervix' - }) - 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: tempAndCervixEvalEndOnSameDay - .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: tempAndCervixEvalEndOnSameDay - .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: tempAndCervixEvalEndOnSameDay - .filter(({date}) => date >= '2018-06-17') - }) - expect(status.cervixShift.detected).to.be.true() - expect(status.cervixShift.cervixPeak.date).to.eql('2018-06-14') - expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-06-17') - - }) - }) - - describe('applying the minus-8 rule', () => { - it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] - }) - - 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-04' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - it('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - 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-04' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - it('shortens the pre-ovu phase if mucus occurs', () => { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-01' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => { - return date > '2018-06-01' - }) - }) - }) - - it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { - const status = getSensiplanStatus({ - cycle: cycleWithMucusOnFirstDay, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - - expect(Object.keys(status.phases).length).to.eql(1) - - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - cycleDays: cycleWithMucusOnFirstDay - }) - }) - - it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(11).fill(fhmOnDay15) - }) - - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-07' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-07') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-08' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-07' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('does not lengthen the pre-ovu phase if < 12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(10).fill(fhmOnDay15) - }) - - - 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: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm, - earlierCycles: [...Array(12).fill(fhmOnDay15)] - }) - - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date >= '2018-06-01' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - - describe('when args are wrong', () => { - it('throws when arg object is not in right format', () => { - const wrongObject = { hello: 'world' } - expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) - }) - it('throws if cycle array is empty', () => { - expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) - }) - it('throws if cycle days are not in right format', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - hello: 'world', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2018-04-13', - temperature: {value: '35'}, - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '09-14-2017', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - }) - it('throws if first cycle day does not have bleeding value', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2017-01-01', - bleeding: { - value: 'medium' - } - }], - earlierCycles: [[ - { - date: '2017-09-23', - } - ]] - })).to.throw(AssertionError) - }) - }) -}) \ No newline at end of file diff --git a/test/sympto/mucus-temp-fixtures.js b/test/sympto/mucus-temp-fixtures.js index 705e6dc..c313629 100644 --- a/test/sympto/mucus-temp-fixtures.js +++ b/test/sympto/mucus-temp-fixtures.js @@ -4,14 +4,6 @@ function convertToSymptoFormat(val) { if (val.temperature) sympto.temperature = { value: val.temperature } if (val.mucus) sympto.mucus = { value: val.mucus } if (val.bleeding) sympto.bleeding = { value: val.bleeding } - if (val.cervix) { - sympto.cervix = {} - if (val.cervix === 'firm & closed') { - sympto.cervix.firmAndClosed = true - } else { - sympto.cervix.firmAndClosed = false - } - } return sympto } diff --git a/test/sympto/mucus-temp.spec.js b/test/sympto/mucus-temp.spec.js index 92f346d..c0f850a 100644 --- a/test/sympto/mucus-temp.spec.js +++ b/test/sympto/mucus-temp.spec.js @@ -17,645 +17,609 @@ import { mucusPeakTwoDaysBeforeFhm, fhmOnDay12, fhmOnDay15, - mucusPeakSlightlyBeforeTempShift, - highestMucusQualityAfterEndOfEval + mucusPeakSlightlyBeforeTempShift } from './mucus-temp-fixtures' const expect = chai.expect describe('sympto', () => { - describe('combining temperature and mucus tracking', () => { - describe('with no previous higher temp measurement', () => { - - it('with no shifts detects only peri-ovulatory', function () { - const status = getSensiplanStatus({ - cycle: cycleWithoutAnyShifts, - previousCycle: cycleWithoutFhm - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - cycleDays: cycleWithoutAnyShifts - }) + describe('with no previous higher measurement', () => { + it('with no shifts detects only peri-ovulatory', function () { + const status = getSensiplanStatus({ + cycle: cycleWithoutAnyShifts, + previousCycle: cycleWithoutFhm }) - it('with temp and mucus shifts detects only peri-ovulatory and post-ovulatory', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm - }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-21') - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) + expect(status).to.eql({ - }) - }) - - describe('with previous higher measurement', () => { - describe('with no shifts detects pre-ovulatory phase', function () { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: fiveDayCycle, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(1) - expect(status.phases.preOvulatory).to.eql({ - cycleDays: fiveDayCycle, + phases: { + periOvulatory: { start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - }) - }) - describe('with no shifts detects pre- and peri-ovulatory phase', () => { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: cycleWithTempAndNoMucusShift, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date > '2018-06-05'), - start: { date: '2018-06-06' } - }) - }) - it('according to 5-day-rule with shortened pre-phase', function () { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - - 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 () { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(3) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00'} - }) - expect(status.phases.postOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21'), - start: { date: '2018-06-21', time: '18:00'} - }) - }) - + cycleDays: cycleWithoutAnyShifts + } + }, }) }) - describe('combining first higher measurment and mucus peak', () => { - it('with fhM + mucus peak on same day finds start of postovu phase', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakAndFhmOnSameDay, - 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: mucusPeakAndFhmOnSameDay - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => date >= '2018-06-21') - }) + it('with shifts detects only peri-ovulatory and post-ovulatory', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm }) - it('with fhM 2 days before mucus peak waits for end of mucus eval', () => { - const status = getSensiplanStatus({ - cycle: fhmTwoDaysBeforeMucusPeak, - previousCycle: cycleWithFhm - }) + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') - 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: fhmTwoDaysBeforeMucusPeak - .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 - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-26' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-26', - time: '18:00' - }, - cycleDays: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => date >= '2018-06-26') - }) + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-21') }) - - it('another example for mucus peak before temp shift', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakSlightlyBeforeTempShift, - 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: mucusPeakSlightlyBeforeTempShift - .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: mucusPeakSlightlyBeforeTempShift - .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: mucusPeakSlightlyBeforeTempShift - .filter(({date}) => date >= '2018-06-17') - }) - }) - - it('with another mucus peak 5 days after fHM ignores it', () => { - const status = getSensiplanStatus({ - cycle: mucusPeak5DaysAfterFhm, - 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-01' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - end: { date: '2018-06-22', time: '18:00' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => { - return date > '2018-06-01' && date <= '2018-06-22' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-22', - time: '18:00' - }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date >= '2018-06-22') - }) - }) - - it('with mucus peak 2 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakTwoDaysBeforeFhm, - 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-04' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-07-03', time: '18:00' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-07-03' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-07-03', - time: '18:00' - }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date >= '2018-07-03') - }) - }) - - it('with mucus peak 5 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: fhm5DaysAfterMucusPeak, - 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: fhm5DaysAfterMucusPeak - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - - describe('applying the minus-8 rule', () => { - it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] - }) - - 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-04' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - // #TODO - it.only('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - 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: fhm5DaysAfterMucusPeak - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => date >= '2018-06-21') - }) - }) - - // #TODO - 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-26', time: '18:00' }, - cycleDays: highestMucusQualityAfterEndOfEval - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-26' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-26', - time: '18:00' - }, - cycleDays: highestMucusQualityAfterEndOfEval - .filter(({date}) => date >= '2018-06-26') - }) - }) - }) - - describe('something', () => { - - it('shortens the pre-ovu phase if mucus occurs', () => { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-01' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => { - return date > '2018-06-01' - }) - }) - }) - - it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { - const status = getSensiplanStatus({ - cycle: cycleWithMucusOnFirstDay, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - - expect(Object.keys(status.phases).length).to.eql(1) - - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - cycleDays: cycleWithMucusOnFirstDay - }) - }) - - it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(11).fill(fhmOnDay15) - }) - - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-07' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-07') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-08' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-07' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('does not lengthen the pre-ovu phase if < 12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(10).fill(fhmOnDay15) - }) - - - 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: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm, - earlierCycles: [...Array(12).fill(fhmOnDay15)] - }) - - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date >= '2018-06-01' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - - describe('when args are wrong', () => { - it('throws when arg object is not in right format', () => { - const wrongObject = { hello: 'world' } - expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) - }) - it('throws if cycle array is empty', () => { - expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) - }) - it('throws if cycle days are not in right format', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - hello: 'world', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2018-04-13', - temperature: {value: '35'}, - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '09-14-2017', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - }) - it('throws if first cycle day does not have bleeding value', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2017-01-01', - bleeding: { - value: 'medium' - } - }], - earlierCycles: [[ - { - date: '2017-09-23', - } - ]] - })).to.throw(AssertionError) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') }) }) }) + describe('with previous higher measurement', () => { + describe('with no shifts detects pre-ovulatory phase', function () { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: fiveDayCycle, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(1) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: fiveDayCycle, + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + }) + + }) + describe('with no shifts detects pre- and peri-ovulatory phase', () => { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: cycleWithTempAndNoMucusShift, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(2) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date <= '2018-06-05'), + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date > '2018-06-05'), + start: { date: '2018-06-06' } + }) + }) + it('according to 5-day-rule with shortened pre-phase', function () { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(2) + + 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 () { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(3) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05'), + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00'} + }) + expect(status.phases.postOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21'), + start: { date: '2018-06-21', time: '18:00'} + }) + }) + + }) + }) + + describe('combining first higher measurment and mucus peak', () => { + it('with fhM + mucus peak on same day finds start of postovu phase', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakAndFhmOnSameDay, + 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: mucusPeakAndFhmOnSameDay + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: mucusPeakAndFhmOnSameDay + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: mucusPeakAndFhmOnSameDay + .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, + 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: fhmTwoDaysBeforeMucusPeak + .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 + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-26' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-26', + time: '18:00' + }, + cycleDays: fhmTwoDaysBeforeMucusPeak + .filter(({date}) => date >= '2018-06-26') + }) + }) + + it('another example for mucus peak before temp shift', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakSlightlyBeforeTempShift, + 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: mucusPeakSlightlyBeforeTempShift + .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: mucusPeakSlightlyBeforeTempShift + .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: mucusPeakSlightlyBeforeTempShift + .filter(({date}) => date >= '2018-06-17') + }) + }) + + it('with another mucus peak 5 days after fHM ignores it', () => { + const status = getSensiplanStatus({ + cycle: mucusPeak5DaysAfterFhm, + 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-01' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + end: { date: '2018-06-22', time: '18:00' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => { + return date > '2018-06-01' && date <= '2018-06-22' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-22', + time: '18:00' + }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date >= '2018-06-22') + }) + }) + + it('with mucus peak 2 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakTwoDaysBeforeFhm, + 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-04' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-07-03', time: '18:00' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-07-03' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-07-03', + time: '18:00' + }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date >= '2018-07-03') + }) + }) + + it('with mucus peak 5 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: fhm5DaysAfterMucusPeak, + 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: fhm5DaysAfterMucusPeak + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) + + describe('applying the minus-8 rule', () => { + it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] + }) + + 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-04' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + it('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + 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-04' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + it('shortens the pre-ovu phase if mucus occurs', () => { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-01' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => { + return date > '2018-06-01' + }) + }) + }) + + it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { + const status = getSensiplanStatus({ + cycle: cycleWithMucusOnFirstDay, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + + expect(Object.keys(status.phases).length).to.eql(1) + + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + cycleDays: cycleWithMucusOnFirstDay + }) + }) + + it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(11).fill(fhmOnDay15) + }) + + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-07' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-07') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-08' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-07' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + + it('does not lengthen the pre-ovu phase if < 12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(10).fill(fhmOnDay15) + }) + + + 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: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + + it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm, + earlierCycles: [...Array(12).fill(fhmOnDay15)] + }) + + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date >= '2018-06-01' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) + + describe('when args are wrong', () => { + it('throws when arg object is not in right format', () => { + const wrongObject = { hello: 'world' } + expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) + }) + it('throws if cycle array is empty', () => { + expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) + }) + it('throws if cycle days are not in right format', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + hello: 'world', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2018-04-13', + temperature: {value: '35'}, + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '09-14-2017', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + }) + it('throws if first cycle day does not have bleeding value', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2017-01-01', + bleeding: { + value: 'medium' + } + }], + earlierCycles: [[ + { + date: '2017-09-23', + } + ]] + })).to.throw(AssertionError) + }) + }) }) diff --git a/test/sympto/mucus-temp.spec.js~HEAD b/test/sympto/mucus-temp.spec.js~HEAD new file mode 100644 index 0000000..92f346d --- /dev/null +++ b/test/sympto/mucus-temp.spec.js~HEAD @@ -0,0 +1,661 @@ +import chai from 'chai' +import getSensiplanStatus from '../../lib/sympto' +import { AssertionError } from 'assert' +import { + cycleWithoutFhm, + longAndComplicatedCycle, + cycleWithTempAndNoMucusShift, + cycleWithFhm, + cycleWithoutAnyShifts, + fiveDayCycle, + cycleWithEarlyMucus, + cycleWithMucusOnFirstDay, + mucusPeakAndFhmOnSameDay, + fhmTwoDaysBeforeMucusPeak, + fhm5DaysAfterMucusPeak, + mucusPeak5DaysAfterFhm, + mucusPeakTwoDaysBeforeFhm, + fhmOnDay12, + fhmOnDay15, + mucusPeakSlightlyBeforeTempShift, + highestMucusQualityAfterEndOfEval +} from './mucus-temp-fixtures' + +const expect = chai.expect + +describe('sympto', () => { + describe('combining temperature and mucus tracking', () => { + describe('with no previous higher temp measurement', () => { + + it('with no shifts detects only peri-ovulatory', function () { + const status = getSensiplanStatus({ + cycle: cycleWithoutAnyShifts, + previousCycle: cycleWithoutFhm + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + cycleDays: cycleWithoutAnyShifts + }) + }) + + it('with temp and mucus shifts detects only peri-ovulatory and post-ovulatory', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm + }) + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-21') + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + + }) + }) + + describe('with previous higher measurement', () => { + describe('with no shifts detects pre-ovulatory phase', function () { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: fiveDayCycle, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(1) + expect(status.phases.preOvulatory).to.eql({ + cycleDays: fiveDayCycle, + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + }) + }) + describe('with no shifts detects pre- and peri-ovulatory phase', () => { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: cycleWithTempAndNoMucusShift, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(2) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date <= '2018-06-05'), + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date > '2018-06-05'), + start: { date: '2018-06-06' } + }) + }) + it('according to 5-day-rule with shortened pre-phase', function () { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(2) + + 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 () { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(3) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05'), + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00'} + }) + expect(status.phases.postOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21'), + start: { date: '2018-06-21', time: '18:00'} + }) + }) + + }) + }) + + describe('combining first higher measurment and mucus peak', () => { + it('with fhM + mucus peak on same day finds start of postovu phase', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakAndFhmOnSameDay, + 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: mucusPeakAndFhmOnSameDay + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: mucusPeakAndFhmOnSameDay + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: mucusPeakAndFhmOnSameDay + .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, + 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: fhmTwoDaysBeforeMucusPeak + .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 + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-26' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-26', + time: '18:00' + }, + cycleDays: fhmTwoDaysBeforeMucusPeak + .filter(({date}) => date >= '2018-06-26') + }) + }) + + it('another example for mucus peak before temp shift', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakSlightlyBeforeTempShift, + 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: mucusPeakSlightlyBeforeTempShift + .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: mucusPeakSlightlyBeforeTempShift + .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: mucusPeakSlightlyBeforeTempShift + .filter(({date}) => date >= '2018-06-17') + }) + }) + + it('with another mucus peak 5 days after fHM ignores it', () => { + const status = getSensiplanStatus({ + cycle: mucusPeak5DaysAfterFhm, + 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-01' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + end: { date: '2018-06-22', time: '18:00' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => { + return date > '2018-06-01' && date <= '2018-06-22' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-22', + time: '18:00' + }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date >= '2018-06-22') + }) + }) + + it('with mucus peak 2 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakTwoDaysBeforeFhm, + 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-04' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-07-03', time: '18:00' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-07-03' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-07-03', + time: '18:00' + }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date >= '2018-07-03') + }) + }) + + it('with mucus peak 5 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: fhm5DaysAfterMucusPeak, + 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: fhm5DaysAfterMucusPeak + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) + + describe('applying the minus-8 rule', () => { + it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] + }) + + 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-04' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + // #TODO + it.only('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + 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: fhm5DaysAfterMucusPeak + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date >= '2018-06-21') + }) + }) + + // #TODO + 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-26', time: '18:00' }, + cycleDays: highestMucusQualityAfterEndOfEval + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-26' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-26', + time: '18:00' + }, + cycleDays: highestMucusQualityAfterEndOfEval + .filter(({date}) => date >= '2018-06-26') + }) + }) + }) + + describe('something', () => { + + it('shortens the pre-ovu phase if mucus occurs', () => { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-01' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => { + return date > '2018-06-01' + }) + }) + }) + + it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { + const status = getSensiplanStatus({ + cycle: cycleWithMucusOnFirstDay, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + + expect(Object.keys(status.phases).length).to.eql(1) + + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + cycleDays: cycleWithMucusOnFirstDay + }) + }) + + it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(11).fill(fhmOnDay15) + }) + + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-07' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-07') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-08' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-07' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + + it('does not lengthen the pre-ovu phase if < 12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(10).fill(fhmOnDay15) + }) + + + 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: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + + it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm, + earlierCycles: [...Array(12).fill(fhmOnDay15)] + }) + + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date >= '2018-06-01' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) + + describe('when args are wrong', () => { + it('throws when arg object is not in right format', () => { + const wrongObject = { hello: 'world' } + expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) + }) + it('throws if cycle array is empty', () => { + expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) + }) + it('throws if cycle days are not in right format', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + hello: 'world', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2018-04-13', + temperature: {value: '35'}, + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '09-14-2017', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + }) + it('throws if first cycle day does not have bleeding value', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2017-01-01', + bleeding: { + value: 'medium' + } + }], + earlierCycles: [[ + { + date: '2017-09-23', + } + ]] + })).to.throw(AssertionError) + }) + }) + }) +}) From 21d6e24f23dd0a90d63e708f2c77fe5b78dd7424 Mon Sep 17 00:00:00 2001 From: emelko Date: Mon, 13 Aug 2018 11:31:21 +0200 Subject: [PATCH 07/28] Add more details to cervix-temp fixtures and to mucus-temp spec --- test/sympto/cervix-temp-fixtures.js | 17 +- test/sympto/mucus-temp.spec.js | 1113 +++++++++++++-------------- 2 files changed, 560 insertions(+), 570 deletions(-) diff --git a/test/sympto/cervix-temp-fixtures.js b/test/sympto/cervix-temp-fixtures.js index 0d6d42c..66239e5 100644 --- a/test/sympto/cervix-temp-fixtures.js +++ b/test/sympto/cervix-temp-fixtures.js @@ -37,17 +37,12 @@ export const cycleWithFhmNoCervixShift = [ { 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-08', temperature: 36.7 }, - { date: '2018-06-09', temperature: 36.7 }, - { date: '2018-06-10', temperature: 36.7 }, - { date: '2018-06-11', temperature: 36.7 }, - { date: '2018-06-12', temperature: 36.7 }, - { date: '2018-06-13', temperature: 36.8 }, - { date: '2018-06-15', temperature: 36.9 }, - { date: '2018-06-16', temperature: 36.9 }, - { date: '2018-06-17', temperature: 36.9 }, - { date: '2018-06-18', temperature: 36.9 } + { date: '2018-06-06', temperature: 36.7, cervix: { isClosed: true, isHard: true } }, + { date: '2018-06-13', temperature: 36.8, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-15', temperature: 36.9, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-17', temperature: 36.9, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-17', temperature: 36.9, cervix: { isClosed: false, isHard: false } }, + { date: '2018-06-18', temperature: 36.9, cervix: { isClosed: false, isHard: false } } ].map(convertToSymptoFormat) export const cycleWithoutFhm = [ diff --git a/test/sympto/mucus-temp.spec.js b/test/sympto/mucus-temp.spec.js index c0f850a..e81ba31 100644 --- a/test/sympto/mucus-temp.spec.js +++ b/test/sympto/mucus-temp.spec.js @@ -23,603 +23,598 @@ import { const expect = chai.expect describe('sympto', () => { - describe('with no previous higher measurement', () => { - it('with no shifts detects only peri-ovulatory', function () { - const status = getSensiplanStatus({ - cycle: cycleWithoutAnyShifts, - previousCycle: cycleWithoutFhm - }) + describe('combining temperature and mucus tracking', () => { + describe('with no previous higher temp measurement', () => { - expect(status).to.eql({ - - phases: { - periOvulatory: { - start: { date: '2018-06-01' }, - cycleDays: cycleWithoutAnyShifts - } - }, - }) - }) - - it('with shifts detects only peri-ovulatory and post-ovulatory', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm - }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-21') - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - describe('with previous higher measurement', () => { - describe('with no shifts detects pre-ovulatory phase', function () { - it('according to 5-day-rule', function () { + it('with no shifts detects only peri-ovulatory', function () { const status = getSensiplanStatus({ - cycle: fiveDayCycle, + cycle: cycleWithoutAnyShifts, + previousCycle: cycleWithoutFhm + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + cycleDays: cycleWithoutAnyShifts + }) + }) + + it('with temp and mucus shifts detects only peri-ovulatory and post-ovulatory', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm + }) + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-21') + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + + }) + }) + + describe('with previous higher measurement', () => { + describe('with no shifts detects pre-ovulatory phase', function () { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: fiveDayCycle, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(1) + expect(status.phases.preOvulatory).to.eql({ + cycleDays: fiveDayCycle, + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + }) + }) + describe('with no shifts detects pre- and peri-ovulatory phase', () => { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: cycleWithTempAndNoMucusShift, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(2) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date <= '2018-06-05'), + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date > '2018-06-05'), + start: { date: '2018-06-06' } + }) + }) + it('according to 5-day-rule with shortened pre-phase', function () { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(2) + + 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 () { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(3) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05'), + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00'} + }) + expect(status.phases.postOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21'), + start: { date: '2018-06-21', time: '18:00'} + }) + }) + + }) + }) + + describe('combining first higher measurment and mucus peak', () => { + it('with fhM + mucus peak on same day finds start of postovu phase', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakAndFhmOnSameDay, 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: mucusPeakAndFhmOnSameDay + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: mucusPeakAndFhmOnSameDay + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: mucusPeakAndFhmOnSameDay + .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, + 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: fhmTwoDaysBeforeMucusPeak + .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 + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-26' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-26', + time: '18:00' + }, + cycleDays: fhmTwoDaysBeforeMucusPeak + .filter(({date}) => date >= '2018-06-26') + }) + }) + + it('another example for mucus peak before temp shift', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakSlightlyBeforeTempShift, + 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: mucusPeakSlightlyBeforeTempShift + .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: mucusPeakSlightlyBeforeTempShift + .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: mucusPeakSlightlyBeforeTempShift + .filter(({date}) => date >= '2018-06-17') + }) + }) + + it('with another mucus peak 5 days after fHM ignores it', () => { + const status = getSensiplanStatus({ + cycle: mucusPeak5DaysAfterFhm, + 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-01' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + end: { date: '2018-06-22', time: '18:00' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => { + return date > '2018-06-01' && date <= '2018-06-22' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-22', + time: '18:00' + }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date >= '2018-06-22') + }) + }) + + it('with mucus peak 2 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakTwoDaysBeforeFhm, + 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-04' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-07-03', time: '18:00' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-07-03' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-07-03', + time: '18:00' + }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date >= '2018-07-03') + }) + }) + + it('with mucus peak 5 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: fhm5DaysAfterMucusPeak, + 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: fhm5DaysAfterMucusPeak + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) + + describe('applying the minus-8 rule', () => { + it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] + }) + + 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-04' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + it('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + 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-04' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + it('shortens the pre-ovu phase if mucus occurs', () => { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-01' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => { + return date > '2018-06-01' + }) + }) + }) + + it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { + const status = getSensiplanStatus({ + cycle: cycleWithMucusOnFirstDay, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + expect(Object.keys(status.phases).length).to.eql(1) - expect(status.phases.preOvulatory).to.eql({ - cycleDays: fiveDayCycle, - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - }) - - }) - describe('with no shifts detects pre- and peri-ovulatory phase', () => { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: cycleWithTempAndNoMucusShift, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) expect(status.phases.periOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date > '2018-06-05'), - start: { date: '2018-06-06' } - }) - }) - it('according to 5-day-rule with shortened pre-phase', function () { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - - 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' } + cycleDays: cycleWithMucusOnFirstDay }) }) - }) - describe('with shifts detects pre- and peri-ovulatory phase', function () { - it('according to 5-day-rule', function () { + + it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { const status = getSensiplanStatus({ cycle: longAndComplicatedCycle, - previousCycle: cycleWithFhm + previousCycle: fhmOnDay15, + earlierCycles: Array(11).fill(fhmOnDay15) }) + expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05'), start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } + end: { date: '2018-06-07' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-07') }) expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-08' }, + end: { date: '2018-06-21', time: '18:00' }, cycleDays: longAndComplicatedCycle - .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00'} + .filter(({date}) => { + return date > '2018-06-07' && date <= '2018-06-21' + }) }) expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21'), - start: { date: '2018-06-21', time: '18:00'} + .filter(({date}) => date >= '2018-06-21') }) }) - }) - }) + it('does not lengthen the pre-ovu phase if < 12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(10).fill(fhmOnDay15) + }) - describe('combining first higher measurment and mucus peak', () => { - it('with fhM + mucus peak on same day finds start of postovu phase', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakAndFhmOnSameDay, - previousCycle: cycleWithFhm + + 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: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') + it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm, + earlierCycles: [...Array(12).fill(fhmOnDay15)] + }) - 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: mucusPeakAndFhmOnSameDay - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => date >= '2018-06-21') + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date >= '2018-06-01' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .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, - previousCycle: cycleWithFhm + describe('when args are wrong', () => { + it('throws when arg object is not in right format', () => { + const wrongObject = { hello: 'world' } + expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) }) - - 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: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => date <= '2018-06-05') + it('throws if cycle array is empty', () => { + expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-26', time: '18:00' }, - cycleDays: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-26' - }) + it('throws if cycle days are not in right format', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + hello: 'world', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2018-04-13', + temperature: {value: '35'}, + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '09-14-2017', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-26', - time: '18:00' - }, - cycleDays: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => date >= '2018-06-26') + it('throws if first cycle day does not have bleeding value', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2017-01-01', + bleeding: { + value: 'medium' + } + }], + earlierCycles: [[ + { + date: '2017-09-23', + } + ]] + })).to.throw(AssertionError) }) }) - - it('another example for mucus peak before temp shift', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakSlightlyBeforeTempShift, - 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: mucusPeakSlightlyBeforeTempShift - .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: mucusPeakSlightlyBeforeTempShift - .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: mucusPeakSlightlyBeforeTempShift - .filter(({date}) => date >= '2018-06-17') - }) - }) - - it('with another mucus peak 5 days after fHM ignores it', () => { - const status = getSensiplanStatus({ - cycle: mucusPeak5DaysAfterFhm, - 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-01' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - end: { date: '2018-06-22', time: '18:00' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => { - return date > '2018-06-01' && date <= '2018-06-22' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-22', - time: '18:00' - }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date >= '2018-06-22') - }) - }) - - it('with mucus peak 2 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakTwoDaysBeforeFhm, - 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-04' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-07-03', time: '18:00' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-07-03' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-07-03', - time: '18:00' - }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date >= '2018-07-03') - }) - }) - - it('with mucus peak 5 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: fhm5DaysAfterMucusPeak, - 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: fhm5DaysAfterMucusPeak - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - - describe('applying the minus-8 rule', () => { - it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] - }) - - 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-04' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - it('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - 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-04' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - it('shortens the pre-ovu phase if mucus occurs', () => { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-01' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => { - return date > '2018-06-01' - }) - }) - }) - - it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { - const status = getSensiplanStatus({ - cycle: cycleWithMucusOnFirstDay, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - - expect(Object.keys(status.phases).length).to.eql(1) - - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - cycleDays: cycleWithMucusOnFirstDay - }) - }) - - it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(11).fill(fhmOnDay15) - }) - - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-07' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-07') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-08' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-07' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('does not lengthen the pre-ovu phase if < 12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(10).fill(fhmOnDay15) - }) - - - 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: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm, - earlierCycles: [...Array(12).fill(fhmOnDay15)] - }) - - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date >= '2018-06-01' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - - describe('when args are wrong', () => { - it('throws when arg object is not in right format', () => { - const wrongObject = { hello: 'world' } - expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) - }) - it('throws if cycle array is empty', () => { - expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) - }) - it('throws if cycle days are not in right format', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - hello: 'world', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2018-04-13', - temperature: {value: '35'}, - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '09-14-2017', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - }) - it('throws if first cycle day does not have bleeding value', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2017-01-01', - bleeding: { - value: 'medium' - } - }], - earlierCycles: [[ - { - date: '2017-09-23', - } - ]] - })).to.throw(AssertionError) - }) }) }) From 80cabee66b84e59c8669233c2153b8d27c13e0c6 Mon Sep 17 00:00:00 2001 From: tina Date: Mon, 3 Sep 2018 13:07:40 +0200 Subject: [PATCH 08/28] adds more meaningful messages to assertion errors --- lib/sympto/index.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/sympto/index.js b/lib/sympto/index.js index ccfbf32..9281d5d 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -100,20 +100,20 @@ export default function getSymptoThermalStatus(cycleInfo) { function throwIfArgsAreNotInRequiredFormat(cycles) { cycles.forEach(cycle => { - assert.ok(Array.isArray(cycle)) - assert.ok(cycle.length > 0) //what about 2 cycles of 1 day each?! - assert.ok(cycle[0].bleeding !== null) - assert.equal(typeof cycle[0].bleeding, 'object', "First cycle day must contain bleeding value") - assert.equal(typeof cycle[0].bleeding.value, 'number') + assert.ok(Array.isArray(cycle), "Cycles must be arrays.") + assert.ok(cycle.length > 0, "Cycle must not be empty.") //what about 2 cycles of 1 day each?! + assert.ok(cycle[0].bleeding !== null, "First cycle day should have bleeding.") + assert.equal(typeof cycle[0].bleeding, 'object', "First cycle day must contain bleeding value.") + assert.equal(typeof cycle[0].bleeding.value, 'number', "First cycle day bleeding value is a number.") cycle.forEach(day => { - assert.equal(typeof day.date, 'string') - assert.doesNotThrow(() => LocalDate.parse(day.date)) - if (day.temperature) assert.equal(typeof day.temperature.value, 'number') - if (day.mucus) assert.equal(typeof day.mucus.value, 'number') - if (day.mucus) assert.ok(day.mucus.value >= 0) - if (day.mucus) assert.ok(day.mucus.value < 5) - if (day.cervix) assert.equal(typeof day.cervix.isClosed, 'boolean') - if (day.cervix) assert.equal(typeof day.cervix.isHard, 'boolean') + assert.equal(typeof day.date, 'string', "Date is given as a string.") + assert.doesNotThrow(() => LocalDate.parse(day.date), "Date is given in right string format.") + if (day.temperature) assert.equal(typeof day.temperature.value, 'number', "Temperature value is a number.") + if (day.mucus) assert.equal(typeof day.mucus.value, 'number', "Mucus value is a number.") + if (day.mucus) assert.ok(day.mucus.value >= 0, "Mucus value is greater or equal to 0.") + if (day.mucus) assert.ok(day.mucus.value < 5, "Mucus value below 5.") + if (day.cervix) assert.equal(typeof day.cervix.isClosed, 'boolean', "Cervic.isClosed is a boolean.") + if (day.cervix) assert.equal(typeof day.cervix.isHard, 'boolean', "Cervic.isHard is a boolean.") }) }) } From 1c2c45f8c67a224ec5f886f26fdc8bb45ce11e92 Mon Sep 17 00:00:00 2001 From: emelko Date: Wed, 5 Sep 2018 15:27:04 +0200 Subject: [PATCH 09/28] Changes cervix value to check for opening and firmness value --- lib/sympto/cervix.js | 4 +- lib/sympto/index.js | 7 +- test/sympto/cervix-temp-fixtures.js | 275 ++++++++++++++-------------- 3 files changed, 148 insertions(+), 138 deletions(-) diff --git a/lib/sympto/cervix.js b/lib/sympto/cervix.js index 01abe36..2e0dff4 100644 --- a/lib/sympto/cervix.js +++ b/lib/sympto/cervix.js @@ -36,6 +36,6 @@ export default function (cycleDays, tempEvalEndIndex) { return { detected: false } } -function isClosedAndHard (cervixValue) { - return cervixValue.isClosed && cervixValue.isHard +function isClosedAndHard (cervix) { + return cervix.value.opening === 0 && cervix.value.firmness === 0 } diff --git a/lib/sympto/index.js b/lib/sympto/index.js index ccfbf32..c50fcbb 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -112,8 +112,11 @@ function throwIfArgsAreNotInRequiredFormat(cycles) { if (day.mucus) assert.equal(typeof day.mucus.value, 'number') if (day.mucus) assert.ok(day.mucus.value >= 0) if (day.mucus) assert.ok(day.mucus.value < 5) - if (day.cervix) assert.equal(typeof day.cervix.isClosed, 'boolean') - if (day.cervix) assert.equal(typeof day.cervix.isHard, 'boolean') + if (day.cervix) assert.equal(typeof day.cervix.value, 'object') + if (day.cervix) assert.ok(day.cervix.value.opening >= 0, "cervix opening value must be 0 or bigger") + if (day.cervix) assert.ok(day.cervix.value.opening <= 2, "cervix opening value must be 2 or smaller") + if (day.cervix) assert.ok(day.cervix.value.firmness >= 0, "cervix firmness value must be 0 or bigger") + if (day.cervix) assert.ok(day.cervix.value.firmness <= 1, "cervix firmness value must be 1 or smaller") }) }) } diff --git a/test/sympto/cervix-temp-fixtures.js b/test/sympto/cervix-temp-fixtures.js index 66239e5..d5b85a5 100644 --- a/test/sympto/cervix-temp-fixtures.js +++ b/test/sympto/cervix-temp-fixtures.js @@ -17,72 +17,79 @@ function convertToSymptoFormat(val) { } export const idealCycle = [ - { date: '2018-08-01', bleeding: 1, cervix: { isClosed: false, isHard: false } }, - { date: '2018-08-02', bleeding: 2, cervix: { isClosed: false, isHard: false } }, - { date: '2018-08-03', temperature: 36.6, bleeding: 2, cervix: { isClosed: false, isHard: false } }, - { date: '2018-08-04', temperature: 36.55, bleeding: 1, cervix: { isClosed: false, isHard: true } }, - { date: '2018-08-05', temperature: 36.6, bleeding: null, cervix: { isClosed: true, isHard: false } }, - { date: '2018-08-06', temperature: 36.65, bleeding: null, cervix: { isClosed: true, isHard: false } }, - { date: '2018-08-07', temperature: 36.7, bleeding: null, cervix: { isClosed: false, isHard: true } }, - { date: '2018-08-08', temperature: 36.6, bleeding: null, cervix: { isClosed: true, isHard: false } }, - { date: '2018-08-09', temperature: 36.8, bleeding: null, cervix: { isClosed: true, isHard: true } }, - { date: '2018-08-10', temperature: 36.75, bleeding: null, cervix: { isClosed: true, isHard: true } }, - { date: '2018-08-11', temperature: 36.9, bleeding: null, cervix: { isClosed: true, isHard: true } }, - { date: '2018-08-12', temperature: 36.95, bleeding: null, cervix: { isClosed: true, isHard: true } }, - { date: '2018-08-13', temperature: 36.95, bleeding: null, cervix: { isClosed: true, isHard: true } } + { date: '2018-08-01', bleeding: 1, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-08-02', bleeding: 2, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-08-03', temperature: 36.6, bleeding: 2, cervix: { opening: 2, firmness: 1 } }, + { date: '2018-08-04', temperature: 36.55, bleeding: 1, cervix: { opening: 2, firmness: 0 } }, + { date: '2018-08-05', temperature: 36.6, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-08-06', temperature: 36.65, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-08-07', temperature: 36.71, cervix: { opening: 1, firmness: 0 } }, + { date: '2018-08-08', temperature: 36.69, cervix: { opening: 1, firmness: 0 } }, + { date: '2018-08-09', temperature: 36.64, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-08-10', temperature: 36.66, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-08-11', temperature: 36.61, cervix: { opening: 1, firmness: 0 } }, + { date: '2018-08-12', temperature: 36.6, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-08-13', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-08-14', temperature: 36.85, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-08-15', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-08-16', temperature: 36.95, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-08-17', temperature: 36.95, cervix: { opening: 0, firmness: 0 } } ].map(convertToSymptoFormat) export const cycleWithFhmNoCervixShift = [ - { 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, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-13', temperature: 36.8, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-15', temperature: 36.9, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-17', temperature: 36.9, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-17', temperature: 36.9, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-18', temperature: 36.9, cervix: { isClosed: false, isHard: false } } + { date: '2018-08-01', bleeding: 1, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-08-02', bleeding: 2, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-08-03', temperature: 36.6, bleeding: 2, cervix: { opening: 2, firmness: 1 } }, + { date: '2018-08-04', temperature: 36.55, bleeding: 1, cervix: { opening: 2, firmness: 0 } }, + { date: '2018-08-05', temperature: 36.6, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-08-06', temperature: 36.65, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-08-07', temperature: 36.7, cervix: { opening: 1, firmness: 0 } }, + { date: '2018-08-08', temperature: 36.6, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-08-09', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-08-10', temperature: 36.85, cervix: { opening: 2, firmness: 0 } }, + { date: '2018-08-11', temperature: 36.9, cervix: { opening: 1, firmness: 0 } }, + { date: '2018-08-12', temperature: 36.95, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-08-13', temperature: 36.95, cervix: { opening: 0, firmness: 0 } } ].map(convertToSymptoFormat) -export const cycleWithoutFhm = [ +export const cycleWithoutFhmNoCervixShift = [ { date: '2018-06-02', temperature: 36.6, bleeding: 2 }, { date: '2018-06-03', temperature: 36.65 }, { date: '2018-06-04', temperature: 36.6 }, { date: '2018-06-05', temperature: 36.55 }, - { date: '2018-06-06', temperature: 36.7, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-09', temperature: 36.8, cervix: { isClosed: true, isHard: false } }, - { date: '2018-06-10', temperature: 36.9, cervix: { isClosed: false, isHard: true } }, - { date: '2018-06-13', temperature: 36.9, cervix: { isClosed: false, isHard: false } } + { date: '2018-06-06', temperature: 36.7, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-09', temperature: 36.8 }, + { date: '2018-06-10', temperature: 36.9, cervix: { opening: 2, firmness: 0 } }, + { date: '2018-06-13', temperature: 36.9, cervix: { opening: 1, firmness: 1 } } ].map(convertToSymptoFormat) export const cycleWithoutAnyShifts = [ - { date: '2018-07-01', temperature: 36.65, bleeding: 2, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-02', temperature: 36.45, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-03', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-04', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-05', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-06', temperature: 36.85, cervix: { isClosed: true, isHard: false } }, - { date: '2018-07-07', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-08', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-09', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-10', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-11', temperature: 36.35, cervix: { isClosed: true, isHard: true } }, - { date: '2018-07-12', temperature: 36.65, cervix: { isClosed: true, isHard: true } }, - { date: '2018-07-13', temperature: 36.25, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-14', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-15', temperature: 36.65, cervix: { isClosed: false, isHard: true } }, - { date: '2018-07-16', temperature: 36.15, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-17', temperature: 36.65, cervix: { isClosed: true, isHard: false } }, - { date: '2018-07-18', temperature: 36.25, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-19', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-20', temperature: 36.45, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-21', temperature: 36.5, cervix: { isClosed: true, isHard: true } }, - { date: '2018-07-22', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-23', temperature: 36.75, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-24', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, - { date: '2018-07-25', temperature: 36.65, cervix: { isClosed: true, isHard: false } }, - { date: '2018-07-26', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, + { date: '2018-07-01', temperature: 36.65, bleeding: -1, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-02', temperature: 36.45, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-03', temperature: 36.65, cervix: { opening: 2, firmness: 1 } }, + { date: '2018-07-04', temperature: 36.65, cervix: { opening: 2, firmness: 1 } }, + { date: '2018-07-05', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-06', temperature: 36.85, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-07-07', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-08', temperature: 36.65, cervix: { opening: 2, firmness: 1 } }, + { date: '2018-07-09', temperature: 36.65, cervix: { opening: 2, firmness: 1 } }, + { date: '2018-07-10', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-11', temperature: 36.35, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-07-12', temperature: 36.65, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-07-13', temperature: 36.25, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-14', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-15', temperature: 36.65, cervix: { opening: 2, firmness: 0 } }, + { date: '2018-07-16', temperature: 36.15, cervix: { opening: 2, firmness: 1 } }, + { date: '2018-07-17', temperature: 36.65, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-07-18', temperature: 36.25, cervix: { opening: 2, firmness: 1 } }, + { date: '2018-07-19', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-20', temperature: 36.45, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-21', temperature: 36.5, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-07-22', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-23', temperature: 36.75, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-24', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-25', temperature: 36.65, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-07-26', temperature: 36.65, cervix: { opening: 2, firmness: 1 } }, ].map(convertToSymptoFormat) export const longAndComplicatedCycle = [ @@ -90,22 +97,22 @@ export const longAndComplicatedCycle = [ { 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, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-09', temperature: 36.5, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-10', temperature: 36.4, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-13', temperature: 36.45, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-14', temperature: 36.5, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-15', temperature: 36.55, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-16', temperature: 36.7, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-17', temperature: 36.65, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-18', temperature: 36.75, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-19', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-20', temperature: 36.85, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-21', temperature: 36.8, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-22', temperature: 36.9, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-25', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-26', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-27', temperature: 36.9, cervix: { isClosed: true, isHard: true } } + { date: '2018-06-06', temperature: 36.7, 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-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-19', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-20', temperature: 36.85, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-06-21', temperature: 36.8, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-06-22', temperature: 36.9, cervix: { opening: 2, firmness: 1 } }, + { date: '2018-06-25', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-26', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-27', temperature: 36.9, cervix: { opening: 0, firmness: 0 } } ].map(convertToSymptoFormat) export const tempAndCervixEvalEndOnSameDay = [ @@ -115,25 +122,25 @@ export const tempAndCervixEvalEndOnSameDay = [ { date: '2018-06-04', bleeding: 2 }, { date: '2018-06-05', bleeding: 1 }, { date: '2018-06-06', bleeding: 1 }, - { date: '2018-06-07', cervix: { isClosed: false, isHard: true } }, - { date: '2018-06-08', temperature: 36.45, cervix: { isClosed: true, isHard: false } }, - { date: '2018-06-09', temperature: 36.5, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-10', temperature: 36.30, cervix: { isClosed: true, isHard: false } }, - { date: '2018-06-11', temperature: 36.30, cervix: { isClosed: false, isHard: true } }, - { date: '2018-06-12', temperature: 36.4, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-13', temperature: 36.3, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-14', temperature: 36.4, cervix: { isClosed: false, isHard: false } }, - { date: '2018-06-15', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-16', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-17', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-18', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-19', temperature: 36.95, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-20', temperature: 37.0, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-21', temperature: 37.0, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-22', temperature: 37.0, cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-23', cervix: { isClosed: true, isHard: true } }, - { date: '2018-06-24', cervix: { isClosed: true, isHard: true }}, - { date: '2018-06-25', cervix: { isClosed: false, isHard: false } } + { date: '2018-06-07', cervix: { opening: 2, firmness: 0 } }, + { date: '2018-06-08', temperature: 36.45, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-06-09', temperature: 36.5, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-10', temperature: 36.30, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-06-11', temperature: 36.30, cervix: { opening: 1, firmness: 0 } }, + { date: '2018-06-12', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-06-13', temperature: 36.3, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-06-14', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-06-15', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-16', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-17', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-18', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-19', temperature: 36.95, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-20', temperature: 37.0, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-21', temperature: 37.0, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-22', temperature: 37.0, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-23', cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-24', cervix: { opening: 0, firmness: 0 }}, + { date: '2018-06-25', cervix: { opening: 1, firmness: 1 } } ].map(convertToSymptoFormat) export const cervixShiftWaitsForTempShift = [ @@ -141,23 +148,23 @@ export const cervixShiftWaitsForTempShift = [ { date: '2018-05-09', bleeding: 2 }, { date: '2018-05-10', bleeding: 2 }, { date: '2018-05-11', bleeding: 1 }, - { date: '2018-05-12', temperature: 36.3, cervix: { isClosed: false, isHard: false } }, - { date: '2018-05-13', temperature: 36.4, cervix: { isClosed: false, isHard: false } }, - { date: '2018-05-14', temperature: 36.3, cervix: { isClosed: false, isHard: false } }, - { date: '2018-05-15', temperature: 36.2, cervix: { isClosed: false, isHard: false } }, - { date: '2018-05-16', temperature: 36.3, cervix: { isClosed: true, isHard: true } }, - { date: '2018-05-17', temperature: 36.3, cervix: { isClosed: true, isHard: true } }, - { date: '2018-05-18', temperature: 36.55, cervix: { isClosed: true, isHard: true } }, - { date: '2018-05-19', temperature: 36.65, cervix: { isClosed: true, isHard: true } }, - { date: '2018-05-20', temperature: 36.7, cervix: { isClosed: true, isHard: true } }, - { date: '2018-05-21', temperature: 36.6, cervix: { isClosed: true, isHard: true } }, - { date: '2018-05-22', temperature: 36.85, cervix: { isClosed: true, isHard: true } }, - { date: '2018-05-23', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, - { date: '2018-05-24', temperature: 36.85, cervix: { isClosed: true, isHard: true } }, - { date: '2018-05-25', temperature: 36.95, cervix: { isClosed: true, isHard: true } }, - { date: '2018-05-26', temperature: 36.85, cervix: { isClosed: true, isHard: false } }, - { date: '2018-05-27', temperature: 36.8, cervix: { isClosed: false, isHard: true } }, - { date: '2018-05-28', temperature: 36.6, cervix: { isClosed: false, isHard: true } }, + { date: '2018-05-12', temperature: 36.3, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-05-13', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-05-14', temperature: 36.3, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-05-15', temperature: 36.2, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-05-16', temperature: 36.3, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-17', temperature: 36.3, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-18', temperature: 36.55, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-19', temperature: 36.65, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-20', temperature: 36.7, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-21', temperature: 36.6, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-22', temperature: 36.85, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-23', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-24', temperature: 36.85, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-25', temperature: 36.95, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-26', temperature: 36.85, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-05-27', temperature: 36.8, cervix: { opening: 1, firmness: 0 } }, + { date: '2018-05-28', temperature: 36.6, cervix: { opening: 1, firmness: 0 } }, { date: '2018-05-29', bleeding: 2 } ].map(convertToSymptoFormat) @@ -166,22 +173,22 @@ export const tempShiftWaitsForCervixShift = [ { 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, cervix: { isClosed: false, isHard: false } }, - { date: '2018-04-10', temperature: 36.5, cervix: { isClosed: false, isHard: false } }, - { date: '2018-04-11', temperature: 36.55, cervix: { isClosed: false, isHard: false } }, - { date: '2018-04-12', temperature: 36.5, cervix: { isClosed: false, isHard: false } }, - { date: '2018-04-13', temperature: 36.35, cervix: { isClosed: false, isHard: false } }, - { date: '2018-04-14', temperature: 36.35, cervix: { isClosed: false, isHard: false } }, - { date: '2018-04-15', temperature: 36.6, cervix: { isClosed: false, isHard: false } }, - { date: '2018-04-16', temperature: 36.8, cervix: { isClosed: false, isHard: false } }, - { date: '2018-04-17', cervix: { isClosed: false, isHard: false } }, - { date: '2018-04-18', temperature: 36.8, cervix: { isClosed: false, isHard: true } }, - { date: '2018-04-19', temperature: 36.85, cervix: { isClosed: true, isHard: true } }, - { date: '2018-04-20', temperature: 37.0, cervix: { isClosed: true, isHard: true } }, - { date: '2018-04-21', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, - { date: '2018-04-22', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, - { date: '2018-04-23', temperature: 37.1, cervix: { isClosed: true, isHard: true } }, - { date: '2018-04-24', temperature: 36.75, cervix: { isClosed: false, isHard: false } } + { date: '2018-04-09', temperature: 36.5, cervix: { opening: 1, firmness: 1 } }, + { 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', cervix: { opening: 1, firmness: 1 } }, + { date: '2018-04-18', temperature: 36.8, cervix: { opening: 1, 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 } }, + { date: '2018-04-21', temperature: 36.9, 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: 1, firmness: 1 } } ].map(convertToSymptoFormat) export const noInfertilePhaseDetected = [ @@ -189,18 +196,18 @@ export const noInfertilePhaseDetected = [ { date: '2018-03-09', bleeding: 3 }, { date: '2018-03-10', bleeding: 3 }, { date: '2018-03-11', bleeding: 3 }, - { date: '2018-03-12', temperature: 36.3, cervix: { isClosed: true, isHard: false } }, - { date: '2018-03-13', temperature: 36.5, cervix: { isClosed: false, isHard: false } }, - { date: '2018-03-14', temperature: 36.45, cervix: { isClosed: false, isHard: false } }, - { date: '2018-03-15', temperature: 36.4, cervix: { isClosed: false, isHard: false } }, - { date: '2018-03-16', temperature: 36.2, cervix: { isClosed: false, isHard: false } }, - { date: '2018-03-17', temperature: 36.5, cervix: { isClosed: false, isHard: false } }, - { date: '2018-03-18', temperature: 36.6, cervix: { isClosed: false, isHard: false } }, - { date: '2018-03-19', temperature: 36.35, cervix: { isClosed: false, isHard: true } }, - { date: '2018-03-20', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, - { date: '2018-03-21', temperature: 36.7, cervix: { isClosed: true, isHard: true } }, - { date: '2018-03-22', temperature: 36.7, cervix: { isClosed: true, isHard: false } }, - { date: '2018-03-23', temperature: 36.7, cervix: { isClosed: true, isHard: true } } + { date: '2018-03-12', temperature: 36.3, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-03-13', temperature: 36.5, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-03-14', temperature: 36.45, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-03-15', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-03-16', temperature: 36.2, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-03-17', temperature: 36.5, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-03-18', temperature: 36.6, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-03-19', temperature: 36.35, cervix: { opening: 1, firmness: 0 } }, + { date: '2018-03-20', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-03-21', temperature: 36.7, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-03-22', temperature: 36.7, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-03-23', temperature: 36.7, cervix: { opening: 0, firmness: 0 } } ].map(convertToSymptoFormat) export const fiveDayCycle = [ From 20dc238ea419c2f568ebf12c9c06aee5c492fdef Mon Sep 17 00:00:00 2001 From: emelko Date: Wed, 5 Sep 2018 15:29:32 +0200 Subject: [PATCH 10/28] Replacing mucus default with secondarySymptom --- lib/sympto/index.js | 5 ++++- lib/sympto/pre-ovulatory.js | 16 ++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/sympto/index.js b/lib/sympto/index.js index c50fcbb..f93ecac 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -16,7 +16,10 @@ export default function getSymptoThermalStatus(cycleInfo) { // if there was no first higher measurement in the previous cycle, // no infertile pre-ovulatory phase may be assumed if (previousCycle) { - const statusForLast = getSymptoThermalStatus({ cycle: previousCycle }) + const statusForLast = getSymptoThermalStatus({ + cycle: previousCycle, + secondarySymptom: secondarySymptom + }) if (statusForLast.temperatureShift) { const preOvuPhase = getPreOvulatoryPhase( cycle, diff --git a/lib/sympto/pre-ovulatory.js b/lib/sympto/pre-ovulatory.js index b1e7698..c250142 100644 --- a/lib/sympto/pre-ovulatory.js +++ b/lib/sympto/pre-ovulatory.js @@ -12,7 +12,7 @@ export default function(cycle, previousCycles) { const maybePreOvuDays = cycle.slice(0, preOvuPhaseLength).filter(d => { return d.date <= preOvuEndDate }) - const preOvulatoryDays = getDaysUntilFertileMucus(maybePreOvuDays) + const preOvulatoryDays = getDaysUntilFertileSecondarySymptom(maybePreOvuDays) // if mucus occurs on the 1st cycle day, there is no pre-ovu phase if (!preOvulatoryDays.length) return null @@ -34,13 +34,17 @@ export default function(cycle, previousCycles) { } } -function getDaysUntilFertileMucus(days) { - const firstFertileMucusDayIndex = days.findIndex(day => { - return day.mucus && day.mucus.value > 1 +function getDaysUntilFertileSecondarySymptom(days, secondarySymptom) { + const firstFertileSecondarySymptomDayIndex = days.findIndex(day => { + if (secondarySymptom === 'mucus') { + return day.mucus && day.mucus.value > 1 + } else if (secondarySymptom === 'cervix') { + return day.cervix && !day.cervix.isClosedAndHard + } }) - if (firstFertileMucusDayIndex > -1) { - return days.slice(0, firstFertileMucusDayIndex) + if (firstFertileSecondarySymptomDayIndex > -1) { + return days.slice(0, firstFertileSecondarySymptomDayIndex) } return days } \ No newline at end of file From abee426337294d046d23a949899cc5cf6d39162b Mon Sep 17 00:00:00 2001 From: emelko Date: Wed, 5 Sep 2018 15:30:38 +0200 Subject: [PATCH 11/28] Renaming nextDays in nextDaysAfterFhm when calculating temperatureShift --- lib/sympto/temperature.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/sympto/temperature.js b/lib/sympto/temperature.js index 387cd63..418757b 100644 --- a/lib/sympto/temperature.js +++ b/lib/sympto/temperature.js @@ -39,18 +39,18 @@ function checkIfFirstHighMeasurement(temp, i, temperatureDays, ltl) { if (i > temperatureDays.length - 3) { return { detected: false } } - const nextDays = temperatureDays.slice(i + 1, i + 4) + const nextDaysAfterFhm = temperatureDays.slice(i + 1, i + 4) return ( - getResultForRegularRule(nextDays, ltl)) || - getResultForFirstExceptionRule(nextDays, ltl) || - getResultForSecondExceptionRule(nextDays, ltl) || + getResultForRegularRule(nextDaysAfterFhm, ltl)) || + getResultForFirstExceptionRule(nextDaysAfterFhm, ltl) || + getResultForSecondExceptionRule(nextDaysAfterFhm, ltl) || { detected: false } } -function getResultForRegularRule(nextDays, ltl) { - if (!nextDays.every(day => day.temp > ltl)) return false - const thirdDay = nextDays[1] +function getResultForRegularRule(nextDaysAfterFhm, ltl) { + if (!nextDaysAfterFhm.every(day => day.temp > ltl)) return false + const thirdDay = nextDaysAfterFhm[1] if (rounded(thirdDay.temp - ltl, 0.1) < 0.2) return false return { detected: true, @@ -60,10 +60,10 @@ function getResultForRegularRule(nextDays, ltl) { } } -function getResultForFirstExceptionRule(nextDays, ltl) { - if (nextDays.length < 3) return false - if (!nextDays.every(day => day.temp > ltl)) return false - const fourthDay = nextDays[2] +function getResultForFirstExceptionRule(nextDaysAfterFhm, ltl) { + if (nextDaysAfterFhm.length < 3) return false + if (!nextDaysAfterFhm.every(day => day.temp > ltl)) return false + const fourthDay = nextDaysAfterFhm[2] if (fourthDay.temp <= ltl) return false return { detected: true, @@ -73,10 +73,10 @@ function getResultForFirstExceptionRule(nextDays, ltl) { } } -function getResultForSecondExceptionRule(nextDays, ltl) { - if (nextDays.length < 3) return false - if (secondOrThirdTempIsAtOrBelowLtl(nextDays, ltl)) { - const fourthDay = nextDays[2] +function getResultForSecondExceptionRule(nextDaysAfterFhm, ltl) { + if (nextDaysAfterFhm.length < 3) return false + if (secondOrThirdTempIsAtOrBelowLtl(nextDaysAfterFhm, ltl)) { + const fourthDay = nextDaysAfterFhm[2] if (rounded(fourthDay.temp - ltl, 0.1) >= 0.2) { return { detected: true, @@ -89,9 +89,9 @@ function getResultForSecondExceptionRule(nextDays, ltl) { return false } -function secondOrThirdTempIsAtOrBelowLtl(nextDays, ltl) { - const secondIsLow = nextDays[0].temp <= ltl - const thirdIsLow = nextDays[1].temp <= ltl +function secondOrThirdTempIsAtOrBelowLtl(nextDaysAfterFhm, ltl) { + const secondIsLow = nextDaysAfterFhm[0].temp <= ltl + const thirdIsLow = nextDaysAfterFhm[1].temp <= ltl if ((secondIsLow || thirdIsLow) && !(secondIsLow && thirdIsLow)) { return true } else { From 809b0f438f740e991dbaef0663e55ecb7a93af5b Mon Sep 17 00:00:00 2001 From: emelko Date: Wed, 5 Sep 2018 15:31:03 +0200 Subject: [PATCH 12/28] Adding more error messages for better understanding of failing tests when arguments are wrong <3 --- lib/sympto/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/sympto/index.js b/lib/sympto/index.js index f93ecac..48e1980 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -107,14 +107,14 @@ function throwIfArgsAreNotInRequiredFormat(cycles) { assert.ok(cycle.length > 0) //what about 2 cycles of 1 day each?! assert.ok(cycle[0].bleeding !== null) assert.equal(typeof cycle[0].bleeding, 'object', "First cycle day must contain bleeding value") - assert.equal(typeof cycle[0].bleeding.value, 'number') + assert.equal(typeof cycle[0].bleeding.value, 'number', "Bleeding value must be a number") cycle.forEach(day => { assert.equal(typeof day.date, 'string') assert.doesNotThrow(() => LocalDate.parse(day.date)) - if (day.temperature) assert.equal(typeof day.temperature.value, 'number') - if (day.mucus) assert.equal(typeof day.mucus.value, 'number') - if (day.mucus) assert.ok(day.mucus.value >= 0) - if (day.mucus) assert.ok(day.mucus.value < 5) + if (day.temperature) assert.equal(typeof day.temperature.value, 'number', "temperature value must be number") + if (day.mucus) assert.equal(typeof day.mucus.value, 'number', "mucus value must be number") + if (day.mucus) assert.ok(day.mucus.value >= 0, "mucus value must be 0 or bigger") + if (day.mucus) assert.ok(day.mucus.value <= 4, "mucus value must be 4 or smaller") if (day.cervix) assert.equal(typeof day.cervix.value, 'object') if (day.cervix) assert.ok(day.cervix.value.opening >= 0, "cervix opening value must be 0 or bigger") if (day.cervix) assert.ok(day.cervix.value.opening <= 2, "cervix opening value must be 2 or smaller") From d16feb6d58fbe4fdc6b93411026ae76b2a6b7149 Mon Sep 17 00:00:00 2001 From: emelko Date: Wed, 5 Sep 2018 16:03:27 +0200 Subject: [PATCH 13/28] Renaming cervixPeak in cervixPeakBeforeShift bc it mustn't be the highest cervix value --- lib/sympto/cervix.js | 2 +- test/sympto/cervix-temp.spec.js | 2 +- test/sympto/cervix.spec.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sympto/cervix.js b/lib/sympto/cervix.js index 2e0dff4..9a59645 100644 --- a/lib/sympto/cervix.js +++ b/lib/sympto/cervix.js @@ -27,7 +27,7 @@ export default function (cycleDays, tempEvalEndIndex) { if (onlyClosedAndHardUntilEndOfTempEval) { return { detected: true, - cervixPeak: day, + cervixPeakBeforeShift: day, evaluationCompleteDay: threeFollowingDays[threeFollowingDays.length - 1] } } diff --git a/test/sympto/cervix-temp.spec.js b/test/sympto/cervix-temp.spec.js index a610d65..17e2089 100644 --- a/test/sympto/cervix-temp.spec.js +++ b/test/sympto/cervix-temp.spec.js @@ -142,9 +142,9 @@ describe('sympto', () => { start: { date: '2018-06-17', time: '18:00' }, cycleDays: tempAndCervixEvalEndOnSameDay .filter(({date}) => date >= '2018-06-17') + expect(status.cervixShift.cervixPeakBeforeShift.date).to.eql('2018-06-14') }) expect(status.cervixShift.detected).to.be.true() - expect(status.cervixShift.cervixPeak.date).to.eql('2018-06-14') expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-06-17') }) diff --git a/test/sympto/cervix.spec.js b/test/sympto/cervix.spec.js index 9bcc2a2..6c43cb9 100644 --- a/test/sympto/cervix.spec.js +++ b/test/sympto/cervix.spec.js @@ -35,7 +35,7 @@ describe('sympto', () => { const status = getCervixStatus(values) expect(status).to.eql({ detected: true, - cervixPeak: { + cervixPeakBeforeShift: { date: 13, cervix: { isHard: true, @@ -58,7 +58,7 @@ describe('sympto', () => { const status = getCervixStatus(values) expect(status).to.eql({ detected: true, - cervixPeak: { + cervixPeakBeforeShift: { date: 0, cervix: { isHard: false, From e2c8292d7f8badf281d6b13d85fa7fb7229b9d4a Mon Sep 17 00:00:00 2001 From: emelko Date: Fri, 7 Sep 2018 19:45:55 +0200 Subject: [PATCH 14/28] secondarySymptom as default; be more explicit for periOvuEnd calculation --- lib/sympto/index.js | 2 +- lib/sympto/pre-ovulatory.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sympto/index.js b/lib/sympto/index.js index 48e1980..979efc6 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -72,7 +72,7 @@ export default function getSymptoThermalStatus(cycleInfo) { if (tempOver > secondarySymptomOver) { periOvulatoryEnd = temperatureShift.evaluationCompleteDay - } else { + } else if (secondarySymptom > tempOver) { periOvulatoryEnd = secondaryShift.evaluationCompleteDay } diff --git a/lib/sympto/pre-ovulatory.js b/lib/sympto/pre-ovulatory.js index c250142..874e2bc 100644 --- a/lib/sympto/pre-ovulatory.js +++ b/lib/sympto/pre-ovulatory.js @@ -13,7 +13,7 @@ export default function(cycle, previousCycles) { return d.date <= preOvuEndDate }) const preOvulatoryDays = getDaysUntilFertileSecondarySymptom(maybePreOvuDays) - // if mucus occurs on the 1st cycle day, there is no pre-ovu phase + // if fertile mucus or cervix occurs on the 1st cycle day, there is no pre-ovu phase if (!preOvulatoryDays.length) return null let endDate @@ -34,7 +34,7 @@ export default function(cycle, previousCycles) { } } -function getDaysUntilFertileSecondarySymptom(days, secondarySymptom) { +function getDaysUntilFertileSecondarySymptom(days, secondarySymptom = 'mucus') { const firstFertileSecondarySymptomDayIndex = days.findIndex(day => { if (secondarySymptom === 'mucus') { return day.mucus && day.mucus.value > 1 @@ -47,4 +47,4 @@ function getDaysUntilFertileSecondarySymptom(days, secondarySymptom) { return days.slice(0, firstFertileSecondarySymptomDayIndex) } return days -} \ No newline at end of file +} From 0b856e298ad756a19912ed4acb20d58e188966ab Mon Sep 17 00:00:00 2001 From: emelko Date: Fri, 7 Sep 2018 19:49:03 +0200 Subject: [PATCH 15/28] Symptom values must have exclude: false for tests; consistency for defining functions --- test/sympto/mucus-temp-fixtures.js | 16 +- test/sympto/mucus-temp.spec.js | 42 +- test/sympto/mucus-temp.spec.js~HEAD | 661 ---------------------------- 3 files changed, 20 insertions(+), 699 deletions(-) delete mode 100644 test/sympto/mucus-temp.spec.js~HEAD diff --git a/test/sympto/mucus-temp-fixtures.js b/test/sympto/mucus-temp-fixtures.js index c313629..d6463c0 100644 --- a/test/sympto/mucus-temp-fixtures.js +++ b/test/sympto/mucus-temp-fixtures.js @@ -1,9 +1,17 @@ - function convertToSymptoFormat(val) { const sympto = { date: val.date } - if (val.temperature) sympto.temperature = { value: val.temperature } - if (val.mucus) sympto.mucus = { value: val.mucus } - if (val.bleeding) sympto.bleeding = { value: val.bleeding } + if (val.temperature) sympto.temperature = { + value: val.temperature, + exclude: false + } + if (val.mucus) sympto.mucus = { + value: val.mucus, + exclude: false + } + if (val.bleeding) sympto.bleeding = { + value: val.bleeding, + exclude: false + } return sympto } diff --git a/test/sympto/mucus-temp.spec.js b/test/sympto/mucus-temp.spec.js index e81ba31..dbb925b 100644 --- a/test/sympto/mucus-temp.spec.js +++ b/test/sympto/mucus-temp.spec.js @@ -22,11 +22,10 @@ import { const expect = chai.expect -describe('sympto', () => { +describe.only('sympto', () => { describe('combining temperature and mucus tracking', () => { describe('with no previous higher temp measurement', () => { - - it('with no shifts detects only peri-ovulatory', function () { + it('with no shifts detects only peri-ovulatory', () => { const status = getSensiplanStatus({ cycle: cycleWithoutAnyShifts, previousCycle: cycleWithoutFhm @@ -36,7 +35,6 @@ describe('sympto', () => { cycleDays: cycleWithoutAnyShifts }) }) - it('with temp and mucus shifts detects only peri-ovulatory and post-ovulatory', () => { const status = getSensiplanStatus({ cycle: longAndComplicatedCycle, @@ -62,15 +60,13 @@ describe('sympto', () => { }) }) - describe('with previous higher measurement', () => { - describe('with no shifts detects pre-ovulatory phase', function () { - it('according to 5-day-rule', function () { + describe('with no shifts detects pre-ovulatory phase', () => { + it('according to 5-day-rule', () => { const status = getSensiplanStatus({ cycle: fiveDayCycle, previousCycle: cycleWithFhm }) - expect(Object.keys(status.phases).length).to.eql(1) expect(status.phases.preOvulatory).to.eql({ cycleDays: fiveDayCycle, @@ -80,14 +76,12 @@ describe('sympto', () => { }) }) describe('with no shifts detects pre- and peri-ovulatory phase', () => { - it('according to 5-day-rule', function () { + it('according to 5-day-rule', () => { const status = getSensiplanStatus({ cycle: cycleWithTempAndNoMucusShift, previousCycle: cycleWithFhm }) - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.preOvulatory).to.eql({ cycleDays: cycleWithTempAndNoMucusShift .filter(({date}) => date <= '2018-06-05'), @@ -100,14 +94,12 @@ describe('sympto', () => { start: { date: '2018-06-06' } }) }) - it('according to 5-day-rule with shortened pre-phase', function () { + it('according to 5-day-rule with shortened pre-phase', () => { const status = getSensiplanStatus({ cycle: cycleWithEarlyMucus, previousCycle: cycleWithFhm }) - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.preOvulatory).to.eql({ cycleDays: [cycleWithEarlyMucus[0]], start: { date: '2018-06-01' }, @@ -119,15 +111,13 @@ describe('sympto', () => { }) }) }) - describe('with shifts detects pre- and peri-ovulatory phase', function () { - it('according to 5-day-rule', function () { + describe('with shifts detects pre- and peri-ovulatory phase', () => { + it('according to 5-day-rule', () => { const status = getSensiplanStatus({ cycle: longAndComplicatedCycle, previousCycle: cycleWithFhm }) - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ cycleDays: longAndComplicatedCycle .filter(({date}) => date <= '2018-06-05'), @@ -146,10 +136,8 @@ describe('sympto', () => { start: { date: '2018-06-21', time: '18:00'} }) }) - }) }) - describe('combining first higher measurment and mucus peak', () => { it('with fhM + mucus peak on same day finds start of postovu phase', () => { const status = getSensiplanStatus({ @@ -184,7 +172,6 @@ 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, @@ -218,7 +205,6 @@ describe('sympto', () => { .filter(({date}) => date >= '2018-06-26') }) }) - it('another example for mucus peak before temp shift', () => { const status = getSensiplanStatus({ cycle: mucusPeakSlightlyBeforeTempShift, @@ -252,16 +238,13 @@ describe('sympto', () => { .filter(({date}) => date >= '2018-06-17') }) }) - it('with another mucus peak 5 days after fHM ignores it', () => { const status = getSensiplanStatus({ cycle: mucusPeak5DaysAfterFhm, 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' }, @@ -286,13 +269,11 @@ describe('sympto', () => { .filter(({date}) => date >= '2018-06-22') }) }) - it('with mucus peak 2 days before fhM waits for end of temp eval', () => { const status = getSensiplanStatus({ cycle: mucusPeakTwoDaysBeforeFhm, previousCycle: cycleWithFhm }) - expect(status.temperatureShift).to.be.an('object') expect(status.mucusShift).to.be.an('object') @@ -320,7 +301,6 @@ describe('sympto', () => { .filter(({date}) => date >= '2018-07-03') }) }) - it('with mucus peak 5 days before fhM waits for end of temp eval', () => { const status = getSensiplanStatus({ cycle: fhm5DaysAfterMucusPeak, @@ -355,7 +335,6 @@ describe('sympto', () => { }) }) }) - describe('applying the minus-8 rule', () => { it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { const status = getSensiplanStatus({ @@ -448,7 +427,6 @@ describe('sympto', () => { }) }) }) - it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { const status = getSensiplanStatus({ cycle: cycleWithMucusOnFirstDay, @@ -464,7 +442,6 @@ describe('sympto', () => { cycleDays: cycleWithMucusOnFirstDay }) }) - it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { const status = getSensiplanStatus({ cycle: longAndComplicatedCycle, @@ -497,7 +474,6 @@ describe('sympto', () => { .filter(({date}) => date >= '2018-06-21') }) }) - it('does not lengthen the pre-ovu phase if < 12 cycles', () => { const status = getSensiplanStatus({ cycle: longAndComplicatedCycle, @@ -530,7 +506,6 @@ describe('sympto', () => { .filter(({date}) => date >= '2018-06-21') }) }) - it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { const status = getSensiplanStatus({ cycle: longAndComplicatedCycle, @@ -558,7 +533,6 @@ describe('sympto', () => { }) }) }) - describe('when args are wrong', () => { it('throws when arg object is not in right format', () => { const wrongObject = { hello: 'world' } diff --git a/test/sympto/mucus-temp.spec.js~HEAD b/test/sympto/mucus-temp.spec.js~HEAD deleted file mode 100644 index 92f346d..0000000 --- a/test/sympto/mucus-temp.spec.js~HEAD +++ /dev/null @@ -1,661 +0,0 @@ -import chai from 'chai' -import getSensiplanStatus from '../../lib/sympto' -import { AssertionError } from 'assert' -import { - cycleWithoutFhm, - longAndComplicatedCycle, - cycleWithTempAndNoMucusShift, - cycleWithFhm, - cycleWithoutAnyShifts, - fiveDayCycle, - cycleWithEarlyMucus, - cycleWithMucusOnFirstDay, - mucusPeakAndFhmOnSameDay, - fhmTwoDaysBeforeMucusPeak, - fhm5DaysAfterMucusPeak, - mucusPeak5DaysAfterFhm, - mucusPeakTwoDaysBeforeFhm, - fhmOnDay12, - fhmOnDay15, - mucusPeakSlightlyBeforeTempShift, - highestMucusQualityAfterEndOfEval -} from './mucus-temp-fixtures' - -const expect = chai.expect - -describe('sympto', () => { - describe('combining temperature and mucus tracking', () => { - describe('with no previous higher temp measurement', () => { - - it('with no shifts detects only peri-ovulatory', function () { - const status = getSensiplanStatus({ - cycle: cycleWithoutAnyShifts, - previousCycle: cycleWithoutFhm - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - cycleDays: cycleWithoutAnyShifts - }) - }) - - it('with temp and mucus shifts detects only peri-ovulatory and post-ovulatory', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm - }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-21') - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - - }) - }) - - describe('with previous higher measurement', () => { - describe('with no shifts detects pre-ovulatory phase', function () { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: fiveDayCycle, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(1) - expect(status.phases.preOvulatory).to.eql({ - cycleDays: fiveDayCycle, - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - }) - }) - describe('with no shifts detects pre- and peri-ovulatory phase', () => { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: cycleWithTempAndNoMucusShift, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date > '2018-06-05'), - start: { date: '2018-06-06' } - }) - }) - it('according to 5-day-rule with shortened pre-phase', function () { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - - 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 () { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(3) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00'} - }) - expect(status.phases.postOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21'), - start: { date: '2018-06-21', time: '18:00'} - }) - }) - - }) - }) - - describe('combining first higher measurment and mucus peak', () => { - it('with fhM + mucus peak on same day finds start of postovu phase', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakAndFhmOnSameDay, - 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: mucusPeakAndFhmOnSameDay - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: mucusPeakAndFhmOnSameDay - .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, - 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: fhmTwoDaysBeforeMucusPeak - .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 - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-26' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-26', - time: '18:00' - }, - cycleDays: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => date >= '2018-06-26') - }) - }) - - it('another example for mucus peak before temp shift', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakSlightlyBeforeTempShift, - 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: mucusPeakSlightlyBeforeTempShift - .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: mucusPeakSlightlyBeforeTempShift - .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: mucusPeakSlightlyBeforeTempShift - .filter(({date}) => date >= '2018-06-17') - }) - }) - - it('with another mucus peak 5 days after fHM ignores it', () => { - const status = getSensiplanStatus({ - cycle: mucusPeak5DaysAfterFhm, - 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-01' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - end: { date: '2018-06-22', time: '18:00' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => { - return date > '2018-06-01' && date <= '2018-06-22' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-22', - time: '18:00' - }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date >= '2018-06-22') - }) - }) - - it('with mucus peak 2 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakTwoDaysBeforeFhm, - 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-04' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-07-03', time: '18:00' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-07-03' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-07-03', - time: '18:00' - }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date >= '2018-07-03') - }) - }) - - it('with mucus peak 5 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: fhm5DaysAfterMucusPeak, - 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: fhm5DaysAfterMucusPeak - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - - describe('applying the minus-8 rule', () => { - it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] - }) - - 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-04' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - // #TODO - it.only('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - 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: fhm5DaysAfterMucusPeak - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => date >= '2018-06-21') - }) - }) - - // #TODO - 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-26', time: '18:00' }, - cycleDays: highestMucusQualityAfterEndOfEval - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-26' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-26', - time: '18:00' - }, - cycleDays: highestMucusQualityAfterEndOfEval - .filter(({date}) => date >= '2018-06-26') - }) - }) - }) - - describe('something', () => { - - it('shortens the pre-ovu phase if mucus occurs', () => { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-01' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => { - return date > '2018-06-01' - }) - }) - }) - - it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { - const status = getSensiplanStatus({ - cycle: cycleWithMucusOnFirstDay, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - - expect(Object.keys(status.phases).length).to.eql(1) - - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - cycleDays: cycleWithMucusOnFirstDay - }) - }) - - it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(11).fill(fhmOnDay15) - }) - - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-07' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-07') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-08' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-07' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('does not lengthen the pre-ovu phase if < 12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(10).fill(fhmOnDay15) - }) - - - 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: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm, - earlierCycles: [...Array(12).fill(fhmOnDay15)] - }) - - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date >= '2018-06-01' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - - describe('when args are wrong', () => { - it('throws when arg object is not in right format', () => { - const wrongObject = { hello: 'world' } - expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) - }) - it('throws if cycle array is empty', () => { - expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) - }) - it('throws if cycle days are not in right format', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - hello: 'world', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2018-04-13', - temperature: {value: '35'}, - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '09-14-2017', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - }) - it('throws if first cycle day does not have bleeding value', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2017-01-01', - bleeding: { - value: 'medium' - } - }], - earlierCycles: [[ - { - date: '2017-09-23', - } - ]] - })).to.throw(AssertionError) - }) - }) - }) -}) From 5cb4c01cecb1d5a3dde61c5533b16d0eecacb4a5 Mon Sep 17 00:00:00 2001 From: emelko Date: Fri, 7 Sep 2018 19:49:52 +0200 Subject: [PATCH 16/28] First 9 tests for cervix temp combination --- test/sympto/cervix-temp-fixtures.js | 47 ++++--- test/sympto/cervix-temp.spec.js | 196 ++++++++++++++++------------ 2 files changed, 132 insertions(+), 111 deletions(-) diff --git a/test/sympto/cervix-temp-fixtures.js b/test/sympto/cervix-temp-fixtures.js index d5b85a5..0c8ae85 100644 --- a/test/sympto/cervix-temp-fixtures.js +++ b/test/sympto/cervix-temp-fixtures.js @@ -1,4 +1,3 @@ - function convertToSymptoFormat(val) { const sympto = { date: val.date } if (val.temperature) sympto.temperature = { @@ -37,11 +36,11 @@ export const idealCycle = [ ].map(convertToSymptoFormat) export const cycleWithFhmNoCervixShift = [ - { date: '2018-08-01', bleeding: 1, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-08-02', bleeding: 2, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-08-03', temperature: 36.6, bleeding: 2, cervix: { opening: 2, firmness: 1 } }, - { date: '2018-08-04', temperature: 36.55, bleeding: 1, cervix: { opening: 2, firmness: 0 } }, - { date: '2018-08-05', temperature: 36.6, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-08-01', bleeding: 1 }, + { date: '2018-08-02', bleeding: 2 }, + { date: '2018-08-03', temperature: 36.6, bleeding: 2 }, + { date: '2018-08-04', temperature: 36.55, bleeding: 1 }, + { date: '2018-08-05', temperature: 36.6 }, { date: '2018-08-06', temperature: 36.65, cervix: { opening: 0, firmness: 1 } }, { date: '2018-08-07', temperature: 36.7, cervix: { opening: 1, firmness: 0 } }, { date: '2018-08-08', temperature: 36.6, cervix: { opening: 0, firmness: 1 } }, @@ -64,11 +63,11 @@ export const cycleWithoutFhmNoCervixShift = [ ].map(convertToSymptoFormat) export const cycleWithoutAnyShifts = [ - { date: '2018-07-01', temperature: 36.65, bleeding: -1, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-07-02', temperature: 36.45, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-07-03', temperature: 36.65, cervix: { opening: 2, firmness: 1 } }, - { date: '2018-07-04', temperature: 36.65, cervix: { opening: 2, firmness: 1 } }, - { date: '2018-07-05', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-01', temperature: 36.65, bleeding: 1 }, + { date: '2018-07-02', temperature: 36.45 }, + { date: '2018-07-03', temperature: 36.65 }, + { date: '2018-07-04', temperature: 36.65 }, + { date: '2018-07-05', temperature: 36.65, cervix: { opening: 0, firmness: 0 } }, { date: '2018-07-06', temperature: 36.85, cervix: { opening: 0, firmness: 1 } }, { date: '2018-07-07', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, { date: '2018-07-08', temperature: 36.65, cervix: { opening: 2, firmness: 1 } }, @@ -84,7 +83,7 @@ export const cycleWithoutAnyShifts = [ { date: '2018-07-18', temperature: 36.25, cervix: { opening: 2, firmness: 1 } }, { date: '2018-07-19', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, { date: '2018-07-20', temperature: 36.45, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-07-21', temperature: 36.5, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-07-21', temperature: 36.52, cervix: { opening: 0, firmness: 0 } }, { date: '2018-07-22', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, { date: '2018-07-23', temperature: 36.75, cervix: { opening: 1, firmness: 1 } }, { date: '2018-07-24', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, @@ -127,7 +126,7 @@ export const tempAndCervixEvalEndOnSameDay = [ { date: '2018-06-09', temperature: 36.5, cervix: { opening: 0, firmness: 0 } }, { date: '2018-06-10', temperature: 36.30, cervix: { opening: 0, firmness: 1 } }, { date: '2018-06-11', temperature: 36.30, cervix: { opening: 1, firmness: 0 } }, - { date: '2018-06-12', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-06-12', temperature: 36.4, cervix: { opening: 2, firmness: 1 } }, { date: '2018-06-13', temperature: 36.3, cervix: { opening: 1, firmness: 1 } }, { date: '2018-06-14', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, { date: '2018-06-15', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, @@ -143,18 +142,18 @@ export const tempAndCervixEvalEndOnSameDay = [ { date: '2018-06-25', cervix: { opening: 1, firmness: 1 } } ].map(convertToSymptoFormat) -export const cervixShiftWaitsForTempShift = [ +export const tempShift3DaysAfterCervixShift = [ { date: '2018-05-08', bleeding: 3 }, { date: '2018-05-09', bleeding: 2 }, { date: '2018-05-10', bleeding: 2 }, { date: '2018-05-11', bleeding: 1 }, - { date: '2018-05-12', temperature: 36.3, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-05-12', temperature: 36.3 }, { date: '2018-05-13', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, { date: '2018-05-14', temperature: 36.3, cervix: { opening: 1, firmness: 1 } }, { date: '2018-05-15', temperature: 36.2, cervix: { opening: 1, firmness: 1 } }, { date: '2018-05-16', temperature: 36.3, cervix: { opening: 0, firmness: 0 } }, { date: '2018-05-17', temperature: 36.3, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-05-18', temperature: 36.55, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-18', temperature: 36.35, cervix: { opening: 0, firmness: 0 } }, { date: '2018-05-19', temperature: 36.65, cervix: { opening: 0, firmness: 0 } }, { date: '2018-05-20', temperature: 36.7, cervix: { opening: 0, firmness: 0 } }, { date: '2018-05-21', temperature: 36.6, cervix: { opening: 0, firmness: 0 } }, @@ -168,12 +167,12 @@ export const cervixShiftWaitsForTempShift = [ { date: '2018-05-29', bleeding: 2 } ].map(convertToSymptoFormat) -export const tempShiftWaitsForCervixShift = [ +export const cervixShift2DaysAfterTempShift = [ { 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, cervix: { opening: 1, firmness: 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 } }, @@ -181,14 +180,13 @@ export const tempShiftWaitsForCervixShift = [ { 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', cervix: { opening: 1, firmness: 1 } }, - { date: '2018-04-18', temperature: 36.8, cervix: { opening: 1, firmness: 0 } }, + { date: '2018-04-17', temperature: 36.8, cervix: { opening: 0, 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 } }, - { date: '2018-04-21', temperature: 36.9, 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: 1, firmness: 1 } } + { date: '2018-04-24', temperature: 36.75, cervix: { opening: 0, firmness: 0 } } ].map(convertToSymptoFormat) export const noInfertilePhaseDetected = [ @@ -196,7 +194,7 @@ export const noInfertilePhaseDetected = [ { date: '2018-03-09', bleeding: 3 }, { date: '2018-03-10', bleeding: 3 }, { date: '2018-03-11', bleeding: 3 }, - { date: '2018-03-12', temperature: 36.3, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-03-12', temperature: 36.3, cervix: { opening: 0, firmness: 0 } }, { date: '2018-03-13', temperature: 36.5, cervix: { opening: 1, firmness: 1 } }, { date: '2018-03-14', temperature: 36.45, cervix: { opening: 1, firmness: 1 } }, { date: '2018-03-15', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, @@ -212,6 +210,5 @@ export const noInfertilePhaseDetected = [ export const fiveDayCycle = [ { date: '2018-08-01', bleeding: 2 }, - { date: '2018-08-03', bleeding: 3 }, - { date: '2018-08-05', bleeding: 0 } + { date: '2018-08-03', bleeding: 3 } ].map(convertToSymptoFormat) diff --git a/test/sympto/cervix-temp.spec.js b/test/sympto/cervix-temp.spec.js index 17e2089..6b06ddd 100644 --- a/test/sympto/cervix-temp.spec.js +++ b/test/sympto/cervix-temp.spec.js @@ -6,8 +6,8 @@ import { cycleWithoutFhm, cycleWithoutAnyShifts, tempAndCervixEvalEndOnSameDay, - cervixShiftWaitsForTempShift, - tempShiftWaitsForCervixShift, + tempShift3DaysAfterCervixShift, + cervixShift2DaysAfterTempShift, noInfertilePhaseDetected, fiveDayCycle } from './cervix-temp-fixtures' @@ -17,8 +17,7 @@ const expect = chai.expect describe('sympto', () => { describe('combining temperature and cervix tracking', () => { describe('with no previous higher temp measurement', () => { - - it('with no temp or cervix shifts detects only peri-ovulatory', function () { + it('with no temp or cervix shifts detects only peri-ovulatory', () => { const status = getSensiplanStatus({ cycle: cycleWithoutAnyShifts, previousCycle: cycleWithoutFhm, @@ -34,8 +33,7 @@ describe('sympto', () => { } }) }) - - it('with temp but no cervix shift detects only peri-ovulatory', function () { + it('with temp but no cervix shift detects only peri-ovulatory', () => { const status = getSensiplanStatus({ cycle: cycleWithFhmNoCervixShift, previousCycle: cycleWithoutFhm, @@ -45,85 +43,79 @@ describe('sympto', () => { expect(status).to.eql({ phases: { periOvulatory: { - start: { date: '2018-06-01' }, + start: { date: '2018-08-01' }, cycleDays: cycleWithFhmNoCervixShift } } }) }) - - it('with temp and cervix shifts detects only peri- and post-ovulatory phases', function () { + it('with temp and cervix shifts detects only peri- and post-ovulatory phases', () => { const status = getSensiplanStatus({ cycle: idealCycle, previousCycle: cycleWithoutFhm, secondarySymptom: 'cervix' }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.cervixShift).to.be.an('object') - expect(Object.keys(status.phases).length).to.eql(2) + expect(status.temperatureShift.evaluationCompleteDay.date).to.eql('2018-08-15') + expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-08-15') + expect(status.temperatureShift.rule).to.eql(0) expect(status.phases.periOvulatory).to.eql({ start: { date: '2018-08-01' }, - end: { date: '2018-08-11', time: '18:00' }, + end: { date: '2018-08-15', time: '18:00' }, cycleDays: idealCycle - .filter(({date}) => date <= '2018-08-11') + .filter(({date}) => date <= '2018-08-15') }) expect(status.phases.postOvulatory).to.eql({ - start: { date: '2018-08-11', time: '18:00' }, + start: { date: '2018-08-15', time: '18:00' }, cycleDays: idealCycle - .filter(({date}) => date >= '2018-08-11') + .filter(({date}) => date >= '2018-08-15') }) }) - }) describe('with previous higher temp measurement', () => { - - describe('with no shifts detects only peri-ovulatory', function () { - it.skip('according to 5-day rule', function () { - const status = getSensiplanStatus({ - cycle: fiveDayCycle, - previousCycle: cycleWithFhmNoCervixShift - }) - - expect(Object.keys(status.phases).length).to.eql(1) - expect(status.phases.preOvulatory).to.eql({ - cycleDays: fiveDayCycle, - start: { date: '2018-08-01' }, - end: { date: '2018-08-05' } - }) + it('with no shifts detects only peri-ovulatory in 3-day long cycle according to 5-day rule', () => { + const status = getSensiplanStatus({ + cycle: fiveDayCycle, + previousCycle: idealCycle, + secondarySymptom: 'cervix' + }) + expect(Object.keys(status.phases).length).to.eql(1) + expect(status.phases.preOvulatory).to.eql({ + cycleDays: fiveDayCycle, + start: { date: '2018-08-01' }, + end: { date: '2018-08-05' } }) }) + it('with no shifts detects pre- and peri-ovulatory phase according to 5-day-rule', () => { + const status = getSensiplanStatus({ + cycle: cycleWithoutAnyShifts, + previousCycle: idealCycle, + secondarySymptom: 'cervix' + }) - describe('with no shifts detects pre- and peri-ovulatory phase', () => { - it.skip('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: cycleWithoutAnyShifts, - previousCycle: cycleWithFhmNoCervixShift - }) - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.preOvulatory).to.eql({ - cycleDays: cycleWithoutAnyShifts - .filter(({date}) => date <= '2018-07-05'), - start: { date: '2018-07-01' }, - end: { date: '2018-07-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: cycleWithoutAnyShifts - .filter(({date}) => date > '2018-07-05'), - start: { date: '2018-07-06' } - }) + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.preOvulatory).to.eql({ + cycleDays: cycleWithoutAnyShifts + .filter(({date}) => date <= '2018-07-05'), + start: { date: '2018-07-01' }, + end: { date: '2018-07-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: cycleWithoutAnyShifts + .filter(({date}) => date >= '2018-07-06'), + start: { date: '2018-07-06' } }) }) - it('with evaluation of temperature and cervix end on same day', () => { const status = getSensiplanStatus({ cycle: tempAndCervixEvalEndOnSameDay, - previousCycle: cycleWithFhmNoCervixShift, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) + expect(status.temperatureShift.evaluationCompleteDay.date).to.eql('2018-06-17') + expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-06-17') + expect(status.phases.preOvulatory).to.eql({ start: { date: '2018-06-01' }, end: { date: '2018-06-05' }, @@ -142,58 +134,90 @@ describe('sympto', () => { start: { date: '2018-06-17', time: '18:00' }, cycleDays: tempAndCervixEvalEndOnSameDay .filter(({date}) => date >= '2018-06-17') - expect(status.cervixShift.cervixPeakBeforeShift.date).to.eql('2018-06-14') }) - expect(status.cervixShift.detected).to.be.true() - expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-06-17') }) - - - it('when cervix shift waits for temperature shift', () => { + it('when temperature shift happens 3 days after cervix shift', () => { const status = getSensiplanStatus({ - cycle: cervixShiftWaitsForTempShift, - previousCycle: cycleWithFhmNoCervixShift, + cycle: tempShift3DaysAfterCervixShift, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) - expect(status.cervixShift.detected).to.be.true() - }) + expect(status.cervixShift).to.be.an('object') + expect(status.temperatureShift).to.be.an('object') + expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-05-18') + expect(status.temperatureShift.evaluationCompleteDay.date).to.eql('2018-05-21') - it('when temperature shift waits for cervix shift', () => { + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-05-08' }, + end: { date: '2018-05-12' }, + cycleDays: tempShift3DaysAfterCervixShift + .filter(({date}) => date <= '2018-05-12') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date:'2018-05-13'}, + end: { date: '2018-05-21', time: '18:00' }, + cycleDays: tempShift3DaysAfterCervixShift + .filter(({date}) => { + return date >= '2018-05-13' && date <= '2018-05-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { date: '2018-05-21', time: '18:00' }, + cycleDays: tempShift3DaysAfterCervixShift + .filter(({date}) => date >= '2018-05-21') + }) + }) + it('when cervix shift happens 2 days after temperature shift', () => { const status = getSensiplanStatus({ - cycle: tempShiftWaitsForCervixShift, - previousCycle: cycleWithFhmNoCervixShift, + cycle: cervixShift2DaysAfterTempShift, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) - expect(status.cervixShift.detected).to.be.true() - }) + 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.phases.preOvulatory).to.eql({ + cycleDays: cervixShift2DaysAfterTempShift + .filter(({date}) => date <= '2018-04-09'), + start: { date: '2018-04-05' }, + end: { date: '2018-04-09' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: cervixShift2DaysAfterTempShift + .filter(({date}) => { + return date >= '2018-04-10' && date <= '2018-04-19' + }), + start: { date: '2018-04-10' }, + end: { date: '2018-04-19', 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' } + }) + }) it('when no infertile phase can be detected', () => { const status = getSensiplanStatus({ cycle: noInfertilePhaseDetected, - previousCycle: cycleWithFhmNoCervixShift, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(2) - }) - - }) - - it('', function () { - const status = getSensiplanStatus({ - cycle: idealCycle, - previousCycle: idealCycle, - secondarySymptom: 'cervix' - }) - - expect(Object.keys(status.phases).length).to.eql() - expect(status).to.eql({ - phases: { - - } + expect(status.phases.preOvulatory).to.eql({ + cycleDays: noInfertilePhaseDetected + .filter(({date}) => date <= '2018-03-12'), + start: { date: '2018-03-08' }, + end: { date: '2018-03-12' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: noInfertilePhaseDetected + .filter(({date}) => date > '2018-03-12'), + start: { date: '2018-03-13' } + }) }) }) - }) }) From d644c880d5df86f5a989ac55511fbafbfcde0b3b Mon Sep 17 00:00:00 2001 From: emelko Date: Fri, 7 Sep 2018 20:10:32 +0200 Subject: [PATCH 17/28] Deletes cervix out of chart --- components/chart/day-column.js | 1 - 1 file changed, 1 deletion(-) diff --git a/components/chart/day-column.js b/components/chart/day-column.js index 20fbcf8..630abc8 100644 --- a/components/chart/day-column.js +++ b/components/chart/day-column.js @@ -29,7 +29,6 @@ export default class DayColumn extends Component { temperatureExclude, bleeding, mucus, - cervix, drawFhmLine, drawLtlAt, rightY, From ef45fd909801521f9c989641bbff4df2baeda708 Mon Sep 17 00:00:00 2001 From: emelko Date: Sat, 8 Sep 2018 12:45:58 +0200 Subject: [PATCH 18/28] Deleting unused code --- components/chart/styles.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/components/chart/styles.js b/components/chart/styles.js index 0b8a49c..d7ab484 100644 --- a/components/chart/styles.js +++ b/components/chart/styles.js @@ -61,11 +61,6 @@ const styles = { '#a64ca6', '#993299' ], - cervixIcon: { - width: 12, - height: 12, - borderRadius: 50 - }, yAxis: { width: config.columnWidth, borderRightWidth: 0.5, From 9f5eb7c32efa98f00635580fadb3ca6c4b6b1559 Mon Sep 17 00:00:00 2001 From: emelko Date: Sat, 8 Sep 2018 12:53:37 +0200 Subject: [PATCH 19/28] Adding when temp and secSymptom evaluation is over at the same day --- lib/sympto/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sympto/index.js b/lib/sympto/index.js index d51fda7..3c8207f 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -70,7 +70,7 @@ export default function getSymptoThermalStatus(cycleInfo) { const tempOver = temperatureShift.evaluationCompleteDay.date const secondarySymptomOver = secondaryShift.evaluationCompleteDay.date - if (tempOver > secondarySymptomOver) { + if (tempOver >= secondarySymptomOver) { periOvulatoryEnd = temperatureShift.evaluationCompleteDay } else if (secondarySymptom > tempOver) { periOvulatoryEnd = secondaryShift.evaluationCompleteDay From e1d6345434cbda512e1dbc9485208fd8ba2de3cf Mon Sep 17 00:00:00 2001 From: emelko Date: Sat, 8 Sep 2018 12:57:38 +0200 Subject: [PATCH 20/28] Removing comment & making error comments even more helpful --- lib/sympto/index.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/sympto/index.js b/lib/sympto/index.js index 3c8207f..d73d635 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -104,21 +104,21 @@ export default function getSymptoThermalStatus(cycleInfo) { function throwIfArgsAreNotInRequiredFormat(cycles) { cycles.forEach(cycle => { assert.ok(Array.isArray(cycle), "Cycles must be arrays.") - assert.ok(cycle.length > 0, "Cycle must not be empty.") //what about 2 cycles of 1 day each?! + assert.ok(cycle.length > 0, "Cycle must not be empty.") assert.ok(cycle[0].bleeding !== null, "First cycle day should have bleeding.") assert.equal(typeof cycle[0].bleeding, 'object', "First cycle day must contain bleeding value.") - assert.equal(typeof cycle[0].bleeding.value, 'number', "First cycle day bleeding value is a number.") + assert.equal(typeof cycle[0].bleeding.value, 'number', "First cycle day bleeding value must be a number.") cycle.forEach(day => { - assert.equal(typeof day.date, 'string', "Date is given as a string.") - assert.doesNotThrow(() => LocalDate.parse(day.date), "Date is given in right string format.") - if (day.temperature) assert.equal(typeof day.temperature.value, 'number', "Temperature value is a number.") - if (day.mucus) assert.equal(typeof day.mucus.value, 'number', "Mucus value is a number.") - if (day.mucus) assert.ok(day.mucus.value >= 0, "Mucus value is greater or equal to 0.") - if (day.mucus) assert.ok(day.mucus.value <= 4, "Mucus value below 5.") - if (day.cervix) assert.ok(day.cervix.value.opening >= 0, "cervix opening value must be 0 or bigger") - if (day.cervix) assert.ok(day.cervix.value.opening <= 2, "cervix opening value must be 2 or smaller") - if (day.cervix) assert.ok(day.cervix.value.firmness >= 0, "cervix firmness value must be 0 or bigger") - if (day.cervix) assert.ok(day.cervix.value.firmness <= 1, "cervix firmness value must be 1 or smaller") + assert.equal(typeof day.date, 'string', "Date must be given as a string.") + assert.doesNotThrow(() => LocalDate.parse(day.date), "Date must be given in right string format.") + if (day.temperature) assert.equal(typeof day.temperature.value, 'number', "Temperature value must be a number.") + if (day.mucus) assert.equal(typeof day.mucus.value, 'number', "Mucus value must be a number.") + if (day.mucus) assert.ok(day.mucus.value >= 0, "Mucus value must greater or equal to 0.") + if (day.mucus) assert.ok(day.mucus.value <= 4, "Mucus value must be below 5.") + if (day.cervix) assert.ok(day.cervix.value.opening >= 0, "Cervix opening value must be 0 or bigger") + if (day.cervix) assert.ok(day.cervix.value.opening <= 2, "Cervix opening value must be 2 or smaller") + if (day.cervix) assert.ok(day.cervix.value.firmness >= 0, "Cervix firmness value must be 0 or bigger") + if (day.cervix) assert.ok(day.cervix.value.firmness <= 1, "Cervix firmness value must be 1 or smaller") assert.equal(typeof cycle[0].bleeding.value, 'number', "Bleeding value must be a number") }) }) From 969da1d16346edae005459c07003826c84cda190 Mon Sep 17 00:00:00 2001 From: emelko Date: Sat, 8 Sep 2018 13:22:17 +0200 Subject: [PATCH 21/28] Renaming test cycles to be more explicit abt what they do --- test/sympto/cervix-temp-fixtures.js | 4 ++-- test/sympto/cervix-temp.spec.js | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/sympto/cervix-temp-fixtures.js b/test/sympto/cervix-temp-fixtures.js index 0c8ae85..c7e7df3 100644 --- a/test/sympto/cervix-temp-fixtures.js +++ b/test/sympto/cervix-temp-fixtures.js @@ -15,7 +15,7 @@ function convertToSymptoFormat(val) { return sympto } -export const idealCycle = [ +export const cervixShiftAndFhmOnSameDay = [ { date: '2018-08-01', bleeding: 1, cervix: { opening: 1, firmness: 1 } }, { date: '2018-08-02', bleeding: 2, cervix: { opening: 1, firmness: 1 } }, { date: '2018-08-03', temperature: 36.6, bleeding: 2, cervix: { opening: 2, firmness: 1 } }, @@ -189,7 +189,7 @@ export const cervixShift2DaysAfterTempShift = [ { date: '2018-04-24', temperature: 36.75, cervix: { opening: 0, firmness: 0 } } ].map(convertToSymptoFormat) -export const noInfertilePhaseDetected = [ +export const noOvulationDetected = [ { date: '2018-03-08', bleeding: 3 }, { date: '2018-03-09', bleeding: 3 }, { date: '2018-03-10', bleeding: 3 }, diff --git a/test/sympto/cervix-temp.spec.js b/test/sympto/cervix-temp.spec.js index 6b06ddd..3f20a5e 100644 --- a/test/sympto/cervix-temp.spec.js +++ b/test/sympto/cervix-temp.spec.js @@ -1,14 +1,14 @@ import chai from 'chai' import getSensiplanStatus from '../../lib/sympto' import { - idealCycle, + cervixShiftAndFhmOnSameDay, cycleWithFhmNoCervixShift, cycleWithoutFhm, cycleWithoutAnyShifts, tempAndCervixEvalEndOnSameDay, tempShift3DaysAfterCervixShift, cervixShift2DaysAfterTempShift, - noInfertilePhaseDetected, + noOvulationDetected, fiveDayCycle } from './cervix-temp-fixtures' @@ -51,7 +51,7 @@ describe('sympto', () => { }) it('with temp and cervix shifts detects only peri- and post-ovulatory phases', () => { const status = getSensiplanStatus({ - cycle: idealCycle, + cycle: cervixShiftAndFhmOnSameDay, previousCycle: cycleWithoutFhm, secondarySymptom: 'cervix' }) @@ -62,12 +62,12 @@ describe('sympto', () => { expect(status.phases.periOvulatory).to.eql({ start: { date: '2018-08-01' }, end: { date: '2018-08-15', time: '18:00' }, - cycleDays: idealCycle + cycleDays: cervixShiftAndFhmOnSameDay .filter(({date}) => date <= '2018-08-15') }) expect(status.phases.postOvulatory).to.eql({ start: { date: '2018-08-15', time: '18:00' }, - cycleDays: idealCycle + cycleDays: cervixShiftAndFhmOnSameDay .filter(({date}) => date >= '2018-08-15') }) }) @@ -76,7 +76,7 @@ describe('sympto', () => { it('with no shifts detects only peri-ovulatory in 3-day long cycle according to 5-day rule', () => { const status = getSensiplanStatus({ cycle: fiveDayCycle, - previousCycle: idealCycle, + previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(1) @@ -89,7 +89,7 @@ describe('sympto', () => { it('with no shifts detects pre- and peri-ovulatory phase according to 5-day-rule', () => { const status = getSensiplanStatus({ cycle: cycleWithoutAnyShifts, - previousCycle: idealCycle, + previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) @@ -109,7 +109,7 @@ describe('sympto', () => { it('with evaluation of temperature and cervix end on same day', () => { const status = getSensiplanStatus({ cycle: tempAndCervixEvalEndOnSameDay, - previousCycle: idealCycle, + previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) @@ -139,7 +139,7 @@ describe('sympto', () => { it('when temperature shift happens 3 days after cervix shift', () => { const status = getSensiplanStatus({ cycle: tempShift3DaysAfterCervixShift, - previousCycle: idealCycle, + previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) @@ -171,7 +171,7 @@ describe('sympto', () => { it('when cervix shift happens 2 days after temperature shift', () => { const status = getSensiplanStatus({ cycle: cervixShift2DaysAfterTempShift, - previousCycle: idealCycle, + previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) @@ -201,19 +201,19 @@ describe('sympto', () => { }) it('when no infertile phase can be detected', () => { const status = getSensiplanStatus({ - cycle: noInfertilePhaseDetected, - previousCycle: idealCycle, + cycle: noOvulationDetected, + previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(2) expect(status.phases.preOvulatory).to.eql({ - cycleDays: noInfertilePhaseDetected + 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: noInfertilePhaseDetected + cycleDays: noOvulationDetected .filter(({date}) => date > '2018-03-12'), start: { date: '2018-03-13' } }) From ab2dd76bf41a86aea3fe3f56ebd7c1a523ec24d8 Mon Sep 17 00:00:00 2001 From: emelko Date: Sat, 8 Sep 2018 13:27:38 +0200 Subject: [PATCH 22/28] Liberating a forgotten .only from tests --- test/sympto/mucus-temp.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sympto/mucus-temp.spec.js b/test/sympto/mucus-temp.spec.js index dbb925b..c2a2563 100644 --- a/test/sympto/mucus-temp.spec.js +++ b/test/sympto/mucus-temp.spec.js @@ -22,7 +22,7 @@ import { const expect = chai.expect -describe.only('sympto', () => { +describe('sympto', () => { describe('combining temperature and mucus tracking', () => { describe('with no previous higher temp measurement', () => { it('with no shifts detects only peri-ovulatory', () => { From 1b0d04dfc06426e926e413cd9f90f5d075c68d5d Mon Sep 17 00:00:00 2001 From: emelko Date: Sat, 8 Sep 2018 14:47:31 +0200 Subject: [PATCH 23/28] Fixing cervix unit tests --- test/sympto/cervix.spec.js | 56 ++++++++++++-------------------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/test/sympto/cervix.spec.js b/test/sympto/cervix.spec.js index 6c43cb9..f935945 100644 --- a/test/sympto/cervix.spec.js +++ b/test/sympto/cervix.spec.js @@ -5,53 +5,45 @@ const expect = chai.expect function turnIntoCycleDayObject(value, fakeDate) { const hardAndClosed = { - isHard: true, - isClosed: true + value: { opening: 0, firmness: 0 } } const hardAndOpen = { - isHard: true, - isClosed: false + value: { opening: 1, firmness: 0 } } const softAndClosed = { - isHard: false, - isClosed: true + value: { opening: 0, firmness: 1 } } const softAndOpen = { - isHard: false, - isClosed: false + value: { opening: 1, firmness: 1 } } const cervixStates = [hardAndClosed, hardAndOpen, softAndClosed, softAndOpen] return { - cervix : cervixStates[value], - date: fakeDate + date: fakeDate, + cervix: cervixStates[value], + exclude: false } } describe('sympto', () => { describe('detects cervix shift', () => { - it('when an ideal cycle happens', function () { - const values = [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 0, 0, 0, 0] + it('when shift happens at day 15 with consistent following days', function () { + const values = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 3, 1, 3, 1, 0, 0, 0, 0] .map(turnIntoCycleDayObject) const status = getCervixStatus(values) expect(status).to.eql({ detected: true, cervixPeakBeforeShift: { date: 13, - cervix: { - isHard: true, - isClosed: false - } + cervix: {value: { opening: 1, firmness: 0 }}, + exclude: false }, evaluationCompleteDay: { date: 16, - cervix: { - isHard: true, - isClosed: true - } + cervix: { value: { opening: 0, firmness: 0 }}, + exclude: false } }) }) - it('at the very first day of cycle days even if later shift happens again', function () { const values = [2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] .map(turnIntoCycleDayObject) @@ -60,17 +52,13 @@ describe('sympto', () => { detected: true, cervixPeakBeforeShift: { date: 0, - cervix: { - isHard: false, - isClosed: true - } + cervix: { value: { opening: 0, firmness: 1 } }, + exclude: false }, evaluationCompleteDay: { date: 3, - cervix: { - isHard: true, - isClosed: true - } + cervix: { value: { opening: 0, firmness: 0 } }, + exclude: false } }) }) @@ -83,32 +71,22 @@ describe('sympto', () => { const status = getCervixStatus(values) expect(status).to.eql({ detected: false }) }) - it('if there are no cervix values', function () { const values = [].map(turnIntoCycleDayObject) const status = getCervixStatus(values) expect(status).to.eql({ detected: false }) }) - it('when the cervix values are all the same', function () { const values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] .map(turnIntoCycleDayObject) const status = getCervixStatus(values) expect(status).to.eql({ detected: false }) }) - it('if no days of hard and closed cervix are tracked', function () { const values = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1] .map(turnIntoCycleDayObject) const status = getCervixStatus(values) expect(status).to.eql({ detected: false }) }) - - it('if days of hard and closed cervix are fewer than 3', function () { - const values = [1, 3, 2, 1, 0, 2, 1, 3, 2, 0, 0, 2, 1, 3, 2, 1] - .map(turnIntoCycleDayObject) - const status = getCervixStatus(values) - expect(status).to.eql({ detected: false }) - }) }) }) From 21dba52753027a2c85e4832fc1091c293afe657b Mon Sep 17 00:00:00 2001 From: emelko Date: Sun, 9 Sep 2018 16:35:16 +0200 Subject: [PATCH 24/28] Renaming for more precision --- lib/sympto/temperature.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/sympto/temperature.js b/lib/sympto/temperature.js index 418757b..fb380b5 100644 --- a/lib/sympto/temperature.js +++ b/lib/sympto/temperature.js @@ -39,18 +39,18 @@ function checkIfFirstHighMeasurement(temp, i, temperatureDays, ltl) { if (i > temperatureDays.length - 3) { return { detected: false } } - const nextDaysAfterFhm = temperatureDays.slice(i + 1, i + 4) + const nextDaysAfterPotentialFhm = temperatureDays.slice(i + 1, i + 4) return ( - getResultForRegularRule(nextDaysAfterFhm, ltl)) || - getResultForFirstExceptionRule(nextDaysAfterFhm, ltl) || - getResultForSecondExceptionRule(nextDaysAfterFhm, ltl) || + getResultForRegularRule(nextDaysAfterPotentialFhm, ltl)) || + getResultForFirstExceptionRule(nextDaysAfterPotentialFhm, ltl) || + getResultForSecondExceptionRule(nextDaysAfterPotentialFhm, ltl) || { detected: false } } -function getResultForRegularRule(nextDaysAfterFhm, ltl) { - if (!nextDaysAfterFhm.every(day => day.temp > ltl)) return false - const thirdDay = nextDaysAfterFhm[1] +function getResultForRegularRule(nextDaysAfterPotentialFhm, ltl) { + if (!nextDaysAfterPotentialFhm.every(day => day.temp > ltl)) return false + const thirdDay = nextDaysAfterPotentialFhm[1] if (rounded(thirdDay.temp - ltl, 0.1) < 0.2) return false return { detected: true, @@ -60,10 +60,10 @@ function getResultForRegularRule(nextDaysAfterFhm, ltl) { } } -function getResultForFirstExceptionRule(nextDaysAfterFhm, ltl) { - if (nextDaysAfterFhm.length < 3) return false - if (!nextDaysAfterFhm.every(day => day.temp > ltl)) return false - const fourthDay = nextDaysAfterFhm[2] +function getResultForFirstExceptionRule(nextDaysAfterPotentialFhm, ltl) { + if (nextDaysAfterPotentialFhm.length < 3) return false + if (!nextDaysAfterPotentialFhm.every(day => day.temp > ltl)) return false + const fourthDay = nextDaysAfterPotentialFhm[2] if (fourthDay.temp <= ltl) return false return { detected: true, @@ -73,10 +73,10 @@ function getResultForFirstExceptionRule(nextDaysAfterFhm, ltl) { } } -function getResultForSecondExceptionRule(nextDaysAfterFhm, ltl) { - if (nextDaysAfterFhm.length < 3) return false - if (secondOrThirdTempIsAtOrBelowLtl(nextDaysAfterFhm, ltl)) { - const fourthDay = nextDaysAfterFhm[2] +function getResultForSecondExceptionRule(nextDaysAfterPotentialFhm, ltl) { + if (nextDaysAfterPotentialFhm.length < 3) return false + if (secondOrThirdTempIsAtOrBelowLtl(nextDaysAfterPotentialFhm, ltl)) { + const fourthDay = nextDaysAfterPotentialFhm[2] if (rounded(fourthDay.temp - ltl, 0.1) >= 0.2) { return { detected: true, @@ -89,9 +89,9 @@ function getResultForSecondExceptionRule(nextDaysAfterFhm, ltl) { return false } -function secondOrThirdTempIsAtOrBelowLtl(nextDaysAfterFhm, ltl) { - const secondIsLow = nextDaysAfterFhm[0].temp <= ltl - const thirdIsLow = nextDaysAfterFhm[1].temp <= ltl +function secondOrThirdTempIsAtOrBelowLtl(nextDaysAfterPotentialFhm, ltl) { + const secondIsLow = nextDaysAfterPotentialFhm[0].temp <= ltl + const thirdIsLow = nextDaysAfterPotentialFhm[1].temp <= ltl if ((secondIsLow || thirdIsLow) && !(secondIsLow && thirdIsLow)) { return true } else { From 2f42840faab33a66410d8a4e2927b02e15de98b1 Mon Sep 17 00:00:00 2001 From: emelko Date: Mon, 10 Sep 2018 12:09:37 +0200 Subject: [PATCH 25/28] Revert "Renaming test cycles to be more explicit abt what they do" This reverts commit 969da1d16346edae005459c07003826c84cda190. --- test/sympto/cervix-temp-fixtures.js | 4 ++-- test/sympto/cervix-temp.spec.js | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/sympto/cervix-temp-fixtures.js b/test/sympto/cervix-temp-fixtures.js index c7e7df3..0c8ae85 100644 --- a/test/sympto/cervix-temp-fixtures.js +++ b/test/sympto/cervix-temp-fixtures.js @@ -15,7 +15,7 @@ function convertToSymptoFormat(val) { return sympto } -export const cervixShiftAndFhmOnSameDay = [ +export const idealCycle = [ { date: '2018-08-01', bleeding: 1, cervix: { opening: 1, firmness: 1 } }, { date: '2018-08-02', bleeding: 2, cervix: { opening: 1, firmness: 1 } }, { date: '2018-08-03', temperature: 36.6, bleeding: 2, cervix: { opening: 2, firmness: 1 } }, @@ -189,7 +189,7 @@ export const cervixShift2DaysAfterTempShift = [ { date: '2018-04-24', temperature: 36.75, cervix: { opening: 0, firmness: 0 } } ].map(convertToSymptoFormat) -export const noOvulationDetected = [ +export const noInfertilePhaseDetected = [ { date: '2018-03-08', bleeding: 3 }, { date: '2018-03-09', bleeding: 3 }, { date: '2018-03-10', bleeding: 3 }, diff --git a/test/sympto/cervix-temp.spec.js b/test/sympto/cervix-temp.spec.js index 3f20a5e..6b06ddd 100644 --- a/test/sympto/cervix-temp.spec.js +++ b/test/sympto/cervix-temp.spec.js @@ -1,14 +1,14 @@ import chai from 'chai' import getSensiplanStatus from '../../lib/sympto' import { - cervixShiftAndFhmOnSameDay, + idealCycle, cycleWithFhmNoCervixShift, cycleWithoutFhm, cycleWithoutAnyShifts, tempAndCervixEvalEndOnSameDay, tempShift3DaysAfterCervixShift, cervixShift2DaysAfterTempShift, - noOvulationDetected, + noInfertilePhaseDetected, fiveDayCycle } from './cervix-temp-fixtures' @@ -51,7 +51,7 @@ describe('sympto', () => { }) it('with temp and cervix shifts detects only peri- and post-ovulatory phases', () => { const status = getSensiplanStatus({ - cycle: cervixShiftAndFhmOnSameDay, + cycle: idealCycle, previousCycle: cycleWithoutFhm, secondarySymptom: 'cervix' }) @@ -62,12 +62,12 @@ describe('sympto', () => { expect(status.phases.periOvulatory).to.eql({ start: { date: '2018-08-01' }, end: { date: '2018-08-15', time: '18:00' }, - cycleDays: cervixShiftAndFhmOnSameDay + cycleDays: idealCycle .filter(({date}) => date <= '2018-08-15') }) expect(status.phases.postOvulatory).to.eql({ start: { date: '2018-08-15', time: '18:00' }, - cycleDays: cervixShiftAndFhmOnSameDay + cycleDays: idealCycle .filter(({date}) => date >= '2018-08-15') }) }) @@ -76,7 +76,7 @@ describe('sympto', () => { it('with no shifts detects only peri-ovulatory in 3-day long cycle according to 5-day rule', () => { const status = getSensiplanStatus({ cycle: fiveDayCycle, - previousCycle: cervixShiftAndFhmOnSameDay, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(1) @@ -89,7 +89,7 @@ describe('sympto', () => { it('with no shifts detects pre- and peri-ovulatory phase according to 5-day-rule', () => { const status = getSensiplanStatus({ cycle: cycleWithoutAnyShifts, - previousCycle: cervixShiftAndFhmOnSameDay, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) @@ -109,7 +109,7 @@ describe('sympto', () => { it('with evaluation of temperature and cervix end on same day', () => { const status = getSensiplanStatus({ cycle: tempAndCervixEvalEndOnSameDay, - previousCycle: cervixShiftAndFhmOnSameDay, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) @@ -139,7 +139,7 @@ describe('sympto', () => { it('when temperature shift happens 3 days after cervix shift', () => { const status = getSensiplanStatus({ cycle: tempShift3DaysAfterCervixShift, - previousCycle: cervixShiftAndFhmOnSameDay, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) @@ -171,7 +171,7 @@ describe('sympto', () => { it('when cervix shift happens 2 days after temperature shift', () => { const status = getSensiplanStatus({ cycle: cervixShift2DaysAfterTempShift, - previousCycle: cervixShiftAndFhmOnSameDay, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) @@ -201,19 +201,19 @@ describe('sympto', () => { }) it('when no infertile phase can be detected', () => { const status = getSensiplanStatus({ - cycle: noOvulationDetected, - previousCycle: cervixShiftAndFhmOnSameDay, + cycle: noInfertilePhaseDetected, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(2) expect(status.phases.preOvulatory).to.eql({ - cycleDays: noOvulationDetected + cycleDays: noInfertilePhaseDetected .filter(({date}) => date <= '2018-03-12'), start: { date: '2018-03-08' }, end: { date: '2018-03-12' } }) expect(status.phases.periOvulatory).to.eql({ - cycleDays: noOvulationDetected + cycleDays: noInfertilePhaseDetected .filter(({date}) => date > '2018-03-12'), start: { date: '2018-03-13' } }) From 3f5c86086de237b8721ab65737878bb3ff0c8921 Mon Sep 17 00:00:00 2001 From: emelko Date: Mon, 10 Sep 2018 12:28:54 +0200 Subject: [PATCH 26/28] Renaming test cycles for cervix+temp to be more explicit abt what they do --- test/sympto/cervix-temp-fixtures.js | 34 ++------------ test/sympto/cervix-temp.spec.js | 71 ++++++++++++++--------------- 2 files changed, 38 insertions(+), 67 deletions(-) diff --git a/test/sympto/cervix-temp-fixtures.js b/test/sympto/cervix-temp-fixtures.js index 0c8ae85..0299524 100644 --- a/test/sympto/cervix-temp-fixtures.js +++ b/test/sympto/cervix-temp-fixtures.js @@ -15,7 +15,7 @@ function convertToSymptoFormat(val) { return sympto } -export const idealCycle = [ +export const cervixShiftAndFhmOnSameDay = [ { date: '2018-08-01', bleeding: 1, cervix: { opening: 1, firmness: 1 } }, { date: '2018-08-02', bleeding: 2, cervix: { opening: 1, firmness: 1 } }, { date: '2018-08-03', temperature: 36.6, bleeding: 2, cervix: { opening: 2, firmness: 1 } }, @@ -62,7 +62,7 @@ export const cycleWithoutFhmNoCervixShift = [ { date: '2018-06-13', temperature: 36.9, cervix: { opening: 1, firmness: 1 } } ].map(convertToSymptoFormat) -export const cycleWithoutAnyShifts = [ +export const longCycleWithoutAnyShifts = [ { date: '2018-07-01', temperature: 36.65, bleeding: 1 }, { date: '2018-07-02', temperature: 36.45 }, { date: '2018-07-03', temperature: 36.65 }, @@ -114,34 +114,6 @@ export const longAndComplicatedCycle = [ { date: '2018-06-27', temperature: 36.9, cervix: { opening: 0, firmness: 0 } } ].map(convertToSymptoFormat) -export const tempAndCervixEvalEndOnSameDay = [ - { date: '2018-06-01', bleeding: 2 }, - { date: '2018-06-02', bleeding: 1 }, - { date: '2018-06-03', bleeding: 1 }, - { date: '2018-06-04', bleeding: 2 }, - { date: '2018-06-05', bleeding: 1 }, - { date: '2018-06-06', bleeding: 1 }, - { date: '2018-06-07', cervix: { opening: 2, firmness: 0 } }, - { date: '2018-06-08', temperature: 36.45, cervix: { opening: 0, firmness: 1 } }, - { date: '2018-06-09', temperature: 36.5, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-06-10', temperature: 36.30, cervix: { opening: 0, firmness: 1 } }, - { date: '2018-06-11', temperature: 36.30, cervix: { opening: 1, firmness: 0 } }, - { date: '2018-06-12', temperature: 36.4, cervix: { opening: 2, firmness: 1 } }, - { date: '2018-06-13', temperature: 36.3, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-06-14', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-06-15', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-06-16', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-06-17', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-06-18', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-06-19', temperature: 36.95, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-06-20', temperature: 37.0, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-06-21', temperature: 37.0, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-06-22', temperature: 37.0, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-06-23', cervix: { opening: 0, firmness: 0 } }, - { date: '2018-06-24', cervix: { opening: 0, firmness: 0 }}, - { date: '2018-06-25', cervix: { opening: 1, firmness: 1 } } -].map(convertToSymptoFormat) - export const tempShift3DaysAfterCervixShift = [ { date: '2018-05-08', bleeding: 3 }, { date: '2018-05-09', bleeding: 2 }, @@ -189,7 +161,7 @@ export const cervixShift2DaysAfterTempShift = [ { date: '2018-04-24', temperature: 36.75, cervix: { opening: 0, firmness: 0 } } ].map(convertToSymptoFormat) -export const noInfertilePhaseDetected = [ +export const noOvulationDetected = [ { date: '2018-03-08', bleeding: 3 }, { date: '2018-03-09', bleeding: 3 }, { date: '2018-03-10', bleeding: 3 }, diff --git a/test/sympto/cervix-temp.spec.js b/test/sympto/cervix-temp.spec.js index 6b06ddd..5ccd940 100644 --- a/test/sympto/cervix-temp.spec.js +++ b/test/sympto/cervix-temp.spec.js @@ -1,14 +1,13 @@ import chai from 'chai' import getSensiplanStatus from '../../lib/sympto' import { - idealCycle, + cervixShiftAndFhmOnSameDay, cycleWithFhmNoCervixShift, cycleWithoutFhm, - cycleWithoutAnyShifts, - tempAndCervixEvalEndOnSameDay, + longCycleWithoutAnyShifts, tempShift3DaysAfterCervixShift, cervixShift2DaysAfterTempShift, - noInfertilePhaseDetected, + noOvulationDetected, fiveDayCycle } from './cervix-temp-fixtures' @@ -19,7 +18,7 @@ describe('sympto', () => { describe('with no previous higher temp measurement', () => { it('with no temp or cervix shifts detects only peri-ovulatory', () => { const status = getSensiplanStatus({ - cycle: cycleWithoutAnyShifts, + cycle: longCycleWithoutAnyShifts, previousCycle: cycleWithoutFhm, secondarySymptom: 'cervix' }) @@ -28,7 +27,7 @@ describe('sympto', () => { phases: { periOvulatory: { start: { date: '2018-07-01' }, - cycleDays: cycleWithoutAnyShifts + cycleDays: longCycleWithoutAnyShifts } } }) @@ -51,7 +50,7 @@ describe('sympto', () => { }) it('with temp and cervix shifts detects only peri- and post-ovulatory phases', () => { const status = getSensiplanStatus({ - cycle: idealCycle, + cycle: cervixShiftAndFhmOnSameDay, previousCycle: cycleWithoutFhm, secondarySymptom: 'cervix' }) @@ -62,21 +61,21 @@ describe('sympto', () => { expect(status.phases.periOvulatory).to.eql({ start: { date: '2018-08-01' }, end: { date: '2018-08-15', time: '18:00' }, - cycleDays: idealCycle + cycleDays: cervixShiftAndFhmOnSameDay .filter(({date}) => date <= '2018-08-15') }) expect(status.phases.postOvulatory).to.eql({ start: { date: '2018-08-15', time: '18:00' }, - cycleDays: idealCycle + cycleDays: cervixShiftAndFhmOnSameDay .filter(({date}) => date >= '2018-08-15') }) }) }) describe('with previous higher temp measurement', () => { - it('with no shifts detects only peri-ovulatory in 3-day long cycle according to 5-day rule', () => { + it('with no shifts detects only peri-ovulatory in 5-day long cycle according to 5-day rule', () => { const status = getSensiplanStatus({ cycle: fiveDayCycle, - previousCycle: idealCycle, + previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(1) @@ -88,58 +87,58 @@ describe('sympto', () => { }) it('with no shifts detects pre- and peri-ovulatory phase according to 5-day-rule', () => { const status = getSensiplanStatus({ - cycle: cycleWithoutAnyShifts, - previousCycle: idealCycle, + cycle: longCycleWithoutAnyShifts, + previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(2) expect(status.phases.preOvulatory).to.eql({ - cycleDays: cycleWithoutAnyShifts + cycleDays: longCycleWithoutAnyShifts .filter(({date}) => date <= '2018-07-05'), start: { date: '2018-07-01' }, end: { date: '2018-07-05' } }) expect(status.phases.periOvulatory).to.eql({ - cycleDays: cycleWithoutAnyShifts + cycleDays: longCycleWithoutAnyShifts .filter(({date}) => date >= '2018-07-06'), start: { date: '2018-07-06' } }) }) it('with evaluation of temperature and cervix end on same day', () => { const status = getSensiplanStatus({ - cycle: tempAndCervixEvalEndOnSameDay, - previousCycle: idealCycle, + cycle: cervixShiftAndFhmOnSameDay, + previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) - expect(status.temperatureShift.evaluationCompleteDay.date).to.eql('2018-06-17') - expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-06-17') + expect(status.temperatureShift.evaluationCompleteDay.date).to.eql('2018-08-15') + expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-08-15') expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: tempAndCervixEvalEndOnSameDay - .filter(({date}) => date <= '2018-06-05') + start: { date: '2018-08-01' }, + end: { date: '2018-08-05' }, + cycleDays: cervixShiftAndFhmOnSameDay + .filter(({date}) => date <= '2018-08-05') }) expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-17', time: '18:00' }, - cycleDays: tempAndCervixEvalEndOnSameDay + start: { date: '2018-08-06' }, + end: { date: '2018-08-15', time: '18:00' }, + cycleDays: cervixShiftAndFhmOnSameDay .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-17' + return date > '2018-08-05' && date <= '2018-08-15' }) }) expect(status.phases.postOvulatory).to.eql({ - start: { date: '2018-06-17', time: '18:00' }, - cycleDays: tempAndCervixEvalEndOnSameDay - .filter(({date}) => date >= '2018-06-17') + start: { date: '2018-08-15', time: '18:00' }, + cycleDays: cervixShiftAndFhmOnSameDay + .filter(({date}) => date >= '2018-08-15') }) }) it('when temperature shift happens 3 days after cervix shift', () => { const status = getSensiplanStatus({ cycle: tempShift3DaysAfterCervixShift, - previousCycle: idealCycle, + previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) @@ -171,7 +170,7 @@ describe('sympto', () => { it('when cervix shift happens 2 days after temperature shift', () => { const status = getSensiplanStatus({ cycle: cervixShift2DaysAfterTempShift, - previousCycle: idealCycle, + previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) @@ -201,19 +200,19 @@ describe('sympto', () => { }) it('when no infertile phase can be detected', () => { const status = getSensiplanStatus({ - cycle: noInfertilePhaseDetected, - previousCycle: idealCycle, + cycle: noOvulationDetected, + previousCycle: cervixShiftAndFhmOnSameDay, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(2) expect(status.phases.preOvulatory).to.eql({ - cycleDays: noInfertilePhaseDetected + 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: noInfertilePhaseDetected + cycleDays: noOvulationDetected .filter(({date}) => date > '2018-03-12'), start: { date: '2018-03-13' } }) From 76056e1db022458241796a51054881cad86f3461 Mon Sep 17 00:00:00 2001 From: emelko Date: Thu, 13 Sep 2018 09:54:13 +0200 Subject: [PATCH 27/28] Improving cervix: * adding tempEvalEnd value to cervix tests * more comments in code for cervix sympto * better description in cervix temp tests * take out cervix.value --- lib/sympto/cervix.js | 25 +++-- lib/sympto/index.js | 8 +- test/sympto/cervix-temp-fixtures.js | 8 +- test/sympto/cervix-temp.spec.js | 15 ++- test/sympto/cervix.spec.js | 141 +++++++++++++++++++++------- 5 files changed, 141 insertions(+), 56 deletions(-) diff --git a/lib/sympto/cervix.js b/lib/sympto/cervix.js index 9a59645..2578381 100644 --- a/lib/sympto/cervix.js +++ b/lib/sympto/cervix.js @@ -1,15 +1,26 @@ export default function (cycleDays, tempEvalEndIndex) { - const cervixDays = cycleDays.filter(day => day.cervix && !day.cervix.exclude) + 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 + // * be followed by at least 3 days + // 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 for (let i = 0; i < cervixDays.length; i++) { const day = cervixDays[i] if (isClosedAndHard(day.cervix)) continue - // the three following days must be with closed and hard cervix - // AND no other cervix value may occur until temperature evaluation has - // been completed + + // the three following days must be with closed and hard cervix (indicating an infertile cervix) 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) }) @@ -33,9 +44,9 @@ export default function (cycleDays, tempEvalEndIndex) { } } - return { detected: false } + return notDetected } -function isClosedAndHard (cervix) { - return cervix.value.opening === 0 && cervix.value.firmness === 0 +function isClosedAndHard (cervixDay) { + return cervixDay.opening === 0 && cervixDay.firmness === 0 } diff --git a/lib/sympto/index.js b/lib/sympto/index.js index d73d635..575b608 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -115,10 +115,10 @@ function throwIfArgsAreNotInRequiredFormat(cycles) { if (day.mucus) assert.equal(typeof day.mucus.value, 'number', "Mucus value must be a number.") if (day.mucus) assert.ok(day.mucus.value >= 0, "Mucus value must greater or equal to 0.") if (day.mucus) assert.ok(day.mucus.value <= 4, "Mucus value must be below 5.") - if (day.cervix) assert.ok(day.cervix.value.opening >= 0, "Cervix opening value must be 0 or bigger") - if (day.cervix) assert.ok(day.cervix.value.opening <= 2, "Cervix opening value must be 2 or smaller") - if (day.cervix) assert.ok(day.cervix.value.firmness >= 0, "Cervix firmness value must be 0 or bigger") - if (day.cervix) assert.ok(day.cervix.value.firmness <= 1, "Cervix firmness value must be 1 or smaller") + if (day.cervix) assert.ok(day.cervix.opening >= 0, "Cervix opening value must be 0 or bigger") + if (day.cervix) assert.ok(day.cervix.opening <= 2, "Cervix opening value must be 2 or smaller") + if (day.cervix) assert.ok(day.cervix.firmness >= 0, "Cervix firmness value must be 0 or bigger") + if (day.cervix) assert.ok(day.cervix.firmness <= 1, "Cervix firmness value must be 1 or smaller") assert.equal(typeof cycle[0].bleeding.value, 'number', "Bleeding value must be a number") }) }) diff --git a/test/sympto/cervix-temp-fixtures.js b/test/sympto/cervix-temp-fixtures.js index 0299524..58ff695 100644 --- a/test/sympto/cervix-temp-fixtures.js +++ b/test/sympto/cervix-temp-fixtures.js @@ -4,8 +4,10 @@ function convertToSymptoFormat(val) { value: val.temperature, exclude: false } - if (val.cervix) sympto.cervix = { - value: val.cervix, + + if (val.cervix && typeof val.cervix.opening === 'number' && typeof val.cervix.firmness === 'number') sympto.cervix = { + opening: val.cervix.opening, + firmness: val.cervix.firmness, exclude: false } if (val.bleeding) sympto.bleeding = { @@ -130,7 +132,7 @@ export const tempShift3DaysAfterCervixShift = [ { date: '2018-05-20', temperature: 36.7, cervix: { opening: 0, firmness: 0 } }, { date: '2018-05-21', temperature: 36.6, cervix: { opening: 0, firmness: 0 } }, { date: '2018-05-22', temperature: 36.85, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-05-23', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-23', temperature: 36.8, cervix: { opening: 1, firmness: 0 } }, { date: '2018-05-24', temperature: 36.85, cervix: { opening: 0, firmness: 0 } }, { date: '2018-05-25', temperature: 36.95, cervix: { opening: 0, firmness: 0 } }, { date: '2018-05-26', temperature: 36.85, cervix: { opening: 0, firmness: 1 } }, diff --git a/test/sympto/cervix-temp.spec.js b/test/sympto/cervix-temp.spec.js index 5ccd940..e2d8fa0 100644 --- a/test/sympto/cervix-temp.spec.js +++ b/test/sympto/cervix-temp.spec.js @@ -48,10 +48,9 @@ describe('sympto', () => { } }) }) - it('with temp and cervix shifts detects only peri- and post-ovulatory phases', () => { + it('with temp and cervix shifts at the same day an no previous cycle detects only peri- and post-ovulatory phases', () => { const status = getSensiplanStatus({ cycle: cervixShiftAndFhmOnSameDay, - previousCycle: cycleWithoutFhm, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(2) @@ -72,7 +71,7 @@ describe('sympto', () => { }) }) describe('with previous higher temp measurement', () => { - it('with no shifts detects only peri-ovulatory in 5-day long cycle according to 5-day rule', () => { + it('with no shifts in 5-day long cycle detects only peri-ovulatory according to 5-day rule', () => { const status = getSensiplanStatus({ cycle: fiveDayCycle, previousCycle: cervixShiftAndFhmOnSameDay, @@ -85,7 +84,7 @@ describe('sympto', () => { end: { date: '2018-08-05' } }) }) - it('with no shifts detects pre- and peri-ovulatory phase according to 5-day-rule', () => { + it('with no shifts in long cycle detects pre- and peri-ovulatory phase according to 5-day-rule', () => { const status = getSensiplanStatus({ cycle: longCycleWithoutAnyShifts, previousCycle: cervixShiftAndFhmOnSameDay, @@ -105,7 +104,7 @@ describe('sympto', () => { start: { date: '2018-07-06' } }) }) - it('with evaluation of temperature and cervix end on same day', () => { + it('with temperature and cervix evaluation end on same day detects all 3 phases', () => { const status = getSensiplanStatus({ cycle: cervixShiftAndFhmOnSameDay, previousCycle: cervixShiftAndFhmOnSameDay, @@ -135,7 +134,7 @@ describe('sympto', () => { .filter(({date}) => date >= '2018-08-15') }) }) - it('when temperature shift happens 3 days after cervix shift', () => { + it('with temperature shift 3 days after cervix shift detects all 3 phases', () => { const status = getSensiplanStatus({ cycle: tempShift3DaysAfterCervixShift, previousCycle: cervixShiftAndFhmOnSameDay, @@ -167,7 +166,7 @@ describe('sympto', () => { .filter(({date}) => date >= '2018-05-21') }) }) - it('when cervix shift happens 2 days after temperature shift', () => { + it('with cervix shift 2 days after temperature shift detects all 3 phases', () => { const status = getSensiplanStatus({ cycle: cervixShift2DaysAfterTempShift, previousCycle: cervixShiftAndFhmOnSameDay, @@ -198,7 +197,7 @@ describe('sympto', () => { start: { date: '2018-04-19', time: '18:00' } }) }) - it('when no infertile phase can be detected', () => { + it('with no shifts no ovulation is found detects only pre and peri-ovulatory phase', () => { const status = getSensiplanStatus({ cycle: noOvulationDetected, previousCycle: cervixShiftAndFhmOnSameDay, diff --git a/test/sympto/cervix.spec.js b/test/sympto/cervix.spec.js index f935945..f8bbc3e 100644 --- a/test/sympto/cervix.spec.js +++ b/test/sympto/cervix.spec.js @@ -5,87 +5,160 @@ const expect = chai.expect function turnIntoCycleDayObject(value, fakeDate) { const hardAndClosed = { - value: { opening: 0, firmness: 0 } + opening: 0, + firmness: 0 } const hardAndOpen = { - value: { opening: 1, firmness: 0 } + opening: 1, + firmness: 0 } const softAndClosed = { - value: { opening: 0, firmness: 1 } + opening: 0, + firmness: 1 } const softAndOpen = { - value: { opening: 1, firmness: 1 } + opening: 1, + firmness: 1 } const cervixStates = [hardAndClosed, hardAndOpen, softAndClosed, softAndOpen] return { date: fakeDate, - cervix: cervixStates[value], - exclude: false + cervix: { + opening: cervixStates[value].opening, + firmness: cervixStates[value].firmness, + exclude: false + } } } describe('sympto', () => { describe('detects cervix shift', () => { - it('when shift happens at day 15 with consistent following days', function () { - const values = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 3, 1, 3, 1, 0, 0, 0, 0] + it('when shift happens at day 13 with consistent following days of infertile cervix until tempEvalEnd', () => { + const values = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 3, 0, 0, 0, 0, 0, 0, 0] .map(turnIntoCycleDayObject) - const status = getCervixStatus(values) + const status = getCervixStatus(values, 16) expect(status).to.eql({ detected: true, cervixPeakBeforeShift: { - date: 13, - cervix: {value: { opening: 1, firmness: 0 }}, - exclude: false + date: 10, + cervix: { + opening: 1, + firmness: 1, + exclude: false + } }, evaluationCompleteDay: { - date: 16, - cervix: { value: { opening: 0, firmness: 0 }}, - exclude: false + date: 13, + cervix: { + opening: 0, + firmness: 0, + exclude: false + } } }) }) - it('at the very first day of cycle days even if later shift happens again', function () { + it('right at the start of cycle days even if later shift happens again because tempEvalEnd happened before second potential shift', () => { const values = [2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] .map(turnIntoCycleDayObject) - const status = getCervixStatus(values) + const status = getCervixStatus(values, 5) expect(status).to.eql({ detected: true, cervixPeakBeforeShift: { date: 0, - cervix: { value: { opening: 0, firmness: 1 } }, - exclude: false + cervix: { + opening: 0, + firmness: 1, + exclude: false + }, }, evaluationCompleteDay: { date: 3, - cervix: { value: { opening: 0, firmness: 0 } }, - exclude: false + cervix: { + opening: 0, + firmness: 0, + exclude: false + } + } + }) + }) + it('at day 6 although right at the start of cycle days a potential shift happened but because tempEvalEnd happens after second shift', () => { + const values = [2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + .map(turnIntoCycleDayObject) + const status = getCervixStatus(values, 10) + expect(status).to.eql({ + detected: true, + cervixPeakBeforeShift: { + date: 6, + cervix: { + opening: 1, + firmness: 0, + exclude: false + }, + }, + evaluationCompleteDay: { + date: 9, + cervix: { + opening: 0, + firmness: 0, + exclude: 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: 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', () => { - it('if there are less than 3 days closed and hard cervix', function () { - const values = [0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 3, 1, 1, 1, 0, 0, 2, 0] + it('if there are less than 3 days closed and hard cervix', () => { + const values = [0, 0, 0, 1, 1, 1, 2, 0, 3, 3, 3, 1, 1, 1, 0, 0, 2, 0] .map(turnIntoCycleDayObject) - const status = getCervixStatus(values) + const status = getCervixStatus(values, 15) expect(status).to.eql({ detected: false }) }) - it('if there are no cervix values', function () { - const values = [].map(turnIntoCycleDayObject) - const status = getCervixStatus(values) - expect(status).to.eql({ detected: false }) - }) - it('when the cervix values are all the same', function () { - const values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + it('if cycleDays have not enough cervix values to detect valid cervix shift', () => { + const values = [2,0,0] .map(turnIntoCycleDayObject) - const status = getCervixStatus(values) + const status = getCervixStatus(values, 17) expect(status).to.eql({ detected: false }) }) - it('if no days of hard and closed cervix are tracked', function () { + 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) - const status = getCervixStatus(values) + const status = getCervixStatus(values, 12) + expect(status).to.eql({ detected: false }) + }) + it('if all days indicate infertile cervix values', () => { + const values = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] + .map(turnIntoCycleDayObject) + const status = getCervixStatus(values, 9) + expect(status).to.eql({ detected: false }) + }) + it('if there are no cervix values', () => { + const values = [].map(turnIntoCycleDayObject) + const status = getCervixStatus(values, 15) expect(status).to.eql({ detected: false }) }) }) From 14989d81d5dbe1e46ab657641d4ca9a8100ef04e Mon Sep 17 00:00:00 2001 From: emelko Date: Thu, 13 Sep 2018 10:49:42 +0200 Subject: [PATCH 28/28] Add better test as dummy cervix data --- db/fixtures.js | 92 +++++++++++++++++++++++++++++++++++++------------- db/index.js | 12 ++++--- 2 files changed, 77 insertions(+), 27 deletions(-) diff --git a/db/fixtures.js b/db/fixtures.js index 321c6df..fd4a949 100644 --- a/db/fixtures.js +++ b/db/fixtures.js @@ -29,28 +29,7 @@ export const cycleWithFhmMucus = [ { date: '2018-07-18', temperature: 36.9, mucus: 2 } ].map(convertToSymptoFormat).reverse() -export const cycleWithFhmCervix = [ - { date: '2018-08-01', bleeding: 2 }, - { date: '2018-08-02', bleeding: 1 }, - { date: '2018-08-03', bleeding: 0 }, - { date: '2018-08-04', bleeding: 0 }, - { date: '2018-08-05', temperature: 36.07 }, - { date: '2018-08-06', temperature: 36.2 }, - { date: '2018-08-07', temperature: 36.35 }, - { date: '2018-08-08', temperature: 36.4 }, - { date: '2018-08-09', temperature: 36.3 }, - { date: '2018-08-10', temperature: 36.45 }, - { date: '2018-08-11', temperature: 36.45 }, - { date: '2018-08-12', temperature: 36.7, cervix: { isClosed: false, isHard: false } }, - { date: '2018-08-13', temperature: 36.8, cervix: { isClosed: true, isHard: true } }, - { date: '2018-08-14', temperature: 36.75, cervix: { isClosed: true, isHard: true } }, - { date: '2018-08-15', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, - { date: '2018-08-16', temperature: 36.95, cervix: { isClosed: true, isHard: true } }, - { date: '2018-08-17', temperature: 36.9, cervix: { isClosed: true, isHard: true } }, - { date: '2018-08-18', temperature: 36.9, cervix: { isClosed: false, isHard: true } } -].map(convertToSymptoFormat).reverse() - -export const longAndComplicatedCycle = [ +export const longAndComplicatedCycleWithMucus = [ { date: '2018-06-01', temperature: 36.6, bleeding: 2 }, { date: '2018-06-02', temperature: 36.65 }, { date: '2018-06-04', temperature: 36.6 }, @@ -94,4 +73,71 @@ export const cycleWithTempAndNoMucusShift = [ { date: '2018-05-24', temperature: 36.85, mucus: 4 }, { date: '2018-05-26', temperature: 36.8, mucus: 4 }, { date: '2018-05-27', temperature: 36.9, mucus: 4 } -].map(convertToSymptoFormat).reverse() \ No newline at end of file +].map(convertToSymptoFormat).reverse() + +export const cycleWithFhmCervix = [ + { date: '2018-08-01', bleeding: 2 }, + { date: '2018-08-02', bleeding: 1 }, + { date: '2018-08-03', bleeding: 0 }, + { date: '2018-08-04', bleeding: 0 }, + { date: '2018-08-05', temperature: 36.07 }, + { date: '2018-08-06', temperature: 36.2 }, + { date: '2018-08-07', temperature: 36.35 }, + { date: '2018-08-08', temperature: 36.4 }, + { date: '2018-08-09', temperature: 36.3 }, + { date: '2018-08-10', temperature: 36.45 }, + { date: '2018-08-11', temperature: 36.45 }, + { date: '2018-08-12', temperature: 36.7, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-08-13', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-08-14', temperature: 36.75, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-08-15', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-08-16', temperature: 36.95, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-08-17', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-08-18', temperature: 36.9, cervix: { opening: 1, firmness: 0 } } +].map(convertToSymptoFormat).reverse() + +export const longAndComplicatedCycleWithCervix = [ + { 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, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-06-09', temperature: 36.5, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-06-10', temperature: 36.4, cervix: { opening: 1, 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: 0, firmness: 0 } }, + { date: '2018-06-16', temperature: 36.7, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-17', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-06-18', temperature: 36.75, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-19', temperature: 36.8, cervix: { opening: 1, firmness: 0 } }, + { date: '2018-06-20', temperature: 36.85, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-21', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-22', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-06-25', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, + { 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).reverse() + +export const cycleWithTempAndNoCervixShift = [ + { date: '2018-07-01', temperature: 36.6, bleeding: 2 }, + { date: '2018-07-02', temperature: 36.65 }, + { date: '2018-07-05', temperature: 36.55 }, + { date: '2018-07-06', temperature: 36.7, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-07-08', temperature: 36.45, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-07-09', temperature: 36.5, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-10', temperature: 36.4, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-07-11', temperature: 36.5, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-07-13', temperature: 36.45, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-07-14', temperature: 36.5, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-15', temperature: 36.55, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-16', temperature: 36.7, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-07-17', temperature: 36.65, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-07-18', temperature: 36.75, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-19', temperature: 36.8, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-20', temperature: 36.85, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-23', temperature: 36.9, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-07-24', temperature: 36.85, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-26', temperature: 36.8, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-27', temperature: 36.9, cervix: { opening: 1, firmness: 1 } } +].map(convertToSymptoFormat).reverse() diff --git a/db/index.js b/db/index.js index 433d000..1b79d7b 100644 --- a/db/index.js +++ b/db/index.js @@ -1,10 +1,12 @@ import Realm from 'realm' import { LocalDate, ChronoUnit } from 'js-joda' import { - cycleWithTempAndNoMucusShift, cycleWithFhmMucus, + longAndComplicatedCycleWithMucus, + cycleWithTempAndNoMucusShift, cycleWithFhmCervix, - longAndComplicatedCycle + longAndComplicatedCycleWithCervix, + cycleWithTempAndNoCervixShift } from './fixtures' const TemperatureSchema = { @@ -183,7 +185,7 @@ function getCycleDay(localDate) { function fillWithMucusDummyData() { const dummyCycles = [ cycleWithFhmMucus, - longAndComplicatedCycle, + longAndComplicatedCycleWithMucus, cycleWithTempAndNoMucusShift ] @@ -207,7 +209,9 @@ function fillWithMucusDummyData() { function fillWithCervixDummyData() { const dummyCycles = [ - cycleWithFhmCervix + cycleWithFhmCervix, + longAndComplicatedCycleWithCervix, + cycleWithTempAndNoCervixShift ] db.write(() => {