Skip to content
Snippets Groups Projects
Commit 1c791df5 authored by Julia Friesel's avatar Julia Friesel
Browse files

Hook up fertility temp status to app

parent 03a0f1fb
No related branches found
No related tags found
No related merge requests found
......@@ -14,8 +14,6 @@ const getCycleDayNumber = cycleModule().getCycleDayNumber
export default class DayView extends Component {
constructor(props) {
super(props)
console.log('new')
console.log(props.cycleDay)
this.cycleDay = props.cycleDay
this.showView = props.showView
this.state = {
......
......@@ -4,6 +4,7 @@ import {
Text
} from 'react-native'
import cycleModule from '../lib/cycle'
import { getTemperatureFertilityStatus } from '../lib/sensiplan-adapter'
import DayView from './cycle-day-overview'
import BleedingEditView from './bleeding'
import TemperatureEditView from './temperature'
......@@ -28,6 +29,7 @@ export default class Day extends Component {
render() {
const cycleDayNumber = getCycleDayNumber(this.cycleDay.date)
const temperatureFertilityStatus = getTemperatureFertilityStatus(this.cycleDay.date)
return (
<View style={ styles.cycleDayOuterView }>
<View style={ styles.cycleDayDateView }>
......@@ -37,6 +39,7 @@ export default class Day extends Component {
</View >
<View style={ styles.cycleDayNumberView }>
{ cycleDayNumber && <Text style={styles.cycleDayNumber} >Cycle day {cycleDayNumber}</Text> }
{ cycleDayNumber && <Text style={styles.cycleDayNumber} >Temperature status: {temperatureFertilityStatus}</Text> }
</View >
<View style={ styles.cycleDaySymptomsView }>
{
......
import * as joda from 'js-joda'
const LocalDate = joda.LocalDate
export default function config(opts = {}) {
export default function config(opts) {
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
bleedingDaysSortedByDate = require('../db').bleedingDaysSortedByDate
temperatureDaysSortedByDate = require('../db').temperatureDaysSortedByDate
maxBreakInBleeding = 1
} else {
bleedingDaysSortedByDate = opts.bleedingDaysSortedByDate
bleedingDaysSortedByDate = opts.bleedingDaysSortedByDate || []
temperatureDaysSortedByDate = opts.temperatureDaysSortedByDate || []
maxBreakInBleeding = opts.maxBreakInBleeding || 1
}
const maxBreakInBleeding = opts.maxBreakInBleeding || 1
function getLastMensesStart(targetDateString) {
const targetDate = LocalDate.parse(targetDateString)
......@@ -53,13 +58,18 @@ export default function config(opts = {}) {
return diffInDays + 1
}
function getPreviousDaysInCycle() {
return []
function getPreviousTemperaturesInCycle(targetDateString, lastMensesStart) {
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 {
getCycleDayNumber,
getLastMensesStart,
getPreviousDaysInCycle
getPreviousTemperaturesInCycle
}
}
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
}
\ No newline at end of file
......@@ -31,7 +31,7 @@ function detectTemperatureShift(temperaturesOfCycle) {
// if we do, remember the details and start collecting the high level temps
acc.detected = true
acc.high = [temp]
acc.rules = checkResult.rules
acc.rule = checkResult.rule
acc.ltl = ltl
acc.low = getSixTempsBefore(i)
......@@ -57,9 +57,7 @@ function checkIfFirstHighMeasurement(temp, i, temps, ltl) {
if (regularRuleApplies(temp, nextTemps, ltl)) {
return {
isFirstHighMeasurement: true,
rules: {
regular: true,
},
rule: 0,
ltl
}
}
......@@ -67,9 +65,7 @@ function checkIfFirstHighMeasurement(temp, i, temps, ltl) {
if (firstExceptionRuleApplies(temp, nextTemps, ltl)) {
return {
isFirstHighMeasurement: true,
rules: {
firstException: true,
},
rule: 1,
ltl
}
}
......@@ -77,9 +73,7 @@ function checkIfFirstHighMeasurement(temp, i, temps, ltl) {
if (secondExceptionRuleApplies(temp, nextTemps, ltl)) {
return {
isFirstHighMeasurement: true,
rules: {
secondException: true,
},
rule: 2,
ltl
}
}
......
......@@ -14,14 +14,13 @@ export default StyleSheet.create({
dateHeader: {
fontSize: 20,
fontWeight: 'bold',
margin: 30,
margin: 20,
color: 'white',
textAlign: 'center',
textAlignVertical: 'center'
},
cycleDayNumber: {
fontSize: 18,
margin: 20,
textAlign: 'center',
textAlignVertical: 'center'
},
......@@ -77,14 +76,13 @@ export default StyleSheet.create({
justifyContent: 'space-around'
},
cycleDayDateView: {
flex: 2,
justifyContent: 'center',
backgroundColor: 'steelblue'
},
cycleDayNumberView: {
flex: 1,
justifyContent: 'center',
backgroundColor: 'skyblue'
backgroundColor: 'skyblue',
padding: 10
},
cycleDaySymptomsView: {
flex: 8,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment