dirty-chai

This commit is contained in:
Julia Friesel
2019-02-02 18:34:12 +01:00
parent 46aa596c7a
commit efca6f0d47
16 changed files with 36 additions and 2877 deletions
+19 -3
View File
@@ -1,4 +1,4 @@
import getFertilityStatus from './sympto'
import getFertilityStatus from 'sympto'
import cycleModule from './cycle'
import { useCervixObservable } from '../local-storage'
import { fertilityStatus as labels } from '../i18n/en/labels'
@@ -99,7 +99,23 @@ function formatStatus(phaseNameForDay, dateString, status) {
}
function formatCycleForSympto(cycle) {
const formatted = cycle.reduce((acc, oldDay) => {
// deep clone
const day = JSON.parse(JSON.stringify(oldDay));
// remove excluded symptoms
['bleeding', 'temperature', 'mucus', 'cervix'].forEach(symptomName => {
if (day[symptomName] && day[symptomName].exclude) {
delete day[symptomName]
}
});
// change format
['bleeding', 'temperature', 'mucus'].forEach(symptomName => {
if (day[symptomName]) day[symptomName] = day[symptomName].value
})
acc.push(day)
return acc
}, [])
// we get earliest last, but sympto wants earliest first
cycle.reverse()
return cycle
formatted.reverse()
return formatted
}
-58
View File
@@ -1,58 +0,0 @@
export default function (cycleDays, tempEvalEndIndex) {
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
// * must happen prior to end of temperature evaluation
// 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 (indicating an infertile cervix)
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)
// if temperature evaluation has been completed an we still haven't found
// a candidate, there is no cervix shift
if (cycleDayIndex > tempEvalEndIndex) return notDetected
// no other fertile cervix value may occur until temperature evaluation has
// been completed
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,
cervixPeakBeforeShift: day,
evaluationCompleteDay: threeFollowingDays[threeFollowingDays.length - 1]
}
}
}
return notDetected
}
function isClosedAndHard (cervixDay) {
return cervixDay.opening === 0 && cervixDay.firmness === 0
}
-127
View File
@@ -1,127 +0,0 @@
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(cycleInfo) {
const { cycle, previousCycle, earlierCycles = [], secondarySymptom = 'mucus' } = cycleInfo
throwIfArgsAreNotInRequiredFormat([cycle, ...earlierCycles])
const status = {
phases: {}
}
// 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,
secondarySymptom: secondarySymptom
})
if (statusForLast.temperatureShift) {
const preOvuPhase = getPreOvulatoryPhase(
cycle,
[previousCycle, ...earlierCycles],
secondarySymptom
)
if (preOvuPhase) {
status.phases.preOvulatory = preOvuPhase
if (status.phases.preOvulatory.cycleDays.length === cycle.length) {
return status
}
}
}
}
// TODO maybe add indicator if there was no preovuphase?
status.phases.periOvulatory = {
start: { date: null },
cycleDays: []
}
const periPhase = status.phases.periOvulatory
if (status.phases.preOvulatory) {
const prePhase = status.phases.preOvulatory
const startDate = LocalDate.parse(prePhase.end.date).plusDays(1).toString()
periPhase.start.date = startDate
const lastPreDay = prePhase.cycleDays[prePhase.cycleDays.length - 1]
periPhase.cycleDays = cycle.slice(cycle.indexOf(lastPreDay) + 1)
} else {
periPhase.start.date = cycle[0].date
periPhase.cycleDays = [...cycle]
}
const temperatureShift = getTemperatureShift(cycle)
if (!temperatureShift.detected) return status
const tempEvalEndIndex = cycle.indexOf(temperatureShift.evaluationCompleteDay)
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 secondarySymptomOver = secondaryShift.evaluationCompleteDay.date
if (tempOver >= secondarySymptomOver) {
periOvulatoryEnd = temperatureShift.evaluationCompleteDay
} else if (secondarySymptom > tempOver) {
periOvulatoryEnd = secondaryShift.evaluationCompleteDay
}
const previousPeriDays = periPhase.cycleDays
const previousPeriEndIndex = previousPeriDays.indexOf(periOvulatoryEnd)
status.phases.postOvulatory = {
start: {
date: periOvulatoryEnd.date,
time: '18:00'
},
cycleDays: previousPeriDays.slice(previousPeriEndIndex)
}
periPhase.cycleDays = previousPeriDays.slice(0, previousPeriEndIndex + 1)
periPhase.end = status.phases.postOvulatory.start
if (secondarySymptom === 'mucus') {
status.mucusShift = secondaryShift
} else if (secondarySymptom === 'cervix') {
status.cervixShift = secondaryShift
}
status.temperatureShift = temperatureShift
return status
}
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.")
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 must be a number.")
cycle.forEach(day => {
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.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")
})
})
}
-26
View File
@@ -1,26 +0,0 @@
import { LocalDate } from 'js-joda'
import getNfpStatus from './index'
export default function (previousCycles, secondarySymptom) {
const fhms = previousCycles
.map(cycle => {
const status = getNfpStatus({ cycle, secondarySymptom })
if (status.temperatureShift) {
const day = status.temperatureShift.firstHighMeasurementDay
const firstCycleDayDate = LocalDate.parse(cycle[0].date)
const fhmDate = LocalDate.parse(day.date)
return fhmDate.compareTo(firstCycleDayDate) + 1
}
return null
})
.filter(val => typeof val === 'number')
const preOvuLength = Math.min(...fhms) - 8
// pre ovu length may only be lengthened if we have more than 12 previous fhms
// if pre ovu length is less than 5, it shortened even with fewer prev fhms
if (preOvuLength < 5) return preOvuLength
if (fhms.length >= 12) return preOvuLength
return null
}
-54
View File
@@ -1,54 +0,0 @@
export default function (cycleDays, tempEvalEndIndex) {
const notDetected = { detected: false}
const mucusDays = cycleDays.filter(day => day.mucus && !day.mucus.exclude)
let currentBestQuality = 0
for (let i = 0; i < mucusDays.length; i++) {
const day = mucusDays[i]
if (day.mucus.value > currentBestQuality) {
currentBestQuality = day.mucus.value
}
// if mucus only changes from dry to nothing, it doesn't constitute a shift
if (currentBestQuality < 2) continue
if (day.mucus.value !== currentBestQuality) continue
// the three following days must be of lower quality
const threeFollowingDays = mucusDays.slice(i + 1, i + 4)
if (threeFollowingDays.length < 3) continue
const bestQualityOccursIn3FollowingDays = threeFollowingDays.some(day => {
return day.mucus.value >= currentBestQuality
})
if (bestQualityOccursIn3FollowingDays) continue
const cycleDayIndex = cycleDays.indexOf(day)
// if temperature evaluation has been completed an we still haven't found
// a candidate, there is no mucus shift
if (cycleDayIndex > tempEvalEndIndex) return notDetected
// no best quality day may occur until temperature evaluation has
// been completed
const relevantDays = cycleDays
.slice(cycleDayIndex + 1, tempEvalEndIndex + 1)
.filter(day => day.mucus && !day.mucus.exclude)
const noBestQualityUntilEndOfTempEval = relevantDays.every(day => {
return day.mucus.value < currentBestQuality
})
if (noBestQualityUntilEndOfTempEval) {
return {
detected: true,
mucusPeak: day,
evaluationCompleteDay: threeFollowingDays[threeFollowingDays.length - 1]
}
}
}
return notDetected
}
-51
View File
@@ -1,51 +0,0 @@
import { LocalDate } from "js-joda"
import apply8DayRule from './minus-8-day-rule'
export default function(cycle, previousCycles, secondarySymptom) {
let preOvuPhaseLength = 5
const minus8DayRuleResult = apply8DayRule(previousCycles, secondarySymptom)
if (minus8DayRuleResult) preOvuPhaseLength = minus8DayRuleResult
const startDate = LocalDate.parse(cycle[0].date)
const preOvuEndDate = startDate.plusDays(preOvuPhaseLength - 1).toString()
const maybePreOvuDays = cycle.slice(0, preOvuPhaseLength).filter(d => {
return d.date <= preOvuEndDate
})
const preOvulatoryDays = getDaysUntilFertileSecondarySymptom(maybePreOvuDays, secondarySymptom)
// if fertile mucus or cervix occurs on the 1st cycle day, there is no pre-ovu phase
if (!preOvulatoryDays.length) return null
let endDate
if (preOvulatoryDays.length === maybePreOvuDays.length) {
endDate = preOvuEndDate
} else {
endDate = preOvulatoryDays[preOvulatoryDays.length - 1].date
}
return {
cycleDays: preOvulatoryDays,
start: {
date: preOvulatoryDays[0].date
},
end: {
date: endDate
}
}
}
function getDaysUntilFertileSecondarySymptom(days, secondarySymptom = 'mucus') {
const firstFertileSecondarySymptomDayIndex = days.findIndex(day => {
if (secondarySymptom === 'mucus') {
return day.mucus && day.mucus.value > 1
} else if (secondarySymptom === 'cervix') {
return day.cervix && day.cervix.opening > 0
|| day.cervix && day.cervix.firmness > 0
}
})
if (firstFertileSecondarySymptomDayIndex > -1) {
return days.slice(0, firstFertileSecondarySymptomDayIndex)
}
return days
}
-122
View File
@@ -1,122 +0,0 @@
export default function (cycleDays) {
const temperatureDays = cycleDays
.filter(day => day.temperature && !day.temperature.exclude)
.map(day => {
return {
originalCycleDay: day,
temp: rounded(day.temperature.value, 0.05)
}
})
function getLtl(i) {
const daysBefore = temperatureDays.slice(0, i).slice(-6)
const temps = daysBefore.map(day => day.temp)
return Math.max(...temps)
}
for (let i = 0; i < temperatureDays.length; i++) {
// need at least 6 low temps before we can detect a first high measurement
if (i < 6) continue
// is the temp a candidate for a first high measurement?
const ltl = getLtl(i)
const temp = temperatureDays[i].temp
if (temp <= ltl) continue
const shift = checkIfFirstHighMeasurement(temp, i, temperatureDays, ltl)
if (shift.detected) {
shift.firstHighMeasurementDay = temperatureDays[i].originalCycleDay
return shift
}
}
return { detected: false }
}
function checkIfFirstHighMeasurement(temp, i, temperatureDays, ltl) {
// need at least 3 high temps to form a high temperature level
if (i > temperatureDays.length - 3) {
return { detected: false }
}
const nextDaysAfterPotentialFhm = temperatureDays.slice(i + 1, i + 4)
return (
getResultForRegularRule(nextDaysAfterPotentialFhm.slice(0, 2), ltl)) ||
getResultForFirstExceptionRule(nextDaysAfterPotentialFhm, ltl) ||
getResultForSecondExceptionRule(nextDaysAfterPotentialFhm, ltl) ||
{ detected: false }
}
function getResultForRegularRule(nextDaysAfterPotentialFhm, ltl) {
if (!nextDaysAfterPotentialFhm.every(day => day.temp > ltl)) return false
const thirdDay = nextDaysAfterPotentialFhm[1]
if (isLessThan0Point2(thirdDay.temp - ltl)) return false
return {
detected: true,
rule: 0,
ltl,
evaluationCompleteDay: thirdDay.originalCycleDay
}
}
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,
rule: 1,
ltl,
evaluationCompleteDay: fourthDay.originalCycleDay
}
}
function getResultForSecondExceptionRule(nextDaysAfterPotentialFhm, ltl) {
if (nextDaysAfterPotentialFhm.length < 3) return false
if (secondOrThirdTempIsAtOrBelowLtl(nextDaysAfterPotentialFhm, ltl)) {
const fourthDay = nextDaysAfterPotentialFhm[2]
if (isBiggerOrEqual0Point2(fourthDay.temp - ltl)) {
return {
detected: true,
rule: 2,
ltl,
evaluationCompleteDay: fourthDay.originalCycleDay
}
}
}
return false
}
function secondOrThirdTempIsAtOrBelowLtl(nextDaysAfterPotentialFhm, ltl) {
const secondIsLow = nextDaysAfterPotentialFhm[0].temp <= ltl
const thirdIsLow = nextDaysAfterPotentialFhm[1].temp <= ltl
if ((secondIsLow || thirdIsLow) && !(secondIsLow && thirdIsLow)) {
return true
} else {
return false
}
}
function rounded(val, step) {
const inverted = 1 / step
// we round the difference because of JS decimal weirdness
return Math.round(val * inverted) / inverted
}
// since we're dealing with floats, there is some imprecision in comparisons,
// so we add an error margin that is definitely much smaller than any possible
// actual difference between values
// see https://floating-point-gui.de/errors/comparison/ for background
const errorMargin = 0.0001
function isLessThan0Point2(val) {
return val < (0.2 - errorMargin)
}
function isBiggerOrEqual0Point2(val) {
return val >= (0.2 - errorMargin)
}
+15
View File
@@ -8853,6 +8853,21 @@
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc="
},
"sympto": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/sympto/-/sympto-1.0.0.tgz",
"integrity": "sha512-kPvjaQLOUZ8mXK49Q5CqEEBPO6e22Nl9n1EgWUVlw1e6HSrkkgLfpNL3x23Ti6gx3kWquifP9T2o6lDB5almhQ==",
"requires": {
"js-joda": "^1.9.2"
},
"dependencies": {
"js-joda": {
"version": "1.9.2",
"resolved": "https://registry.npmjs.org/js-joda/-/js-joda-1.9.2.tgz",
"integrity": "sha512-gW45RnlxvxG3VRumOFlYr/dB3gIsE3fuC9uxTCxfVnPTTUh/NaXo09GT74g4HY34zM7omksxSSJFd7oXimKrEA=="
}
}
},
"sync-request": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/sync-request/-/sync-request-3.0.1.tgz",
+2 -1
View File
@@ -40,7 +40,8 @@
"react-native-restart": "0.0.7",
"react-native-share": "^1.1.3",
"react-native-vector-icons": "^5.0.0",
"realm": "^2.22.0"
"realm": "^2.22.0",
"sympto": "^1.0.0"
},
"devDependencies": {
"babel-eslint": "^10.0.1",
-314
View File
@@ -1,314 +0,0 @@
function convertToSymptoFormat(val) {
const sympto = { date: val.date }
if (val.temperature) sympto.temperature = {
value: val.temperature,
time: '08:00',
exclude: false
}
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 = {
value: val.bleeding,
exclude: false
}
return sympto
}
export const cervixShiftAndFhmOnSameDay = [
{ 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, cervix: { opening: 0, firmness: 0 } },
{ 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-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 } },
{ 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 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: { 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 longCycleWithoutAnyShifts = [
{ 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 } },
{ 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.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 } },
{ 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 = [
{ 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: 0, firmness: 0 } },
{ date: '2018-06-07', temperature: 36.5, cervix: { opening: 0, firmness: 0 } },
{ date: '2018-06-08', temperature: 36.52, cervix: { opening: 0, firmness: 0 } },
{ date: '2018-06-09', temperature: 36.5, cervix: { opening: 2, firmness: 1 } },
{ date: '2018-06-10', temperature: 36.7, 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.5, cervix: { opening: 2, firmness: 1 } },
{ date: '2018-06-17', temperature: 36.5, cervix: { opening: 2, firmness: 1 } },
{ date: '2018-06-18', temperature: 36.5, 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: 0, firmness: 0 } },
{ date: '2018-06-21', temperature: 36.8, cervix: { opening: 1, firmness: 1 } },
{ 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: 0, firmness: 0 } },
{ date: '2018-06-27', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }
].map(convertToSymptoFormat)
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 },
{ 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.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 } },
{ date: '2018-05-22', temperature: 36.85, 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 } },
{ 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)
export const cervixShift3DaysAfterTempShift = [
{ 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 },
{ 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', temperature: 36.8, cervix: { opening: 1, 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-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: 0, firmness: 0 } }
].map(convertToSymptoFormat)
export const cervixShift4DaysAfterTempShift = [
{ 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 },
{ 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', temperature: 36.8, cervix: { opening: 1, firmness: 0 } },
{ date: '2018-04-18', temperature: 36.8, cervix: { opening: 0, firmness: 1 } },
{ 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-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: 0, firmness: 0 } }
].map(convertToSymptoFormat)
export const noOvulationDetected = [
{ 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: { 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 } },
{ 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 = [
{ date: '2018-08-01', bleeding: 2 },
{ date: '2018-08-03', bleeding: 3 }
].map(convertToSymptoFormat)
export const fhmOnDay12 = [
{ 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: 0, firmness: 0 } },
{ 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-12', temperature: 36.8, cervix: { opening: 1, firmness: 1 } },
{ date: '2018-06-14', temperature: 36.9, 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 } }
].map(convertToSymptoFormat)
export const fhmOnDay15 = [
{ 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: 0, firmness: 0 } },
{ 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-11', temperature: 36.4, cervix: { opening: 1, firmness: 1 } },
{ date: '2018-06-12', temperature: 36.4, 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: 1, firmness: 1 } },
{ date: '2018-06-16', temperature: 36.9, 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 } }
].map(convertToSymptoFormat)
export const cycleWithEarlyCervix = [
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.65, cervix: { opening: 1, firmness: 1 } },
{ date: '2018-06-05', temperature: 36.55 },
{ date: '2018-06-06', temperature: 36.7, cervix: { opening: 0, firmness: 0 } },
{ date: '2018-06-08', temperature: 36.45, cervix: { opening: 0, firmness: 0 } },
{ date: '2018-06-09', temperature: 36.5, cervix: { opening: 1, firmness: 1 } },
{ date: '2018-06-10', temperature: 36.4, cervix: { opening: 2, firmness: 0 } },
{ date: '2018-06-11', temperature: 36.5, cervix: { opening: 2, firmness: 1 } },
{ date: '2018-06-13', temperature: 36.45, cervix: { opening: 2, 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: 1, firmness: 0 } },
{ date: '2018-06-17', temperature: 36.65, cervix: { opening: 0, firmness: 1 } },
{ date: '2018-06-18', temperature: 36.75, cervix: { opening: 0, firmness: 0 } },
{ date: '2018-06-19', temperature: 36.8, cervix: { opening: 0, firmness: 0 } },
{ date: '2018-06-20', temperature: 36.85, cervix: { opening: 0, firmness: 0 } },
{ date: '2018-06-23', temperature: 36.9, cervix: { opening: 0, firmness: 1 } },
{ date: '2018-06-24', temperature: 36.85, cervix: { opening: 1, firmness: 1 } },
{ 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)
export const cycleWithCervixOnFirstDay = [
{ date: '2018-06-01', temperature: 36.6, bleeding: 2, cervix: { opening: 1, firmness: 1 } },
{ date: '2018-06-02', temperature: 36.65 },
{ date: '2018-06-05', temperature: 36.55 },
{ date: '2018-06-06', temperature: 36.7, cervix: { opening: 0, firmness: 0 } },
{ date: '2018-06-08', temperature: 36.45, cervix: { opening: 0, firmness: 0 } },
{ date: '2018-06-09', temperature: 36.5, cervix: { opening: 1, firmness: 1 } },
{ date: '2018-06-10', temperature: 36.4, cervix: { opening: 2, firmness: 0 } },
{ date: '2018-06-11', temperature: 36.5, cervix: { opening: 2, firmness: 1 } },
{ date: '2018-06-13', temperature: 36.45, cervix: { opening: 2, 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: 1, firmness: 0 } },
{ date: '2018-06-17', temperature: 36.65, cervix: { opening: 0, firmness: 1 } },
{ date: '2018-06-18', temperature: 36.75, cervix: { opening: 0, firmness: 0 } },
{ date: '2018-06-19', temperature: 36.8, cervix: { opening: 0, firmness: 0 } },
{ date: '2018-06-20', temperature: 36.85, cervix: { opening: 0, firmness: 0 } },
{ date: '2018-06-23', temperature: 36.9, cervix: { opening: 0, firmness: 1 } },
{ date: '2018-06-24', temperature: 36.85, cervix: { opening: 1, firmness: 1 } },
{ 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)
export const fertileCervixOnlyAfterEndOfTempEval = [
{ 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-09', temperature: 36.5 },
{ date: '2018-06-10', temperature: 36.4 },
{ date: '2018-06-13', temperature: 36.45 },
{ date: '2018-06-14', temperature: 36.5 },
{ date: '2018-06-15', temperature: 36.55 },
{ date: '2018-06-16', temperature: 36.7 },
{ date: '2018-06-17', temperature: 36.65 },
{ date: '2018-06-18', temperature: 36.60 },
{ date: '2018-06-19', temperature: 36.8 },
{ date: '2018-06-20', temperature: 36.85 },
{ date: '2018-06-21', temperature: 36.8 },
{ date: '2018-06-22', temperature: 36.9 },
{ date: '2018-06-25', temperature: 36.9, cervix: { opening: 1, firmness: 1 }},
{ date: '2018-06-26', temperature: 36.8, cervix: { opening: 0, firmness: 0 }},
{ date: '2018-06-30', temperature: 36.9, cervix: { opening: 0, firmness: 0 }},
{ date: '2018-07-01', temperature: 36.9, cervix: { opening: 0, firmness: 0 }},
{ date: '2018-07-02', temperature: 36.9, cervix: { opening: 0, firmness: 0 }}
].map(convertToSymptoFormat)
-558
View File
@@ -1,558 +0,0 @@
import chai from 'chai'
import getSensiplanStatus from '../../lib/sympto'
import { AssertionError } from 'assert'
import {
cervixShiftAndFhmOnSameDay,
cycleWithFhmNoCervixShift,
cycleWithoutFhmNoCervixShift,
longCycleWithoutAnyShifts,
longAndComplicatedCycle,
tempShift3DaysAfterCervixShift,
cervixShift3DaysAfterTempShift,
cervixShift4DaysAfterTempShift,
noOvulationDetected,
fiveDayCycle,
fhmOnDay12,
fhmOnDay15,
cycleWithEarlyCervix,
cycleWithCervixOnFirstDay,
fertileCervixOnlyAfterEndOfTempEval
} 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', () => {
const status = getSensiplanStatus({
cycle: longCycleWithoutAnyShifts,
previousCycle: cycleWithoutFhmNoCervixShift,
secondarySymptom: 'cervix'
})
expect(Object.keys(status.phases).length).to.eql(1)
expect(status).to.eql({
phases: {
periOvulatory: {
start: { date: '2018-07-01' },
cycleDays: longCycleWithoutAnyShifts
}
}
})
})
it('with temp but no cervix shift detects only peri-ovulatory', () => {
const status = getSensiplanStatus({
cycle: cycleWithFhmNoCervixShift,
previousCycle: cycleWithoutFhmNoCervixShift,
secondarySymptom: 'cervix'
})
expect(Object.keys(status.phases).length).to.eql(1)
expect(status).to.eql({
phases: {
periOvulatory: {
start: { date: '2018-08-01' },
cycleDays: cycleWithFhmNoCervixShift
}
}
})
})
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,
secondarySymptom: 'cervix'
})
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-15', time: '18:00' },
cycleDays: cervixShiftAndFhmOnSameDay
.filter(({date}) => date <= '2018-08-15')
})
expect(status.phases.postOvulatory).to.eql({
start: { date: '2018-08-15', time: '18:00' },
cycleDays: cervixShiftAndFhmOnSameDay
.filter(({date}) => date >= '2018-08-15')
})
})
})
describe('with previous higher temp measurement', () => {
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,
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 in long cycle detects pre- and peri-ovulatory phase according to 5-day-rule', () => {
const status = getSensiplanStatus({
cycle: longCycleWithoutAnyShifts,
previousCycle: cervixShiftAndFhmOnSameDay,
secondarySymptom: 'cervix'
})
expect(Object.keys(status.phases).length).to.eql(2)
expect(status.phases.preOvulatory).to.eql({
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: longCycleWithoutAnyShifts
.filter(({date}) => date >= '2018-07-06'),
start: { date: '2018-07-06' }
})
})
it('with temperature and cervix evaluation end on same day detects all 3 phases', () => {
const status = getSensiplanStatus({
cycle: cervixShiftAndFhmOnSameDay,
previousCycle: cervixShiftAndFhmOnSameDay,
secondarySymptom: 'cervix'
})
expect(Object.keys(status.phases).length).to.eql(3)
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-08-01' },
end: { date: '2018-08-05' },
cycleDays: cervixShiftAndFhmOnSameDay
.filter(({date}) => date <= '2018-08-05')
})
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-08-06' },
end: { date: '2018-08-15', time: '18:00' },
cycleDays: cervixShiftAndFhmOnSameDay
.filter(({date}) => {
return date > '2018-08-05' && date <= '2018-08-15'
})
})
expect(status.phases.postOvulatory).to.eql({
start: { date: '2018-08-15', time: '18:00' },
cycleDays: cervixShiftAndFhmOnSameDay
.filter(({date}) => date >= '2018-08-15')
})
})
it('with temperature shift 3 days after cervix shift detects all 3 phases', () => {
const status = getSensiplanStatus({
cycle: tempShift3DaysAfterCervixShift,
previousCycle: cervixShiftAndFhmOnSameDay,
secondarySymptom: 'cervix'
})
expect(Object.keys(status.phases).length).to.eql(3)
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')
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('with cervix shift 3 days after temperature shift detects all 3 phases', () => {
const status = getSensiplanStatus({
cycle: cervixShift3DaysAfterTempShift,
previousCycle: cervixShiftAndFhmOnSameDay,
secondarySymptom: 'cervix'
})
expect(Object.keys(status.phases).length).to.eql(3)
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-20')
expect(status.phases.preOvulatory).to.eql({
cycleDays: cervixShift3DaysAfterTempShift
.filter(({date}) => date <= '2018-04-09'),
start: { date: '2018-04-05' },
end: { date: '2018-04-09' }
})
expect(status.phases.periOvulatory).to.eql({
cycleDays: cervixShift3DaysAfterTempShift
.filter(({date}) => {
return date >= '2018-04-10' && date <= '2018-04-20'
}),
start: { date: '2018-04-10' },
end: { date: '2018-04-20', time: '18:00'}
})
expect(status.phases.postOvulatory).to.eql({
cycleDays: cervixShift3DaysAfterTempShift
.filter(({date}) => date >= '2018-04-20'),
start: { date: '2018-04-20', time: '18:00' }
})
})
it('with cervix shift 4 days after temperature shift detects no post-ovulatory phase', () => {
const status = getSensiplanStatus({
cycle: cervixShift4DaysAfterTempShift,
previousCycle: cervixShiftAndFhmOnSameDay,
secondarySymptom: 'cervix'
})
expect(Object.keys(status.phases).length).to.eql(2)
expect(status.phases.preOvulatory).to.eql({
cycleDays: cervixShift4DaysAfterTempShift
.filter(({date}) => date <= '2018-04-09'),
start: { date: '2018-04-05' },
end: { date: '2018-04-09' }
})
expect(status.phases.periOvulatory).to.eql({
cycleDays: cervixShift4DaysAfterTempShift
.filter(({date}) => {
return date >= '2018-04-10'
}),
start: { date: '2018-04-10' }
})
})
it('with fertile cervix only occurring after end of temperature evaluation ignores it', () => {
const status = getSensiplanStatus({
cycle: fertileCervixOnlyAfterEndOfTempEval,
previousCycle: cervixShiftAndFhmOnSameDay,
secondarySymptom: 'cervix'
})
expect(status.temperatureShift).to.be.undefined()
expect(status.cervixShift).to.be.undefined()
expect(Object.keys(status.phases).length).to.eql(2)
expect(status.phases.preOvulatory).to.eql({
start: { date: '2018-06-01' },
end: { date: '2018-06-05' },
cycleDays: fertileCervixOnlyAfterEndOfTempEval
.filter(({date}) => date <= '2018-06-05')
})
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-06' },
cycleDays: fertileCervixOnlyAfterEndOfTempEval
.filter(({date}) => {
return date > '2018-06-05'
})
})
})
it('with no shifts no ovulation is found detects only pre and peri-ovulatory phase', () => {
const status = getSensiplanStatus({
cycle: noOvulationDetected,
previousCycle: cervixShiftAndFhmOnSameDay,
secondarySymptom: 'cervix'
})
expect(Object.keys(status.phases).length).to.eql(2)
expect(status.phases.preOvulatory).to.eql({
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: noOvulationDetected
.filter(({date}) => date > '2018-03-12'),
start: { date: '2018-03-13' }
})
})
})
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)],
secondarySymptom: 'cervix'
})
expect(status.temperatureShift).to.be.an('object')
expect(status.cervixShift).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-26', time: '18:00' },
cycleDays: longAndComplicatedCycle
.filter(({date}) => {
return date > '2018-06-04' && date <= '2018-06-26'
})
})
expect(status.phases.postOvulatory).to.eql({
start: {
date: '2018-06-26',
time: '18:00'
},
cycleDays: longAndComplicatedCycle
.filter(({date}) => date >= '2018-06-26')
})
})
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),
secondarySymptom: 'cervix'
})
expect(status.temperatureShift).to.be.an('object')
expect(status.cervixShift).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-26', time: '18:00' },
cycleDays: longAndComplicatedCycle
.filter(({date}) => {
return date > '2018-06-04' && date <= '2018-06-26'
})
})
expect(status.phases.postOvulatory).to.eql({
start: {
date: '2018-06-26',
time: '18:00'
},
cycleDays: longAndComplicatedCycle
.filter(({date}) => date >= '2018-06-26')
})
})
it('shortens the pre-ovu phase if early fertile cervix occurs', () => {
const status = getSensiplanStatus({
cycle: cycleWithEarlyCervix,
previousCycle: fhmOnDay12,
earlierCycles: Array(10).fill(fhmOnDay12),
secondarySymptom: 'cervix'
})
expect(status.temperatureShift).to.be.an('object')
expect(status.cervixShift).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: cycleWithEarlyCervix
.filter(({date}) => date <= '2018-06-01')
})
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-02' },
end: { date: '2018-06-20', time: '18:00'},
cycleDays: cycleWithEarlyCervix
.filter(({date}) => {
return date > '2018-06-01' && date <= '2018-06-20'
})
})
expect(status.phases.postOvulatory).to.eql({
start: { date: '2018-06-20', time: '18:00' },
cycleDays: cycleWithEarlyCervix
.filter(({date}) => date >= '2018-06-20')
})
})
it('shortens the pre-ovu phase if cervix occurs even on the first day', () => {
const status = getSensiplanStatus({
cycle: cycleWithCervixOnFirstDay,
previousCycle: fhmOnDay12,
earlierCycles: Array(10).fill(fhmOnDay12),
secondarySymptom: 'cervix'
})
expect(Object.keys(status.phases).length).to.eql(2)
expect(status.temperatureShift).to.be.an('object')
expect(status.cervixShift).to.be.an('object')
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-01' },
end: { date: '2018-06-20', time: '18:00'},
cycleDays: cycleWithCervixOnFirstDay
.filter(({date}) => {
return date >= '2018-06-01' && date <= '2018-06-20'
})
})
expect(status.phases.postOvulatory).to.eql({
start: { date: '2018-06-20', time: '18:00' },
cycleDays: cycleWithCervixOnFirstDay
.filter(({date}) => date >= '2018-06-20')
})
})
it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => {
const status = getSensiplanStatus({
cycle: longAndComplicatedCycle,
previousCycle: fhmOnDay15,
earlierCycles: Array(11).fill(fhmOnDay15),
secondarySymptom: 'cervix'
})
expect(status.temperatureShift).to.be.an('object')
expect(status.cervixShift).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-07' },
cycleDays: longAndComplicatedCycle
.filter(({date}) => date <= '2018-06-07')
})
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-08' },
end: { date: '2018-06-26', time: '18:00'},
cycleDays: longAndComplicatedCycle
.filter(({date}) => {
return date >= '2018-06-08' && date <= '2018-06-26'
})
})
expect(status.phases.postOvulatory).to.eql({
start: { date: '2018-06-26', time: '18:00' },
cycleDays: longAndComplicatedCycle
.filter(({date}) => date >= '2018-06-26')
})
})
it('does not lengthen the pre-ovu phase if < 12 cycles', () => {
const status = getSensiplanStatus({
cycle: longAndComplicatedCycle,
previousCycle: fhmOnDay15,
earlierCycles: Array(10).fill(fhmOnDay15),
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: longAndComplicatedCycle
.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: longAndComplicatedCycle
.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: longAndComplicatedCycle
.filter(({date}) => date >= '2018-06-26')
})
})
it('does not detect any pre-ovu phase if prev cycle had no fhm', () => {
const status = getSensiplanStatus({
cycle: longAndComplicatedCycle,
previousCycle: cycleWithoutFhmNoCervixShift,
earlierCycles: [...Array(12).fill(fhmOnDay15)],
secondarySymptom: 'cervix'
})
expect(Object.keys(status.phases).length).to.eql(2)
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-01' },
end: { date: '2018-06-26', time: '18:00' },
cycleDays: longAndComplicatedCycle
.filter(({date}) => {
return date >= '2018-06-01' && date <= '2018-06-26'
})
})
expect(status.phases.postOvulatory).to.eql({
start: {
date: '2018-06-26',
time: '18:00'
},
cycleDays: longAndComplicatedCycle
.filter(({date}) => date >= '2018-06-26')
})
})
})
describe('when args are wrong', () => {
it('throws when arg object is not in right format', () => {
const wrongObject = { ada: 'lovelace' }
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: [{
Ilike: "you"
}],
})).to.throw(AssertionError)
expect(() => getSensiplanStatus({
cycle: [{
date: '01.09.2018',
bleeding: { value: 0 },
cervix: {opening: 0, firmness: 0}
}],
})).to.throw(AssertionError)
expect(() => getSensiplanStatus({
cycle: [{
date: '2018-01-01',
bleeding: { value: 'medium' },
temperature: { value: 36.6 }
}],
})).to.throw(AssertionError)
expect(() => getSensiplanStatus({
cycle: [{
date: '2018-09-01',
bleeding: { value: 0 },
temperature: { value: '36.6' }
}],
})).to.throw(AssertionError)
expect(() => getSensiplanStatus({
cycle: [{
date: '2018-09-01',
bleeding: { value: 0 },
temperature: { value: 36.6 },
cervix: {opening: 4, firmness: 18}
}],
})).to.throw(AssertionError)
expect(() => getSensiplanStatus({
cycle: [{
date: '2018-09-01',
bleeding: { value: 0 },
temperature: 37.9
}],
})).to.throw(AssertionError)
})
it('throws if first cycle day does not have valid bleeding value', () => {
expect(() => getSensiplanStatus({
cycle: [{
date: '2018-09-01',
bleeding: { value: 0 }
}],
earlierCycles: [[{
date: '2017-09-23',
bleeding: { value: '1' }
}]]
})).to.throw(AssertionError)
})
})
})
})
-147
View File
@@ -1,147 +0,0 @@
import chai from 'chai'
import getCervixStatus from '../../lib/sympto/cervix'
const expect = chai.expect
function turnIntoCycleDayObject(value, fakeDate) {
const hardAndClosed = {
opening: 0,
firmness: 0
}
const hardAndOpen = {
opening: 1,
firmness: 0
}
const softAndClosed = {
opening: 0,
firmness: 1
}
const softAndOpen = {
opening: 1,
firmness: 1
}
const cervixStates = [hardAndClosed, hardAndOpen, softAndClosed, softAndOpen]
return {
date: fakeDate,
cervix: {
opening: cervixStates[value].opening,
firmness: cervixStates[value].firmness,
exclude: false
}
}
}
describe('sympto', () => {
describe('detects cervix shift', () => {
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, 16)
expect(status).to.eql({
detected: true,
cervixPeakBeforeShift: {
date: 10,
cervix: {
opening: 1,
firmness: 1,
exclude: false
}
},
evaluationCompleteDay: {
date: 13,
cervix: {
opening: 0,
firmness: 0,
exclude: false
}
}
})
})
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, 5)
expect(status).to.eql({
detected: true,
cervixPeakBeforeShift: {
date: 0,
cervix: {
opening: 0,
firmness: 1,
exclude: false
},
},
evaluationCompleteDay: {
date: 3,
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
}
}
})
})
})
describe('detects no cervix shift', () => {
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, 15)
expect(status).to.eql({ detected: false })
})
it('if cycleDays have not enough cervix values to detect valid cervix shift', () => {
const values = [2,0,0]
.map(turnIntoCycleDayObject)
const status = getCervixStatus(values, 17)
expect(status).to.eql({ detected: 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: false })
})
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, 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 })
})
})
})
-403
View File
@@ -1,403 +0,0 @@
function convertToSymptoFormat(val) {
const sympto = { date: val.date }
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
}
export const cycleWithFhm = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-13', temperature: 36.9, mucus: 4 },
{ date: '2018-06-15', temperature: 37.0, mucus: 2 },
{ date: '2018-06-16', temperature: 37.0, mucus: 2 },
{ date: '2018-06-17', temperature: 37.0, mucus: 2 },
{ date: '2018-06-18', temperature: 37.0, mucus: 2 }
].map(convertToSymptoFormat)
export const cycleWithoutFhm = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-09', temperature: 36.9, mucus: 4 },
{ date: '2018-06-10', temperature: 37.0, mucus: 2 },
{ date: '2018-06-13', temperature: 37.0, mucus: 2 }
].map(convertToSymptoFormat)
export const longAndComplicatedCycle = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-09', temperature: 36.6, mucus: 4 },
{ date: '2018-06-10', temperature: 36.5, mucus: 2 },
{ date: '2018-06-13', temperature: 36.55, mucus: 3 },
{ date: '2018-06-14', temperature: 36.6, mucus: 4 },
{ date: '2018-06-15', temperature: 36.65, mucus: 4 },
{ date: '2018-06-16', temperature: 36.8, mucus: 3 },
{ date: '2018-06-17', temperature: 36.75, mucus: 3 },
{ date: '2018-06-18', temperature: 36.85, mucus: 4 },
{ date: '2018-06-19', temperature: 36.9, mucus: 1 },
{ date: '2018-06-20', temperature: 36.95, mucus: 2 },
{ date: '2018-06-21', temperature: 36.9, mucus: 2 },
{ date: '2018-06-22', temperature: 37.0, mucus: 2 },
{ date: '2018-06-25', temperature: 37.0, mucus: 1 },
{ date: '2018-06-26', temperature: 36.9, mucus: 1 },
{ date: '2018-06-27', temperature: 37.0, mucus: 1 }
].map(convertToSymptoFormat)
export const cycleWithTempAndNoMucusShift = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-08', temperature: 36.55, mucus: 1 },
{ date: '2018-06-09', temperature: 36.6, mucus: 4 },
{ date: '2018-06-10', temperature: 36.5, mucus: 2 },
{ date: '2018-06-11', temperature: 36.6, mucus: 3 },
{ date: '2018-06-13', temperature: 36.55, mucus: 3 },
{ date: '2018-06-14', temperature: 36.6, mucus: 4 },
{ date: '2018-06-15', temperature: 36.65, mucus: 4 },
{ date: '2018-06-16', temperature: 36.8, mucus: 3 },
{ date: '2018-06-17', temperature: 36.75, mucus: 3 },
{ date: '2018-06-18', temperature: 36.85, mucus: 4 },
{ date: '2018-06-19', temperature: 36.9, mucus: 4 },
{ date: '2018-06-20', temperature: 36.95, mucus: 4 },
{ date: '2018-06-23', temperature: 37.0, mucus: 3 },
{ date: '2018-06-24', temperature: 36.95, mucus: 4 },
{ date: '2018-06-26', temperature: 36.9, mucus: 4 },
{ date: '2018-06-27', temperature: 37.0, mucus: 4 }
].map(convertToSymptoFormat)
export const cycleWithEarlyMucus = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75, mucus: 3 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-08', temperature: 36.55, mucus: 1 },
{ date: '2018-06-09', temperature: 36.6, mucus: 4 },
{ date: '2018-06-10', temperature: 36.5, mucus: 2 },
{ date: '2018-06-11', temperature: 36.6, mucus: 3 },
{ date: '2018-06-13', temperature: 36.55, mucus: 3 },
{ date: '2018-06-14', temperature: 36.6, mucus: 4 },
{ date: '2018-06-15', temperature: 36.65, mucus: 4 },
{ date: '2018-06-16', temperature: 36.8, mucus: 3 },
{ date: '2018-06-17', temperature: 36.75, mucus: 3 },
{ date: '2018-06-18', temperature: 36.85, mucus: 4 },
{ date: '2018-06-19', temperature: 36.9, mucus: 4 },
{ date: '2018-06-20', temperature: 36.95, mucus: 4 },
{ date: '2018-06-23', temperature: 37.0, mucus: 3 },
{ date: '2018-06-24', temperature: 36.95, mucus: 4 },
{ date: '2018-06-26', temperature: 36.9, mucus: 4 },
{ date: '2018-06-27', temperature: 37.0, mucus: 4 }
].map(convertToSymptoFormat)
export const cycleWithMucusOnFirstDay = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2, mucus: 3},
{ date: '2018-06-02', temperature: 36.75, mucus: 3 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-08', temperature: 36.55, mucus: 1 },
{ date: '2018-06-09', temperature: 36.6, mucus: 4 },
{ date: '2018-06-10', temperature: 36.5, mucus: 2 },
{ date: '2018-06-11', temperature: 36.6, mucus: 3 },
{ date: '2018-06-13', temperature: 36.55, mucus: 3 },
{ date: '2018-06-14', temperature: 36.6, mucus: 4 },
{ date: '2018-06-15', temperature: 36.65, mucus: 4 },
{ date: '2018-06-16', temperature: 36.8, mucus: 3 },
{ date: '2018-06-17', temperature: 36.75, mucus: 3 },
{ date: '2018-06-18', temperature: 36.85, mucus: 4 },
{ date: '2018-06-19', temperature: 36.9, mucus: 4 },
{ date: '2018-06-20', temperature: 36.95, mucus: 4 },
{ date: '2018-06-23', temperature: 37.0, mucus: 3 },
{ date: '2018-06-24', temperature: 36.95, mucus: 4 },
{ date: '2018-06-26', temperature: 36.9, mucus: 4 },
{ date: '2018-06-27', temperature: 37.0, mucus: 4 }
].map(convertToSymptoFormat)
export const cycleWithoutAnyShifts = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-07', temperature: 36.85, mucus: 0 },
{ date: '2018-06-08', temperature: 36.55, mucus: 1 }
].map(convertToSymptoFormat)
export const fiveDayCycle = [
{ date: '2018-06-01', bleeding: 2 },
{ date: '2018-06-03', bleeding: 3 },
].map(convertToSymptoFormat)
export const mucusPeakAndFhmOnSameDay = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-09', temperature: 36.6, mucus: 4 },
{ date: '2018-06-10', temperature: 36.5, mucus: 2 },
{ date: '2018-06-13', temperature: 36.55, mucus: 3 },
{ date: '2018-06-14', temperature: 36.6, mucus: 4 },
{ date: '2018-06-15', temperature: 36.65, mucus: 4 },
{ date: '2018-06-16', temperature: 36.8, mucus: 3 },
{ date: '2018-06-17', temperature: 36.75, mucus: 3 },
{ date: '2018-06-18', temperature: 36.85, mucus: 4 },
{ date: '2018-06-19', temperature: 36.9, mucus: 3 },
{ date: '2018-06-20', temperature: 37.0, mucus: 2 },
{ date: '2018-06-21', temperature: 36.9, mucus: 2 },
{ date: '2018-06-22', temperature: 37.0, mucus: 2 },
{ date: '2018-06-25', temperature: 37.0, mucus: 1 },
{ date: '2018-06-26', temperature: 36.9, mucus: 1 },
{ date: '2018-06-27', temperature: 37.0, mucus: 1 }
].map(convertToSymptoFormat)
export const mucusPeakOnLastDayOfTempEval = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-09', temperature: 36.6, mucus: 1 },
{ date: '2018-06-10', temperature: 36.5, mucus: 2 },
{ date: '2018-06-13', temperature: 36.55, mucus: 2 },
{ date: '2018-06-14', temperature: 36.6, mucus: 2 },
{ date: '2018-06-15', temperature: 36.65, mucus: 1 },
{ date: '2018-06-16', temperature: 36.8, mucus: 2 },
{ date: '2018-06-17', temperature: 36.75, mucus: 2 },
{ date: '2018-06-18', temperature: 36.85, mucus: 2 },
{ date: '2018-06-19', temperature: 36.9, mucus: 2 },
{ date: '2018-06-20', temperature: 36.95, mucus: 3 },
{ date: '2018-06-21', temperature: 36.9, mucus: 2 },
{ date: '2018-06-22', temperature: 37.0, mucus: 2 },
{ date: '2018-06-25', temperature: 37.0, mucus: 1 },
{ date: '2018-06-26', temperature: 36.9, mucus: 1 },
].map(convertToSymptoFormat)
export const mucusPeakAfterLastDayOfTempEval = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-09', temperature: 36.6, mucus: 1 },
{ date: '2018-06-10', temperature: 36.5, mucus: 2 },
{ date: '2018-06-13', temperature: 36.55, mucus: 2 },
{ date: '2018-06-14', temperature: 36.6, mucus: 2 },
{ date: '2018-06-15', temperature: 36.65, mucus: 1 },
{ date: '2018-06-16', temperature: 36.8, mucus: 2 },
{ date: '2018-06-17', temperature: 36.75, mucus: 2 },
{ date: '2018-06-18', temperature: 36.85, mucus: 2 },
{ date: '2018-06-19', temperature: 36.9, mucus: 2 },
{ date: '2018-06-20', temperature: 37.0, mucus: 2 },
{ date: '2018-06-21', temperature: 36.9, mucus: 3 },
{ date: '2018-06-22', temperature: 37.0, mucus: 2 },
{ date: '2018-06-25', temperature: 37.0, mucus: 1 },
{ date: '2018-06-26', temperature: 36.9, mucus: 1 },
].map(convertToSymptoFormat)
export const mucusPeakOnAndAfterLastDayOfTempEval = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-09', temperature: 36.6, mucus: 1 },
{ date: '2018-06-10', temperature: 36.5, mucus: 2 },
{ date: '2018-06-13', temperature: 36.55, mucus: 2 },
{ date: '2018-06-14', temperature: 36.6, mucus: 2 },
{ date: '2018-06-15', temperature: 36.65, mucus: 1 },
{ date: '2018-06-16', temperature: 36.8, mucus: 2 },
{ date: '2018-06-17', temperature: 36.75, mucus: 2 },
{ date: '2018-06-18', temperature: 36.85, mucus: 2 },
{ date: '2018-06-19', temperature: 36.9, mucus: 2 },
{ date: '2018-06-20', temperature: 37.0, mucus: 3 },
{ date: '2018-06-21', temperature: 36.9, mucus: 3 },
{ date: '2018-06-22', temperature: 37.0, mucus: 2 },
{ date: '2018-06-25', temperature: 37.0, mucus: 1 },
{ date: '2018-06-26', temperature: 36.9, mucus: 1 },
].map(convertToSymptoFormat)
export const mucusPeakTwoDaysBeforeFhm = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65, mucus: 2 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-09', temperature: 36.6, mucus: 4 },
{ date: '2018-06-10', temperature: 36.5, mucus: 2 },
{ date: '2018-06-13', temperature: 36.55, mucus: 3 },
{ date: '2018-06-14', temperature: 36.6, mucus: 4 },
{ date: '2018-06-15', temperature: 36.65, mucus: 4 },
{ date: '2018-06-16', temperature: 36.8, mucus: 4 },
{ date: '2018-06-17', temperature: 36.75, mucus: 3 },
{ date: '2018-06-18', temperature: 36.85, mucus: 2 },
{ date: '2018-07-02', temperature: 36.9, mucus: 3 },
{ date: '2018-07-03', temperature: 37.0, mucus: 2 },
{ date: '2018-07-04', temperature: 36.9, mucus: 2 },
].map(convertToSymptoFormat)
export const mucusPeak5DaysAfterFhm = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75, mucus: 2 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-09', temperature: 36.6, mucus: 4 },
{ date: '2018-06-10', temperature: 36.5, mucus: 2 },
{ date: '2018-06-13', temperature: 36.55, mucus: 3 },
{ date: '2018-06-14', temperature: 36.6, mucus: 3 },
{ date: '2018-06-15', temperature: 36.65, mucus: 3 },
{ date: '2018-06-16', temperature: 36.8, mucus: 3 },
{ date: '2018-06-17', temperature: 36.75, mucus: 3 },
{ date: '2018-06-18', temperature: 36.70, mucus: 2 },
{ date: '2018-06-19', temperature: 36.9, mucus: 2 },
{ date: '2018-06-20', temperature: 36.95, mucus: 2 },
{ date: '2018-06-21', temperature: 36.9, mucus: 2 },
{ date: '2018-06-22', temperature: 37.0, mucus: 2 },
{ date: '2018-06-25', temperature: 37.0, mucus: 1 },
{ date: '2018-06-26', temperature: 36.9, mucus: 4 },
{ date: '2018-06-30', temperature: 37.0, mucus: 1 },
{ date: '2018-07-01', temperature: 37.0, mucus: 1 },
{ date: '2018-07-02', temperature: 37.0, mucus: 1 }
].map(convertToSymptoFormat)
export const highestMucusQualityAfterEndOfEval = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75, mucus: 2 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-09', temperature: 36.6, mucus: 1 },
{ date: '2018-06-10', temperature: 36.5, mucus: 2 },
{ date: '2018-06-13', temperature: 36.55, mucus: 3 },
{ date: '2018-06-14', temperature: 36.6, mucus: 3 },
{ date: '2018-06-15', temperature: 36.65, mucus: 3 },
{ date: '2018-06-16', temperature: 36.8, mucus: 3 },
{ date: '2018-06-17', temperature: 36.75, mucus: 3 },
{ date: '2018-06-18', temperature: 36.70, mucus: 2 },
{ date: '2018-06-19', temperature: 36.9, mucus: 3 },
{ date: '2018-06-20', temperature: 36.95, mucus: 3 },
{ date: '2018-06-21', temperature: 36.9, mucus: 3 },
{ date: '2018-06-22', temperature: 37.0, mucus: 1 },
{ date: '2018-06-25', temperature: 37.0, mucus: 1 },
{ date: '2018-06-26', temperature: 36.9, mucus: 1 },
{ date: '2018-06-30', temperature: 37.0, mucus: 1 },
{ date: '2018-07-01', temperature: 37.0, mucus: 4 },
{ date: '2018-07-02', temperature: 37.0, mucus: 1 }
].map(convertToSymptoFormat)
export const fhm5DaysAfterMucusPeak = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-09', temperature: 36.6, mucus: 4 },
{ date: '2018-06-10', temperature: 36.5, mucus: 2 },
{ date: '2018-06-13', temperature: 36.55, mucus: 3 },
{ date: '2018-06-14', temperature: 36.6, mucus: 4 },
{ date: '2018-06-15', temperature: 36.65, mucus: 3 },
{ date: '2018-06-16', temperature: 36.8, mucus: 3 },
{ date: '2018-06-17', temperature: 36.75, mucus: 3 },
{ date: '2018-06-18', temperature: 36.85, mucus: 2 },
{ date: '2018-06-19', temperature: 36.9, mucus: 2 },
{ date: '2018-06-20', temperature: 36.95, mucus: 2 },
{ date: '2018-06-21', temperature: 36.9, mucus: 2 },
{ date: '2018-06-22', temperature: 37.0, mucus: 2 },
{ date: '2018-06-25', temperature: 37.0, mucus: 1 },
{ date: '2018-06-26', temperature: 36.9, mucus: 4 },
{ date: '2018-06-27', temperature: 37.0, mucus: 1 }
].map(convertToSymptoFormat)
export const fhmOnDay12 = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-09', temperature: 36.6, mucus: 2 },
{ date: '2018-06-10', temperature: 36.5, mucus: 3 },
{ date: '2018-06-12', temperature: 36.9, mucus: 3 },
{ date: '2018-06-14', temperature: 37.0, mucus: 2 },
{ date: '2018-06-17', temperature: 37.0, mucus: 2 },
{ date: '2018-06-18', temperature: 37.0, mucus: 2 },
].map(convertToSymptoFormat)
export const fhmOnDay15 = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8, mucus: 0 },
{ date: '2018-06-09', temperature: 36.6, mucus: 2 },
{ date: '2018-06-10', temperature: 36.5, mucus: 3 },
{ date: '2018-06-15', temperature: 36.9, mucus: 3 },
{ date: '2018-06-16', temperature: 37.0, mucus: 2 },
{ date: '2018-06-17', temperature: 37.0, mucus: 2 },
{ date: '2018-06-18', temperature: 37.0, mucus: 2 },
].map(convertToSymptoFormat)
export const mucusPeakSlightlyBeforeTempShift = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-07', temperature: 36.5, mucus: 1 },
{ date: '2018-06-08', temperature: 36.45, mucus: 2},
{ date: '2018-06-09', temperature: 36.5, mucus: 2},
{ date: '2018-06-10', temperature: 36.55, mucus: 2},
{ date: '2018-06-11', temperature: 36.5, mucus: 3},
{ date: '2018-06-12', temperature: 36.55, mucus: 3},
{ date: '2018-06-13', temperature: 36.55, mucus: 4},
{ date: '2018-06-14', temperature: 36.65, mucus: 3},
{ date: '2018-06-15', temperature: 36.7, mucus: 3},
{ date: '2018-06-16', temperature: 36.7, mucus: 3},
{ date: '2018-06-17', temperature: 36.65, mucus: 2},
{ date: '2018-06-18', temperature: 36.7, mucus: 1},
{ date: '2018-06-19', temperature: 36.8, mucus: 1},
{ date: '2018-06-20', temperature: 36.85, mucus: 1},
{ date: '2018-06-21', temperature: 36.9, mucus: 1},
{ date: '2018-06-22', temperature: 36.9, mucus: 1}
].map(convertToSymptoFormat)
export const mucusOnlyAfterEndOfTempEval = [
{ date: '2018-06-01', temperature: 36.7, bleeding: 2 },
{ date: '2018-06-02', temperature: 36.75 },
{ date: '2018-06-04', temperature: 36.7 },
{ date: '2018-06-05', temperature: 36.65 },
{ date: '2018-06-06', temperature: 36.8 },
{ date: '2018-06-09', temperature: 36.6 },
{ date: '2018-06-10', temperature: 36.5 },
{ date: '2018-06-13', temperature: 36.55 },
{ date: '2018-06-14', temperature: 36.6 },
{ date: '2018-06-15', temperature: 36.65 },
{ date: '2018-06-16', temperature: 36.8 },
{ date: '2018-06-17', temperature: 36.75 },
{ date: '2018-06-18', temperature: 36.70 },
{ date: '2018-06-19', temperature: 36.9 },
{ date: '2018-06-20', temperature: 36.95 },
{ date: '2018-06-21', temperature: 36.9 },
{ date: '2018-06-22', temperature: 37.0 },
{ date: '2018-06-25', temperature: 37.0, mucus: 4 },
{ date: '2018-06-26', temperature: 36.9, mucus: 1 },
{ date: '2018-06-30', temperature: 37.0, mucus: 1 },
{ date: '2018-07-01', temperature: 37.0, mucus: 1 },
{ date: '2018-07-02', temperature: 37.0, mucus: 1 }
].map(convertToSymptoFormat)
-661
View File
@@ -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,
mucusPeakOnLastDayOfTempEval,
mucusPeakAfterLastDayOfTempEval,
mucusPeakOnAndAfterLastDayOfTempEval,
fhm5DaysAfterMucusPeak,
mucusPeak5DaysAfterFhm,
mucusPeakTwoDaysBeforeFhm,
fhmOnDay12,
fhmOnDay15,
mucusPeakSlightlyBeforeTempShift,
mucusOnlyAfterEndOfTempEval
} 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', () => {
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', () => {
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,
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', () => {
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', () => {
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', () => {
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'),
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 mucus peak 3 days after fhM waits for end of mucus eval', () => {
const status = getSensiplanStatus({
cycle: mucusPeakOnLastDayOfTempEval,
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: mucusPeakOnLastDayOfTempEval
.filter(({date}) => date <= '2018-06-05')
})
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-06' },
end: { date: '2018-06-25', time: '18:00' },
cycleDays: mucusPeakOnLastDayOfTempEval
.filter(({date}) => {
return date > '2018-06-05' && date <= '2018-06-25'
})
})
expect(status.phases.postOvulatory).to.eql({
start: {
date: '2018-06-25',
time: '18:00'
},
cycleDays: mucusPeakOnLastDayOfTempEval
.filter(({date}) => date >= '2018-06-25')
})
})
it('with mucus peak 4 days after fhM detects no postovu phase', () => {
const status = getSensiplanStatus({
cycle: mucusPeakAfterLastDayOfTempEval,
previousCycle: cycleWithFhm
})
expect(Object.keys(status.phases).length).to.eql(2)
expect(status.phases.preOvulatory).to.eql({
start: { date: '2018-06-01' },
end: { date: '2018-06-05' },
cycleDays: mucusPeakAfterLastDayOfTempEval
.filter(({date}) => date <= '2018-06-05')
})
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-06' },
cycleDays: mucusPeakAfterLastDayOfTempEval
.filter(({date}) => date > '2018-06-05')
})
})
it('with mucus peak 3 and 4 days after fhM detects no postovu phase', () => {
const status = getSensiplanStatus({
cycle: mucusPeakOnAndAfterLastDayOfTempEval,
previousCycle: cycleWithFhm
})
expect(Object.keys(status.phases).length).to.eql(2)
expect(status.phases.preOvulatory).to.eql({
start: { date: '2018-06-01' },
end: { date: '2018-06-05' },
cycleDays: mucusPeakOnAndAfterLastDayOfTempEval
.filter(({date}) => date <= '2018-06-05')
})
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-06' },
cycleDays: mucusPeakOnAndAfterLastDayOfTempEval
.filter(({date}) => date > '2018-06-05')
})
})
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 mucus only occurring after end of temperature evaluation ignores it', () => {
const status = getSensiplanStatus({
cycle: mucusOnlyAfterEndOfTempEval,
previousCycle: cycleWithFhm
})
expect(status.temperatureShift).to.be.undefined()
expect(status.mucusShift).to.be.undefined()
expect(Object.keys(status.phases).length).to.eql(2)
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' },
cycleDays: mucusOnlyAfterEndOfTempEval
.filter(({date}) => {
return date > '2018-06-05'
})
})
})
})
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)
})
})
})
})
-80
View File
@@ -1,80 +0,0 @@
import chai from 'chai'
import getMucusStatus from '../../lib/sympto/mucus'
const expect = chai.expect
function turnIntoCycleDayObject(value, fakeDate) {
return {
mucus : { value },
date: fakeDate
}
}
describe('sympto', () => {
describe('detect mucus shift', () => {
describe('regular rule', () => {
it('detects mucus shift correctly', function () {
const values = [0,0,0,1,1,2,2,2,3,3,3,2,2,0,1,1,1,1,0,0,0,0,0]
.map(turnIntoCycleDayObject)
const status = getMucusStatus(values, 12)
expect(status).to.eql({
detected: true,
mucusPeak: {
date: 10,
mucus: { value: 3 }
},
evaluationCompleteDay: {
date: 13,
mucus: { value: 0 }
}
})
})
it('detects no mucus shift when there are less than 3 days of lower quality', function () {
const values = [0, 1, 1, 2, 0, 0, 1, 2, 3, 2, 3, 3, 3, 2, 2]
.map(turnIntoCycleDayObject)
const status = getMucusStatus(values, 30)
expect(status).to.eql({ detected: false })
})
it('detects no mucus shift when there are no mucus values', function () {
const status = getMucusStatus(Array(10).fill({
date: 1,
temperature: { value: 35 }
}))
expect(status).to.eql({ detected: false })
})
it('detects no mucus shift when the mucus values are all the same', function () {
const values = [2, 2, 2, 2, 2, 2, 2, 2]
.map(turnIntoCycleDayObject)
const status = getMucusStatus(values, 30)
expect(status).to.eql({ detected: false })
})
it('detects no mucus shift when mucus only changes from dry to nothing', function () {
const values = [0,0,0,1,0,0,0,0,0,0,0]
.map(turnIntoCycleDayObject)
const status = getMucusStatus(values, 30)
expect(status).to.eql({ detected: false })
})
it('ignores an early seeming shift from 0 to 1', function () {
const values = [0,0,0,1,0,0,0,2,3,3,3,2,2,0,1,1,1,1,0,0,0,0,0]
.map(turnIntoCycleDayObject)
const status = getMucusStatus(values, 12)
expect(status).to.eql({
detected: true,
mucusPeak: {
date: 10,
mucus: { value: 3 }
},
evaluationCompleteDay: {
date: 13,
mucus: { value: 0 }
}
})
})
})
})
})
-272
View File
@@ -1,272 +0,0 @@
import chai from 'chai'
import getTemperatureStatus from '../../lib/sympto/temperature'
const expect = chai.expect
function turnIntoCycleDayObject(value, fakeDate) {
return {
temperature : { value },
date: fakeDate
}
}
describe('sympto', () => {
describe('detect temperature shift', () => {
describe('regular rule', () => {
it('reports lower temperature status before shift', () => {
const lowerTemps = [36.7, 36.57, 36.47, 36.49, 36.57]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(lowerTemps)
expect(status).to.eql({ detected: false })
})
it('detects temperature shift correctly', () => {
const tempShift =
[36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(tempShift)
expect(status).to.eql({
detected: true,
ltl: 36.6,
firstHighMeasurementDay: {
date: 7,
temperature: { value: 36.8 }
},
evaluationCompleteDay: {
date: 9,
temperature: { value: 36.8 }
},
rule: 0
})
})
it('detects temperature shift correctly with drop after third high temp', () => {
const tempShift =
[36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8, 36.4]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(tempShift)
expect(status).to.eql({
detected: true,
ltl: 36.6,
firstHighMeasurementDay: {
date: 7,
temperature: { value: 36.8 }
},
evaluationCompleteDay: {
date: 9,
temperature: { value: 36.8 }
},
rule: 0
})
})
it('detects no temperature shift when there are no 6 low temps', () => {
const tempShift = [36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(tempShift)
expect(status).to.eql({ detected: false })
})
it('detects no temperature shift if the shift is not high enough', () => {
const tempShift =
[36.57, 36.7, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(tempShift)
expect(status).to.eql({ detected: false })
})
it('detects missing temperature shift correctly', () => {
const noTempShift =
[36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(noTempShift)
expect(status).to.eql({ detected: false })
})
it('detects shift after an earlier one was invalid', () => {
const temps =
[36.4, 36.4, 36.4, 36.4, 36.4, 36.4, 36.6, 36.6, 36.4, 36.4,
36.7, 36.8, 36.9]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(temps)
expect(status).to.eql({
ltl: 36.6,
firstHighMeasurementDay: {
date: 10,
temperature: { value: 36.7 }
},
evaluationCompleteDay: {
date: 12,
temperature: { value: 36.9 }
},
detected: true,
rule: 0
})
})
it('detects 2 consecutive invalid shifts', () => {
const temps =
[36.4, 36.4, 36.4, 36.4, 36.4, 36.4, 36.6, 36.6, 36.4, 36.4,
36.6, 36.6, 36.7]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(temps)
expect(status).to.eql({ detected: false })
})
})
describe('1st exception rule', () => {
it('detects temperature shift', () => {
const firstException =
[36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55,
36.8, 36.86, 36.77, 36.63]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(firstException)
expect(status).to.eql({
ltl: 36.6,
firstHighMeasurementDay: {
date: 7,
temperature: { value: 36.8 }
},
evaluationCompleteDay: {
date: 10,
temperature : { value: 36.63 }
},
detected: true,
rule: 1
})
})
it('detects missing temperature shift correctly', () => {
const firstExceptionNoShift =
[36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55,
36.8, 36.86, 36.77, 36.57]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(firstExceptionNoShift)
expect(status).to.eql({ detected: false })
})
it('detects missing temperature shift with not enough high temps', () => {
const temps =
[36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(temps)
expect(status).to.eql({ detected: false })
})
it('detects shift after an earlier one was invalid', () => {
const temps =
[36.4, 36.4, 36.4, 36.4, 36.4, 36.4, 36.6, 36.6, 36.4, 36.4,
36.7, 36.7, 36.7, 36.7]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(temps)
expect(status).to.eql({
ltl: 36.6,
firstHighMeasurementDay: {
date: 10,
temperature: { value: 36.7 }
},
evaluationCompleteDay: {
date: 13,
temperature : { value: 36.7 }
},
detected: true,
rule: 1
})
})
})
describe('2nd exception rule', () => {
it('detects temperature shift with exception temp eql ltl', () => {
const secondException =
[36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55,
36.8, 36.86, 36.6, 36.8]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(secondException)
expect(status).to.eql({
ltl: 36.6,
firstHighMeasurementDay: {
date: 7,
temperature: { value: 36.8 }
},
evaluationCompleteDay: {
date: 10,
temperature : { value: 36.8 }
},
detected: true,
rule: 2
})
})
it('detects temperature shift with exception temp lower than ltl', () => {
const secondException =
[36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55,
36.8, 36.86, 36.4, 36.8]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(secondException)
expect(status).to.eql({
ltl: 36.6,
firstHighMeasurementDay: {
date: 7,
temperature: { value: 36.8 }
},
evaluationCompleteDay: {
date: 10,
temperature : { value: 36.8 }
},
detected: true,
rule: 2
})
})
it('detects missing temperature shift correctly', () => {
const temps =
[36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55,
36.8, 36.86, 36.4, 36.77, 36.77]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(temps)
expect(status).to.eql({ detected: false })
})
it('detects missing temperature shift when not enough high temps', () => {
const temps =
[36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.4]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(temps)
expect(status).to.eql({ detected: false })
})
it('detects shift after an earlier one was invalid', () => {
const temps =
[36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.4,
36.77, 36.9, 36.9, 36.86, 37.04]
.map(turnIntoCycleDayObject)
const status = getTemperatureStatus(temps)
expect(status).to.eql({
ltl: 36.85,
firstHighMeasurementDay: {
date: 11,
temperature: { value: 36.9 }
},
evaluationCompleteDay: {
date: 14,
temperature : { value: 37.04 }
},
detected: true,
rule: 2
})
})
})
})
})