Skip to content
Snippets Groups Projects
Commit e4bae38d authored by Julia Friesel's avatar Julia Friesel
Browse files

Introduce facade for sympto

parent fb990b5a
No related branches found
No related tags found
No related merge requests found
import { detectTemperatureShift } from './sympto/temperature' import getTemperatureStatus from './sympto/temperature'
import cycleModule from './cycle' import cycleModule from './cycle'
const getLastMensesStart = cycleModule().getLastMensesStart const getLastMensesStart = cycleModule().getLastMensesStart
...@@ -10,7 +10,7 @@ function getTemperatureFertilityStatus(targetDateString) { ...@@ -10,7 +10,7 @@ function getTemperatureFertilityStatus(targetDateString) {
const previousTemperaturesInCycle = getPreviousTemperaturesInCycle(targetDateString, lastMensesStart) const previousTemperaturesInCycle = getPreviousTemperaturesInCycle(targetDateString, lastMensesStart)
// we get temps with latest first, but sympto module expects latest last // we get temps with latest first, but sympto module expects latest last
previousTemperaturesInCycle.reverse() previousTemperaturesInCycle.reverse()
const status = detectTemperatureShift(previousTemperaturesInCycle) const status = getTemperatureStatus(previousTemperaturesInCycle)
return formatStatusForApp(status) return formatStatusForApp(status)
} }
......
import getTemperatureStatus from './temperature'
import getMucusStatus from './mucus'
export default function (cycleDays) {
const temperatureStatus = getTemperatureStatus(cycleDays)
const mucusStatus = getMucusStatus(cycleDays)
}
\ No newline at end of file
function detectTemperatureShift(temperaturesOfCycle) { export default function getTemperatureStatus(temperaturesOfCycle) {
// sensiplan rounds temps to the nearest 0.05 // sensiplan rounds temps to the nearest 0.05
const tempValues = temperaturesOfCycle.map(val => rounded(val, 0.05)) const tempValues = temperaturesOfCycle.map(val => rounded(val, 0.05))
...@@ -25,7 +25,7 @@ function detectTemperatureShift(temperaturesOfCycle) { ...@@ -25,7 +25,7 @@ function detectTemperatureShift(temperaturesOfCycle) {
if (temp <= ltl) return acc if (temp <= ltl) return acc
const checkResult = checkIfFirstHighMeasurement(temp, i, tempValues, ltl) const checkResult = checkIfFirstHighMeasurement(temp, i, tempValues, ltl)
// if we don't have a winner, keep going // if we don't have a winner, keep move on to the next candidates
if (!checkResult.isFirstHighMeasurement) return acc if (!checkResult.isFirstHighMeasurement) return acc
// if we do, remember the details and start collecting the high level temps // if we do, remember the details and start collecting the high level temps
...@@ -115,8 +115,4 @@ function secondOrThirdTempIsAtOrBelowLtl(nextTemps, ltl) { ...@@ -115,8 +115,4 @@ function secondOrThirdTempIsAtOrBelowLtl(nextTemps, ltl) {
} else { } else {
return false return false
} }
}
export {
detectTemperatureShift
} }
\ No newline at end of file
import chai from 'chai' import chai from 'chai'
import { detectTemperatureShift } from '../../lib/sympto/temperature' import getTemperatureStatus from '../../lib/sympto/temperature'
const expect = chai.expect const expect = chai.expect
...@@ -8,13 +8,13 @@ describe.only('sympto', () => { ...@@ -8,13 +8,13 @@ describe.only('sympto', () => {
describe('regular rule', () => { describe('regular rule', () => {
it('reports lower temperature status before shift', function () { it('reports lower temperature status before shift', function () {
const lowerTemps = [36.7, 36.57, 36.47, 36.49, 36.57] const lowerTemps = [36.7, 36.57, 36.47, 36.49, 36.57]
const status = detectTemperatureShift(lowerTemps) const status = getTemperatureStatus(lowerTemps)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
it('detects temperature shift correctly', function () { it('detects temperature shift correctly', function () {
const tempShift = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8] const tempShift = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8]
const status = detectTemperatureShift(tempShift) const status = getTemperatureStatus(tempShift)
expect(status).to.eql({ expect(status).to.eql({
low: [36.55, 36.45, 36.5, 36.55, 36.6, 36.55], low: [36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
ltl: 36.6, ltl: 36.6,
...@@ -26,26 +26,26 @@ describe.only('sympto', () => { ...@@ -26,26 +26,26 @@ describe.only('sympto', () => {
it('detects no temperature shift when there are no 6 low temps', function () { it('detects no temperature shift when there are no 6 low temps', function () {
const tempShift = [36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8] const tempShift = [36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8]
const status = detectTemperatureShift(tempShift) const status = getTemperatureStatus(tempShift)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
it('detects no temperature shift if the shift is not high enough', function () { it('detects no temperature shift if the shift is not high enough', function () {
const tempShift = [36.57, 36.7, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8] const tempShift = [36.57, 36.7, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8]
const status = detectTemperatureShift(tempShift) const status = getTemperatureStatus(tempShift)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
it('detects missing temperature shift correctly', function () { it('detects missing temperature shift correctly', function () {
const noTempShift = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77] const noTempShift = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77]
const status = detectTemperatureShift(noTempShift) const status = getTemperatureStatus(noTempShift)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
it('detects shift after an earlier one was invalid', function () { it('detects shift after an earlier one was invalid', function () {
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] 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]
const status = detectTemperatureShift(temps) const status = getTemperatureStatus(temps)
expect(status).to.eql({ expect(status).to.eql({
low: [36.4, 36.4, 36.6, 36.6, 36.4, 36.4], low: [36.4, 36.4, 36.6, 36.6, 36.4, 36.4],
ltl: 36.6, ltl: 36.6,
...@@ -58,7 +58,7 @@ describe.only('sympto', () => { ...@@ -58,7 +58,7 @@ describe.only('sympto', () => {
it('detects 2 consecutive invalid shifts', function () { it('detects 2 consecutive invalid shifts', function () {
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] 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]
const status = detectTemperatureShift(temps) const status = getTemperatureStatus(temps)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
}) })
...@@ -66,7 +66,7 @@ describe.only('sympto', () => { ...@@ -66,7 +66,7 @@ describe.only('sympto', () => {
describe('1st exception rule', () => { describe('1st exception rule', () => {
it('detects temperature shift', function () { it('detects temperature shift', function () {
const firstException = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77, 36.63] const firstException = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77, 36.63]
const status = detectTemperatureShift(firstException) const status = getTemperatureStatus(firstException)
expect(status).to.eql({ expect(status).to.eql({
low: [36.55, 36.45, 36.5, 36.55, 36.6, 36.55], low: [36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
ltl: 36.6, ltl: 36.6,
...@@ -78,20 +78,20 @@ describe.only('sympto', () => { ...@@ -78,20 +78,20 @@ describe.only('sympto', () => {
it('detects missing temperature shift correctly', function () { it('detects missing temperature shift correctly', function () {
const firstExceptionNoShift = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77, 36.57] const firstExceptionNoShift = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77, 36.57]
const status = detectTemperatureShift(firstExceptionNoShift) const status = getTemperatureStatus(firstExceptionNoShift)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
it('detects missing temperature shift with not enough high temps', function () { it('detects missing temperature shift with not enough high temps', function () {
const temps = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77] const temps = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77]
const status = detectTemperatureShift(temps) const status = getTemperatureStatus(temps)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
it('detects shift after an earlier one was invalid', function () { it('detects shift after an earlier one was invalid', function () {
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] 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]
const status = detectTemperatureShift(temps) const status = getTemperatureStatus(temps)
expect(status).to.eql({ expect(status).to.eql({
low: [36.4, 36.4, 36.6, 36.6, 36.4, 36.4], low: [36.4, 36.4, 36.6, 36.6, 36.4, 36.4],
ltl: 36.6, ltl: 36.6,
...@@ -105,7 +105,7 @@ describe.only('sympto', () => { ...@@ -105,7 +105,7 @@ describe.only('sympto', () => {
describe('2nd exception rule', () => { describe('2nd exception rule', () => {
it('detects temperature shift with exception temp eql ltl', function () { it('detects temperature shift with exception temp eql ltl', function () {
const secondException = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.6, 36.8] const secondException = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.6, 36.8]
const status = detectTemperatureShift(secondException) const status = getTemperatureStatus(secondException)
expect(status).to.eql({ expect(status).to.eql({
low: [36.55, 36.45, 36.5, 36.55, 36.6, 36.55], low: [36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
ltl: 36.6, ltl: 36.6,
...@@ -117,7 +117,7 @@ describe.only('sympto', () => { ...@@ -117,7 +117,7 @@ describe.only('sympto', () => {
it('detects temperature shift with exception temp lower than ltl', function () { it('detects temperature shift with exception temp lower than ltl', function () {
const secondException = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.4, 36.8] const secondException = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.4, 36.8]
const status = detectTemperatureShift(secondException) const status = getTemperatureStatus(secondException)
expect(status).to.eql({ expect(status).to.eql({
low: [36.55, 36.45, 36.5, 36.55, 36.6, 36.55], low: [36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
ltl: 36.6, ltl: 36.6,
...@@ -129,19 +129,19 @@ describe.only('sympto', () => { ...@@ -129,19 +129,19 @@ describe.only('sympto', () => {
it('detects missing temperature shift correctly', function () { it('detects missing temperature shift correctly', function () {
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] 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]
const status = detectTemperatureShift(temps) const status = getTemperatureStatus(temps)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
it('detects missing temperature shift when not enough high temps', function () { it('detects missing temperature shift when not enough high temps', function () {
const temps = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.4] const temps = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.4]
const status = detectTemperatureShift(temps) const status = getTemperatureStatus(temps)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
it('detects shift after an earlier one was invalid', function () { it('detects shift after an earlier one was invalid', function () {
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] 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]
const status = detectTemperatureShift(temps) const status = getTemperatureStatus(temps)
expect(status).to.eql({ expect(status).to.eql({
low: [36.6, 36.55, 36.8, 36.85, 36.4, 36.75], low: [36.6, 36.55, 36.8, 36.85, 36.4, 36.75],
ltl: 36.85, ltl: 36.85,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment