diff --git a/.eslintrc b/.eslintrc index 40d7e9b2b5e5ba1b615742b17810e711274a4dda..6ec6205a75c3c3f5668108ae62979aa3fafedbd7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -48,6 +48,6 @@ "prefer-const": "error", "no-trailing-spaces": "error", "react/prop-types": 0, - "max-len": "warn" + "max-len": [1, {"ignoreStrings": true}] } } \ No newline at end of file diff --git a/labels/labels.js b/labels/labels.js index a5ed61a483b3ffc78cc83f68ce1a0c3bfa5b79d7..9afc14201c73ad669b77e89d29539672a28770ca 100644 --- a/labels/labels.js +++ b/labels/labels.js @@ -1,5 +1,7 @@ -const bleeding = ['spotting', 'light', 'medium', 'heavy'] +export const bleeding = ['spotting', 'light', 'medium', 'heavy'] -export { - bleeding +export const fertilityStatus = { + fertile: 'fertile', + infertile: 'infertile', + unknown: 'We cannot show any cycle information because no menses has been entered' } \ No newline at end of file diff --git a/lib/sympto-adapter.js b/lib/sympto-adapter.js index 8c1c3e131f541636e094932aa1e3fc47ed0f4ff4..6d2a489b0dcbf1127254f0da4ad506d9243cd540 100644 --- a/lib/sympto-adapter.js +++ b/lib/sympto-adapter.js @@ -1,11 +1,12 @@ import getFertilityStatus from './sympto' import cycleModule from './cycle' +import { fertilityStatus } from '../labels/labels' const { getCycleDaysBeforeDay, getPreviousCycles } = cycleModule() export default function (dateString) { const cycle = getCycleDaysBeforeDay(dateString) - if (!cycle) return `We cannot show any cycle information because no menses has been entered` + if (!cycle) return fertilityStatus.unknown // we get earliest last, but sympto wants earliest first cycle.reverse() @@ -18,5 +19,9 @@ export default function (dateString) { } function formatStatusForApp(status) { - return status.assumeFertility ? 'fertile' : 'infertile' + if (status.assumeFertility) { + return fertilityStatus.fertile + } else { + return fertilityStatus.infertile + } } \ No newline at end of file diff --git a/lib/sympto/index.js b/lib/sympto/index.js index 015093914f293a2a2a2fff24d135bb0e7d1f6897..42902012de31b6970a973f22e026775f3fc1122f 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -14,9 +14,10 @@ export default function getSymptoThermalStatus({ cycle, previousCycles = [] }) { // if there was no first higher measurement in the previous cycle, // no infertile pre-ovulatory phase may be assumed - if (previousCycles) { - const lastCycle = previousCycles[previousCycles.length - 1] - if (lastCycle && getSymptoThermalStatus({ cycle: lastCycle }).temperatureShift) { + const lastCycle = previousCycles[previousCycles.length - 1] + if (lastCycle) { + const statusForLast = getSymptoThermalStatus({ cycle: lastCycle }) + if (statusForLast.temperatureShift) { status.phases.preOvulatory = getPreOvulatoryPhase(cycle, previousCycles) if (status.phases.preOvulatory.cycleDays.length === cycle.length) { status.assumeFertility = false @@ -33,7 +34,8 @@ export default function getSymptoThermalStatus({ cycle, previousCycles = [] }) { if (status.phases.preOvulatory) { const prePhase = status.phases.preOvulatory - periPhase.start.date = LocalDate.parse(prePhase.end.date).plusDays(1).toString() + 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 { @@ -48,22 +50,28 @@ export default function getSymptoThermalStatus({ cycle, previousCycles = [] }) { const mucusShift = getMucusShift(cycle, tempEvalEndIndex) if (!mucusShift.detected) return status - const periOvulatoryEnd = - temperatureShift.evaluationCompleteDay.date > mucusShift.evaluationCompleteDay.date ? - temperatureShift.evaluationCompleteDay : mucusShift.evaluationCompleteDay + let periOvulatoryEnd + const tempOver = temperatureShift.evaluationCompleteDay.date + const mucusOver = mucusShift.evaluationCompleteDay.date - const prevPeriOvulatoryDays = periPhase.cycleDays - const periOvulatoryEndIndex = prevPeriOvulatoryDays.indexOf(periOvulatoryEnd) + if (tempOver > mucusOver) { + periOvulatoryEnd = temperatureShift.evaluationCompleteDay + } else { + periOvulatoryEnd = mucusShift.evaluationCompleteDay + } + + const previousPeriDays = periPhase.cycleDays + const previousPeriEndIndex = previousPeriDays.indexOf(periOvulatoryEnd) status.phases.postOvulatory = { start: { date: periOvulatoryEnd.date, time: '18:00' }, - cycleDays: prevPeriOvulatoryDays.slice(periOvulatoryEndIndex) + cycleDays: previousPeriDays.slice(previousPeriEndIndex) } - periPhase.cycleDays = prevPeriOvulatoryDays.slice(0, periOvulatoryEndIndex + 1) + periPhase.cycleDays = previousPeriDays.slice(0, previousPeriEndIndex + 1) periPhase.end = status.phases.postOvulatory.start status.mucusShift = mucusShift diff --git a/lib/sympto/mucus.js b/lib/sympto/mucus.js index 07a7ca4ff8bd4ab6203a4ab7a774ea2d72fc46fe..9eb37efb6d5af600a24a05d91c373492bc44521b 100644 --- a/lib/sympto/mucus.js +++ b/lib/sympto/mucus.js @@ -6,16 +6,16 @@ export default function (cycleDays, tempEvalEndIndex) { const day = mucusDays[i] if (day.mucus.value !== bestQuality) continue - // sensiplan says the three following days must be of lower quality + // the three following days must be of lower quality // AND no best quality day may occur until temperature evaluation has // been completed const threeFollowingDays = mucusDays.slice(i + 1, i + 4) if (threeFollowingDays.length < 3) continue - const bestQualityOccurringIn3FollowingDays = threeFollowingDays.some(day => { + const bestQualityOccursIn3FollowingDays = threeFollowingDays.some(day => { return day.mucus.value >= bestQuality }) - if (bestQualityOccurringIn3FollowingDays) continue + if (bestQualityOccursIn3FollowingDays) continue const cycleDayIndex = cycleDays.indexOf(day) const relevantDays = cycleDays diff --git a/lib/sympto/temperature.js b/lib/sympto/temperature.js index af9028281ba62974749e3b970d63108633b8368e..387cd6378457fda7d98cd633ee3e9a0eb02f88fa 100644 --- a/lib/sympto/temperature.js +++ b/lib/sympto/temperature.js @@ -23,11 +23,11 @@ export default function (cycleDays) { const temp = temperatureDays[i].temp if (temp <= ltl) continue - const checkResult = checkIfFirstHighMeasurement(temp, i, temperatureDays, ltl) + const shift = checkIfFirstHighMeasurement(temp, i, temperatureDays, ltl) - if (checkResult.detected) { - checkResult.firstHighMeasurementDay = temperatureDays[i].originalCycleDay - return checkResult + if (shift.detected) { + shift.firstHighMeasurementDay = temperatureDays[i].originalCycleDay + return shift } }