Use new smpto module in day view
This commit is contained in:
+11
-4
@@ -4,7 +4,7 @@ import {
|
|||||||
Text
|
Text
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
import { getTemperatureFertilityStatus } from '../lib/sympto-adapter'
|
import getFertilityStatus from '../lib/sympto-adapter'
|
||||||
import DayView from './cycle-day-overview'
|
import DayView from './cycle-day-overview'
|
||||||
import BleedingEditView from './bleeding'
|
import BleedingEditView from './bleeding'
|
||||||
import TemperatureEditView from './temperature'
|
import TemperatureEditView from './temperature'
|
||||||
@@ -29,7 +29,7 @@ export default class Day extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const cycleDayNumber = getCycleDayNumber(this.cycleDay.date)
|
const cycleDayNumber = getCycleDayNumber(this.cycleDay.date)
|
||||||
const temperatureFertilityStatus = getTemperatureFertilityStatus(this.cycleDay.date)
|
const fertilityStatus = getFertilityStatus(this.cycleDay.date)
|
||||||
return (
|
return (
|
||||||
<View style={ styles.cycleDayOuterView }>
|
<View style={ styles.cycleDayOuterView }>
|
||||||
<View style={ styles.cycleDayDateView }>
|
<View style={ styles.cycleDayDateView }>
|
||||||
@@ -38,8 +38,15 @@ export default class Day extends Component {
|
|||||||
</Text>
|
</Text>
|
||||||
</View >
|
</View >
|
||||||
<View style={ styles.cycleDayNumberView }>
|
<View style={ styles.cycleDayNumberView }>
|
||||||
{ cycleDayNumber && <Text style={styles.cycleDayNumber} >Cycle day {cycleDayNumber}</Text> }
|
{ cycleDayNumber &&
|
||||||
{ cycleDayNumber && <Text style={styles.cycleDayNumber} >Temperature status: {temperatureFertilityStatus}</Text> }
|
<Text style={styles.cycleDayNumber} >
|
||||||
|
Cycle day {cycleDayNumber}
|
||||||
|
</Text> }
|
||||||
|
|
||||||
|
{ cycleDayNumber &&
|
||||||
|
<Text style={styles.cycleDayNumber} >
|
||||||
|
{fertilityStatus}
|
||||||
|
</Text> }
|
||||||
</View >
|
</View >
|
||||||
<View style={ styles.cycleDaySymptomsView }>
|
<View style={ styles.cycleDaySymptomsView }>
|
||||||
{
|
{
|
||||||
|
|||||||
+14
-2
@@ -4,16 +4,20 @@ const LocalDate = joda.LocalDate
|
|||||||
export default function config(opts) {
|
export default function config(opts) {
|
||||||
let bleedingDaysSortedByDate
|
let bleedingDaysSortedByDate
|
||||||
let temperatureDaysSortedByDate
|
let temperatureDaysSortedByDate
|
||||||
|
let cycleDaysSortedByDate
|
||||||
let maxBreakInBleeding
|
let maxBreakInBleeding
|
||||||
|
|
||||||
if (!opts) {
|
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
|
bleedingDaysSortedByDate = require('../db').bleedingDaysSortedByDate
|
||||||
temperatureDaysSortedByDate = require('../db').temperatureDaysSortedByDate
|
temperatureDaysSortedByDate = require('../db').temperatureDaysSortedByDate
|
||||||
|
cycleDaysSortedByDate = require('../db').cycleDaysSortedByDate
|
||||||
maxBreakInBleeding = 1
|
maxBreakInBleeding = 1
|
||||||
} else {
|
} else {
|
||||||
bleedingDaysSortedByDate = opts.bleedingDaysSortedByDate || []
|
bleedingDaysSortedByDate = opts.bleedingDaysSortedByDate || []
|
||||||
temperatureDaysSortedByDate = opts.temperatureDaysSortedByDate || []
|
temperatureDaysSortedByDate = opts.temperatureDaysSortedByDate || []
|
||||||
|
cycleDaysSortedByDate = opts.cycleDaysSortedByDate || []
|
||||||
maxBreakInBleeding = opts.maxBreakInBleeding || 1
|
maxBreakInBleeding = opts.maxBreakInBleeding || 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,9 +71,17 @@ export default function config(opts) {
|
|||||||
.map(day => day.temperature.value)
|
.map(day => day.temperature.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCycleDaysBeforeDay(targetDateString) {
|
||||||
|
const firstCycleDay = getLastMensesStart(targetDateString)
|
||||||
|
return cycleDaysSortedByDate.filter(({date}) => {
|
||||||
|
return date >= firstCycleDay.date && date <= targetDateString
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getCycleDayNumber,
|
getCycleDayNumber,
|
||||||
getLastMensesStart,
|
getLastMensesStart,
|
||||||
getPreviousTemperaturesInCycle
|
getPreviousTemperaturesInCycle,
|
||||||
|
getCycleDaysBeforeDay
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-21
@@ -1,29 +1,18 @@
|
|||||||
import getTemperatureStatus from './sympto/temperature'
|
import getFertilityStatus from './sympto'
|
||||||
import cycleModule from './cycle'
|
import cycleModule from './cycle'
|
||||||
|
|
||||||
const getLastMensesStart = cycleModule().getLastMensesStart
|
const { getCycleDaysBeforeDay } = cycleModule()
|
||||||
const getPreviousTemperaturesInCycle = cycleModule().getPreviousTemperaturesInCycle
|
|
||||||
|
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)
|
return formatStatusForApp(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatStatusForApp(status) {
|
function formatStatusForApp(status) {
|
||||||
if (!status.detected) return 'fertile'
|
const fertileStatus = status.assumeFertility ? 'fertile' : 'infertile'
|
||||||
const dict = [
|
return `You are currently ${fertileStatus}`
|
||||||
"regular temperature",
|
|
||||||
"first exception",
|
|
||||||
"second exception"
|
|
||||||
]
|
|
||||||
return `infertile according to the ${dict[status.rule]} rule`
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
getTemperatureFertilityStatus
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user