Merge branch 'master'

This commit is contained in:
emelko
2018-08-31 00:36:19 +02:00
parent 5296a9c6ee
commit 3ff7dd7340
14 changed files with 1359 additions and 706 deletions
+215
View File
@@ -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)
+199
View File
@@ -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: {
}
})
})
})
})
+114
View File
@@ -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 })
})
})
})
-660
View File
@@ -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)
})
})
})
@@ -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)
+661
View File
@@ -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)
})
})
})
})