Refactor getStatusAsString
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
||||
Text
|
||||
} from 'react-native'
|
||||
import cycleModule from '../../lib/cycle'
|
||||
import getFertilityStatus from '../../lib/sympto-adapter'
|
||||
import { getFertilityStatusStringForDay } from '../../lib/sympto-adapter'
|
||||
import DayView from './cycle-day-overview'
|
||||
import BleedingEditView from './symptoms/bleeding'
|
||||
import TemperatureEditView from './symptoms/temperature'
|
||||
@@ -33,7 +33,7 @@ export default class Day extends Component {
|
||||
|
||||
render() {
|
||||
const cycleDayNumber = getCycleDayNumber(this.cycleDay.date)
|
||||
const fertilityStatus = getFertilityStatus(this.cycleDay.date)
|
||||
const fertilityStatus = getFertilityStatusStringForDay(this.cycleDay.date)
|
||||
return (
|
||||
<View>
|
||||
<View style={ styles.cycleDayDateView }>
|
||||
|
||||
@@ -94,7 +94,7 @@ export default class Mucus extends Component {
|
||||
saveSymptom('mucus', this.cycleDay, {
|
||||
feeling: this.state.currentFeelingValue,
|
||||
texture: this.state.currentTextureValue,
|
||||
computedNfp: computeSensiplanValue(this.state.currentFeelingValue, this.state.currentTextureValue),
|
||||
value: computeSensiplanValue(this.state.currentFeelingValue, this.state.currentTextureValue),
|
||||
exclude: this.state.exclude
|
||||
})
|
||||
},
|
||||
|
||||
+44
-16
@@ -2,31 +2,59 @@ import getFertilityStatus from './sympto'
|
||||
import cycleModule from './cycle'
|
||||
import { fertilityStatus } from '../labels/labels'
|
||||
|
||||
const { getCycleDaysBeforeDay, getPreviousCycles } = cycleModule()
|
||||
const {
|
||||
getCycleForDay,
|
||||
getCyclesBefore,
|
||||
getPreviousCycle
|
||||
} = cycleModule()
|
||||
|
||||
export default function (dateString) {
|
||||
const cycle = getCycleDaysBeforeDay(dateString)
|
||||
export function getFertilityStatusStringForDay(dateString) {
|
||||
const cycle = getCycleForDay(dateString)
|
||||
if (!cycle) return fertilityStatus.unknown
|
||||
|
||||
const previousCycles = getPreviousCycles(cycle[0])
|
||||
const cycleInfo = {cycle: formatCycleForSympto(cycle)}
|
||||
|
||||
const status = getFertilityStatus({
|
||||
cycle: formatCycleForSympto(cycle),
|
||||
previousCycles: previousCycles.map(formatCycleForSympto)
|
||||
})
|
||||
const previousCycle = getPreviousCycle(dateString)
|
||||
|
||||
if (status.phases.postOvulatory) {
|
||||
const phase = status.phases.postOvulatory
|
||||
if (phase.start.date === dateString) {
|
||||
return fertilityStatus.fertileUntilEvening
|
||||
if (previousCycle) {
|
||||
cycleInfo.previousCycle = formatCycleForSympto(previousCycle)
|
||||
const earlierCycles = getCyclesBefore(previousCycle[0])
|
||||
if (earlierCycles) {
|
||||
cycleInfo.earlierCycles = earlierCycles.map(formatCycleForSympto)
|
||||
}
|
||||
}
|
||||
|
||||
if (status.assumeFertility) {
|
||||
return fertilityStatus.fertile
|
||||
} else {
|
||||
return fertilityStatus.infertile
|
||||
const status = getFertilityStatus(cycleInfo)
|
||||
|
||||
const phaseNameForDay = Object.keys(status.phases).find(phaseName => {
|
||||
const phase = status.phases[phaseName]
|
||||
const dayIsAfterPhaseStart = dateString >= phase.start.date
|
||||
let dayIsBeforePhaseEnd
|
||||
if (phase.end) {
|
||||
dayIsBeforePhaseEnd = dateString <= phase.end.date
|
||||
} else {
|
||||
dayIsBeforePhaseEnd = true
|
||||
}
|
||||
return dayIsAfterPhaseStart && dayIsBeforePhaseEnd
|
||||
})
|
||||
|
||||
return mapToString(phaseNameForDay, dateString, status)
|
||||
}
|
||||
|
||||
function mapToString(phaseNameForDay, dateString, status) {
|
||||
const mapping = {
|
||||
preOvulatory: () => fertilityStatus.infertile,
|
||||
periOvulatory: (dateString, status) => {
|
||||
const phaseEnd = status.phases.periOvulatory.end
|
||||
if (phaseEnd && phaseEnd.date === dateString) {
|
||||
return fertilityStatus.fertileUntilEvening
|
||||
}
|
||||
return fertilityStatus.fertile
|
||||
},
|
||||
postOvulatory: () => fertilityStatus.infertile
|
||||
}
|
||||
|
||||
return mapping[phaseNameForDay](dateString, status)
|
||||
}
|
||||
|
||||
function formatCycleForSympto(cycle) {
|
||||
|
||||
Reference in New Issue
Block a user