Hook up fertility temp status to app
This commit is contained in:
@@ -14,8 +14,6 @@ const getCycleDayNumber = cycleModule().getCycleDayNumber
|
|||||||
export default class DayView extends Component {
|
export default class DayView extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
console.log('new')
|
|
||||||
console.log(props.cycleDay)
|
|
||||||
this.cycleDay = props.cycleDay
|
this.cycleDay = props.cycleDay
|
||||||
this.showView = props.showView
|
this.showView = props.showView
|
||||||
this.state = {
|
this.state = {
|
||||||
|
|||||||
@@ -4,6 +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/sensiplan-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'
|
||||||
@@ -28,6 +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)
|
||||||
return (
|
return (
|
||||||
<View style={ styles.cycleDayOuterView }>
|
<View style={ styles.cycleDayOuterView }>
|
||||||
<View style={ styles.cycleDayDateView }>
|
<View style={ styles.cycleDayDateView }>
|
||||||
@@ -37,6 +39,7 @@ export default class Day extends Component {
|
|||||||
</View >
|
</View >
|
||||||
<View style={ styles.cycleDayNumberView }>
|
<View style={ styles.cycleDayNumberView }>
|
||||||
{ cycleDayNumber && <Text style={styles.cycleDayNumber} >Cycle day {cycleDayNumber}</Text> }
|
{ cycleDayNumber && <Text style={styles.cycleDayNumber} >Cycle day {cycleDayNumber}</Text> }
|
||||||
|
{ cycleDayNumber && <Text style={styles.cycleDayNumber} >Temperature status: {temperatureFertilityStatus}</Text> }
|
||||||
</View >
|
</View >
|
||||||
<View style={ styles.cycleDaySymptomsView }>
|
<View style={ styles.cycleDaySymptomsView }>
|
||||||
{
|
{
|
||||||
|
|||||||
+18
-8
@@ -1,16 +1,21 @@
|
|||||||
import * as joda from 'js-joda'
|
import * as joda from 'js-joda'
|
||||||
|
|
||||||
const LocalDate = joda.LocalDate
|
const LocalDate = joda.LocalDate
|
||||||
|
|
||||||
export default function config(opts = {}) {
|
export default function config(opts) {
|
||||||
let bleedingDaysSortedByDate
|
let bleedingDaysSortedByDate
|
||||||
if (!opts.bleedingDaysSortedByDate) {
|
let temperatureDaysSortedByDate
|
||||||
|
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
|
bleedingDaysSortedByDate = require('../db').bleedingDaysSortedByDate
|
||||||
|
temperatureDaysSortedByDate = require('../db').temperatureDaysSortedByDate
|
||||||
|
maxBreakInBleeding = 1
|
||||||
} else {
|
} else {
|
||||||
bleedingDaysSortedByDate = opts.bleedingDaysSortedByDate
|
bleedingDaysSortedByDate = opts.bleedingDaysSortedByDate || []
|
||||||
|
temperatureDaysSortedByDate = opts.temperatureDaysSortedByDate || []
|
||||||
|
maxBreakInBleeding = opts.maxBreakInBleeding || 1
|
||||||
}
|
}
|
||||||
const maxBreakInBleeding = opts.maxBreakInBleeding || 1
|
|
||||||
|
|
||||||
function getLastMensesStart(targetDateString) {
|
function getLastMensesStart(targetDateString) {
|
||||||
const targetDate = LocalDate.parse(targetDateString)
|
const targetDate = LocalDate.parse(targetDateString)
|
||||||
@@ -53,13 +58,18 @@ export default function config(opts = {}) {
|
|||||||
return diffInDays + 1
|
return diffInDays + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPreviousDaysInCycle() {
|
function getPreviousTemperaturesInCycle(targetDateString, lastMensesStart) {
|
||||||
return []
|
const startIndex = temperatureDaysSortedByDate.findIndex(day => day.date <= targetDateString)
|
||||||
|
const previousTemperaturesInCycle = temperatureDaysSortedByDate.slice(startIndex)
|
||||||
|
const endIndex = previousTemperaturesInCycle.findIndex(day => day.date < lastMensesStart.date)
|
||||||
|
return previousTemperaturesInCycle
|
||||||
|
.slice(0, endIndex)
|
||||||
|
.map(day => day.temperature.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getCycleDayNumber,
|
getCycleDayNumber,
|
||||||
getLastMensesStart,
|
getLastMensesStart,
|
||||||
getPreviousDaysInCycle
|
getPreviousTemperaturesInCycle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { detectTemperatureShift } from './sensiplan'
|
||||||
|
import cycleModule from './cycle'
|
||||||
|
|
||||||
|
const getLastMensesStart = cycleModule().getLastMensesStart
|
||||||
|
const getPreviousTemperaturesInCycle = cycleModule().getPreviousTemperaturesInCycle
|
||||||
|
|
||||||
|
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 sensiplan module expects latest last
|
||||||
|
previousTemperaturesInCycle.reverse()
|
||||||
|
const status = detectTemperatureShift(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
|
||||||
|
}
|
||||||
+4
-10
@@ -31,7 +31,7 @@ function detectTemperatureShift(temperaturesOfCycle) {
|
|||||||
// 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
|
||||||
acc.detected = true
|
acc.detected = true
|
||||||
acc.high = [temp]
|
acc.high = [temp]
|
||||||
acc.rules = checkResult.rules
|
acc.rule = checkResult.rule
|
||||||
acc.ltl = ltl
|
acc.ltl = ltl
|
||||||
acc.low = getSixTempsBefore(i)
|
acc.low = getSixTempsBefore(i)
|
||||||
|
|
||||||
@@ -57,9 +57,7 @@ function checkIfFirstHighMeasurement(temp, i, temps, ltl) {
|
|||||||
if (regularRuleApplies(temp, nextTemps, ltl)) {
|
if (regularRuleApplies(temp, nextTemps, ltl)) {
|
||||||
return {
|
return {
|
||||||
isFirstHighMeasurement: true,
|
isFirstHighMeasurement: true,
|
||||||
rules: {
|
rule: 0,
|
||||||
regular: true,
|
|
||||||
},
|
|
||||||
ltl
|
ltl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,9 +65,7 @@ function checkIfFirstHighMeasurement(temp, i, temps, ltl) {
|
|||||||
if (firstExceptionRuleApplies(temp, nextTemps, ltl)) {
|
if (firstExceptionRuleApplies(temp, nextTemps, ltl)) {
|
||||||
return {
|
return {
|
||||||
isFirstHighMeasurement: true,
|
isFirstHighMeasurement: true,
|
||||||
rules: {
|
rule: 1,
|
||||||
firstException: true,
|
|
||||||
},
|
|
||||||
ltl
|
ltl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,9 +73,7 @@ function checkIfFirstHighMeasurement(temp, i, temps, ltl) {
|
|||||||
if (secondExceptionRuleApplies(temp, nextTemps, ltl)) {
|
if (secondExceptionRuleApplies(temp, nextTemps, ltl)) {
|
||||||
return {
|
return {
|
||||||
isFirstHighMeasurement: true,
|
isFirstHighMeasurement: true,
|
||||||
rules: {
|
rule: 2,
|
||||||
secondException: true,
|
|
||||||
},
|
|
||||||
ltl
|
ltl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-5
@@ -14,14 +14,13 @@ export default StyleSheet.create({
|
|||||||
dateHeader: {
|
dateHeader: {
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
margin: 30,
|
margin: 20,
|
||||||
color: 'white',
|
color: 'white',
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
textAlignVertical: 'center'
|
textAlignVertical: 'center'
|
||||||
},
|
},
|
||||||
cycleDayNumber: {
|
cycleDayNumber: {
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
margin: 20,
|
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
textAlignVertical: 'center'
|
textAlignVertical: 'center'
|
||||||
},
|
},
|
||||||
@@ -77,14 +76,13 @@ export default StyleSheet.create({
|
|||||||
justifyContent: 'space-around'
|
justifyContent: 'space-around'
|
||||||
},
|
},
|
||||||
cycleDayDateView: {
|
cycleDayDateView: {
|
||||||
flex: 2,
|
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
backgroundColor: 'steelblue'
|
backgroundColor: 'steelblue'
|
||||||
},
|
},
|
||||||
cycleDayNumberView: {
|
cycleDayNumberView: {
|
||||||
flex: 1,
|
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
backgroundColor: 'skyblue'
|
backgroundColor: 'skyblue',
|
||||||
|
padding: 10
|
||||||
},
|
},
|
||||||
cycleDaySymptomsView: {
|
cycleDaySymptomsView: {
|
||||||
flex: 8,
|
flex: 8,
|
||||||
|
|||||||
Reference in New Issue
Block a user