diff --git a/components/cycle-day-overview.js b/components/cycle-day-overview.js index f8c3acaef232b03ce00a88b495b7d32a57b41a68..49068fea332eb2aa53c775005442da31934e4734 100644 --- a/components/cycle-day-overview.js +++ b/components/cycle-day-overview.js @@ -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 = { diff --git a/components/cycle-day.js b/components/cycle-day.js index 2d782202327f596293491fd885863f9c0cb04ad6..5b54b2f98eb7a6e2c8020b23e336fbc7513d7611 100644 --- a/components/cycle-day.js +++ b/components/cycle-day.js @@ -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 }> { diff --git a/lib/cycle.js b/lib/cycle.js index 8dbe838ccd5cfad8542dbbdd1a3f305214d44aef..ec334276c980fb1cdbdaca2f36e6ed3fb08dee31 100644 --- a/lib/cycle.js +++ b/lib/cycle.js @@ -1,16 +1,21 @@ 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 } } diff --git a/lib/sensiplan-adapter.js b/lib/sensiplan-adapter.js new file mode 100644 index 0000000000000000000000000000000000000000..7ae60b312b25ccbeeec3ab4e2338b124ab2ffff3 --- /dev/null +++ b/lib/sensiplan-adapter.js @@ -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 +} \ No newline at end of file diff --git a/lib/sensiplan.js b/lib/sensiplan.js index ed369532d127cabf6b734ec36560558b2b16ce0c..3f66c47d38d4cc8ab3dfec5948a4c6063aa3daa6 100644 --- a/lib/sensiplan.js +++ b/lib/sensiplan.js @@ -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 } } diff --git a/styles/index.js b/styles/index.js index 5eb9cc18d02c1e9eee813bb20db5a791981b3f34..204e13256c3a885de08d117ff81d0b05c81f4980 100644 --- a/styles/index.js +++ b/styles/index.js @@ -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,