diff --git a/components/cycle-day.js b/components/cycle-day.js index aafb0996ef34d5f73e6721e3b219431657d638a8..194b1456807250942a8dee52cbad5ccc78aba0d3 100644 --- a/components/cycle-day.js +++ b/components/cycle-day.js @@ -4,7 +4,7 @@ import { Text } from 'react-native' import cycleModule from '../lib/cycle' -import { getTemperatureFertilityStatus } from '../lib/sympto-adapter' +import getFertilityStatus from '../lib/sympto-adapter' import DayView from './cycle-day-overview' import BleedingEditView from './bleeding' import TemperatureEditView from './temperature' @@ -29,7 +29,7 @@ export default class Day extends Component { render() { const cycleDayNumber = getCycleDayNumber(this.cycleDay.date) - const temperatureFertilityStatus = getTemperatureFertilityStatus(this.cycleDay.date) + const fertilityStatus = getFertilityStatus(this.cycleDay.date) return ( <View style={ styles.cycleDayOuterView }> <View style={ styles.cycleDayDateView }> @@ -38,8 +38,15 @@ export default class Day extends Component { </Text> </View > <View style={ styles.cycleDayNumberView }> - { cycleDayNumber && <Text style={styles.cycleDayNumber} >Cycle day {cycleDayNumber}</Text> } - { cycleDayNumber && <Text style={styles.cycleDayNumber} >Temperature status: {temperatureFertilityStatus}</Text> } + { cycleDayNumber && + <Text style={styles.cycleDayNumber} > + Cycle day {cycleDayNumber} + </Text> } + + { cycleDayNumber && + <Text style={styles.cycleDayNumber} > + {fertilityStatus} + </Text> } </View > <View style={ styles.cycleDaySymptomsView }> { diff --git a/lib/cycle.js b/lib/cycle.js index ec334276c980fb1cdbdaca2f36e6ed3fb08dee31..15fca1584ba79cea60640462fbead419715aa58d 100644 --- a/lib/cycle.js +++ b/lib/cycle.js @@ -4,16 +4,20 @@ const LocalDate = joda.LocalDate export default function config(opts) { let bleedingDaysSortedByDate let temperatureDaysSortedByDate + let cycleDaysSortedByDate let maxBreakInBleeding if (!opts) { - // we only want to require (and run) the db module when not running the tests + // we only want to require (and run) the db module + // when not running the tests bleedingDaysSortedByDate = require('../db').bleedingDaysSortedByDate temperatureDaysSortedByDate = require('../db').temperatureDaysSortedByDate + cycleDaysSortedByDate = require('../db').cycleDaysSortedByDate maxBreakInBleeding = 1 } else { bleedingDaysSortedByDate = opts.bleedingDaysSortedByDate || [] temperatureDaysSortedByDate = opts.temperatureDaysSortedByDate || [] + cycleDaysSortedByDate = opts.cycleDaysSortedByDate || [] maxBreakInBleeding = opts.maxBreakInBleeding || 1 } @@ -67,9 +71,17 @@ export default function config(opts) { .map(day => day.temperature.value) } + function getCycleDaysBeforeDay(targetDateString) { + const firstCycleDay = getLastMensesStart(targetDateString) + return cycleDaysSortedByDate.filter(({date}) => { + return date >= firstCycleDay.date && date <= targetDateString + }) + } + return { getCycleDayNumber, getLastMensesStart, - getPreviousTemperaturesInCycle + getPreviousTemperaturesInCycle, + getCycleDaysBeforeDay } } diff --git a/lib/sympto-adapter.js b/lib/sympto-adapter.js index d2f1ffb08df10da152d8c32b9bb0c8166fac906f..e9e384d78ab2b8fc138f173225e7db63cb144ae5 100644 --- a/lib/sympto-adapter.js +++ b/lib/sympto-adapter.js @@ -1,29 +1,18 @@ -import getTemperatureStatus from './sympto/temperature' +import getFertilityStatus from './sympto' import cycleModule from './cycle' -const getLastMensesStart = cycleModule().getLastMensesStart -const getPreviousTemperaturesInCycle = cycleModule().getPreviousTemperaturesInCycle +const { getCycleDaysBeforeDay } = cycleModule() + +export default function (dateString) { + // we get earliest last, but sympto wants earliest first + const cycle = getCycleDaysBeforeDay(dateString).reverse() + // const previousCycles = getPreviousCycles() + const status = getFertilityStatus({cycle}) -function getTemperatureFertilityStatus(targetDateString) { - const lastMensesStart = getLastMensesStart(targetDateString) - if (!lastMensesStart) return formatStatusForApp({ detected: false }) - const previousTemperaturesInCycle = getPreviousTemperaturesInCycle(targetDateString, lastMensesStart) - // we get temps with latest first, but sympto module expects latest last - previousTemperaturesInCycle.reverse() - const status = getTemperatureStatus(previousTemperaturesInCycle) return formatStatusForApp(status) } function formatStatusForApp(status) { - if (!status.detected) return 'fertile' - const dict = [ - "regular temperature", - "first exception", - "second exception" - ] - return `infertile according to the ${dict[status.rule]} rule` -} - -export { - getTemperatureFertilityStatus + const fertileStatus = status.assumeFertility ? 'fertile' : 'infertile' + return `You are currently ${fertileStatus}` } \ No newline at end of file