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

Get previous cycles before detecting fertility status

parent 8a8b1310
No related branches found
No related tags found
No related merge requests found
......@@ -43,10 +43,9 @@ export default class Day extends Component {
Cycle day {cycleDayNumber}
</Text> }
{ cycleDayNumber &&
<Text style={styles.cycleDayNumber} >
{fertilityStatus}
</Text> }
</Text>
</View >
<View style={ styles.cycleDaySymptomsView }>
{
......
import * as joda from 'js-joda'
const LocalDate = joda.LocalDate
export default function config(opts) {
......@@ -49,14 +50,16 @@ export default function config(opts) {
return !previousBleedingDays.some(({ wrappedDate }) => wrappedDate.equals(periodThreshold) || wrappedDate.isAfter(periodThreshold))
}
withWrappedDates.forEach(day => delete day.wrappedDate)
return lastPeriodStart
}
function getCycleDayNumber(targetDateString) {
const lastMensesStart = getLastMensesStart(targetDateString)
if (!lastMensesStart) return null
const targetDate = joda.LocalDate.parse(targetDateString)
const diffInDays = lastMensesStart.wrappedDate.until(targetDate, joda.ChronoUnit.DAYS)
const targetDate = LocalDate.parse(targetDateString)
const lastMensesLocalDate = LocalDate.parse(lastMensesStart.date)
const diffInDays = lastMensesLocalDate.until(targetDate, joda.ChronoUnit.DAYS)
// cycle starts at day 1
return diffInDays + 1
......@@ -73,15 +76,36 @@ export default function config(opts) {
function getCycleDaysBeforeDay(targetDateString) {
const firstCycleDay = getLastMensesStart(targetDateString)
if (!firstCycleDay) return null
return cycleDaysSortedByDate.filter(({date}) => {
return date >= firstCycleDay.date && date <= targetDateString
})
}
function getPreviousCycles(targetCycleStartDay) {
let previousCycleStartIndex = cycleDaysSortedByDate.indexOf(targetCycleStartDay)
const cycles = []
while (previousCycleStartIndex < cycleDaysSortedByDate.length - 1) {
const prevDate = cycleDaysSortedByDate[previousCycleStartIndex + 1].date
const cycleStart = getLastMensesStart(prevDate)
if (!cycleStart) break
const cycleStartIndex = cycleDaysSortedByDate.indexOf(cycleStart)
const lastDayInCycle = previousCycleStartIndex + 1
const cycle = cycleDaysSortedByDate.slice(lastDayInCycle, cycleStartIndex + 1)
cycles.push(cycle)
previousCycleStartIndex = cycleStartIndex
}
return cycles
}
return {
getCycleDayNumber,
getLastMensesStart,
getPreviousTemperaturesInCycle,
getCycleDaysBeforeDay
getCycleDaysBeforeDay,
getPreviousCycles
}
}
import getFertilityStatus from './sympto'
import cycleModule from './cycle'
const { getCycleDaysBeforeDay } = cycleModule()
const { getCycleDaysBeforeDay, getPreviousCycles } = cycleModule()
export default function (dateString) {
const cycle = getCycleDaysBeforeDay(dateString)
if (!cycle) return `We cannot show any cycle information because no menses has been entered`
// we get earliest last, but sympto wants earliest first
const cycle = getCycleDaysBeforeDay(dateString).reverse()
// const previousCycles = getPreviousCycles()
const status = getFertilityStatus({cycle})
cycle.reverse()
const previousCycles = getPreviousCycles(cycle[0])
previousCycles.forEach(cycle => cycle.reverse())
const status = getFertilityStatus({cycle, previousCycles})
return formatStatusForApp(status)
}
function formatStatusForApp(status) {
const fertileStatus = status.assumeFertility ? 'fertile' : 'infertile'
return `You are currently ${fertileStatus}`
return status.assumeFertility ? 'fertile' : 'infertile'
}
\ No newline at end of file
......@@ -23,7 +23,7 @@ describe('getCycleDay', () => {
value: 2
}
}]
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays}).getCycleDayNumber
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const targetDate = '2018-05-17'
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(9)
......@@ -49,7 +49,7 @@ describe('getCycleDay', () => {
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays}).getCycleDayNumber
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(15)
})
......@@ -73,7 +73,7 @@ describe('getCycleDay', () => {
}]
const targetDate = '2018-04-27'
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays}).getCycleDayNumber
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(18)
})
......@@ -87,59 +87,147 @@ describe('getCycleDay', () => {
}]
const targetDate = '2018-05-13'
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays}).getCycleDayNumber
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(1)
})
})
describe('getCycleDay returns null', () => {
it('if there are no bleeding days', function () {
const bleedingDays = []
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays}).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.be.null()
describe('getCycleDay returns null', () => {
it('if there are no bleeding days', function () {
const bleedingDays = []
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.be.null()
})
})
})
describe('getCycleDay with cycle thresholds', () => {
const maxBreakInBleeding = 3
describe('getCycleDay with cycle thresholds', () => {
const maxBreakInBleeding = 3
it('disregards bleeding breaks shorter than max allowed bleeding break in a bleeding period', () => {
const bleedingDays = [{
date: '2018-05-14',
bleeding: {
value: 2
}
}, {
date: '2018-05-10',
bleeding: {
value: 2
}
}]
it('disregards bleeding breaks shorter than max allowed bleeding break in a bleeding period', () => {
const bleedingDays = [{
date: '2018-05-14',
bleeding: {
value: 2
}
}, {
date: '2018-05-10',
bleeding: {
value: 2
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(8)
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(8)
})
it('counts bleeding breaks longer than maxAllowedBleedingBreak in a bleeding period', () => {
const bleedingDays = [{
date: '2018-05-14',
bleeding: {
value: 2
}
}, {
date: '2018-05-09',
bleeding: {
value: 2
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(4)
})
})
})
it('counts bleeding breaks longer than maxAllowedBleedingBreak in a bleeding period', () => {
const bleedingDays = [{
date: '2018-05-14',
bleeding: {
value: 2
}
}, {
date: '2018-05-09',
bleeding: {
value: 2
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(4)
describe('getPreviousCycles', () => {
it('gets previous cycles', () => {
const cycleDaysSortedByDate = [
{
date: '2018-07-05',
bleeding: { value: 2 }
},
{
date: '2018-06-05',
bleeding: { value: 2 }
},
{
date: '2018-05-05',
mucus: { value: 2 }
},
{
date: '2018-05-04',
bleeding: { value: 2 }
},
{
date: '2018-05-03',
bleeding: { value: 2 }
},
{
date: '2018-04-05',
mucus: { value: 2 }
},
{
date: '2018-04-04',
mucus: { value: 2 }
},
{
date: '2018-04-03',
mucus: { value: 2 }
},
{
date: '2018-04-02',
bleeding: { value: 2 }
},
]
const { getPreviousCycles } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
})
const result = getPreviousCycles(cycleDaysSortedByDate[0])
expect(result.length).to.eql(3)
expect(result).to.eql([
[
{
date: '2018-06-05',
bleeding: { value: 2 }
}
], [
{
date: '2018-05-05',
mucus: { value: 2 }
},
{
date: '2018-05-04',
bleeding: { value: 2 }
},
{
date: '2018-05-03',
bleeding: { value: 2 }
}
], [
{
date: '2018-04-05',
mucus: { value: 2 }
},
{
date: '2018-04-04',
mucus: { value: 2 }
},
{
date: '2018-04-03',
mucus: { value: 2 }
},
{
date: '2018-04-02',
bleeding: { value: 2 }
},
]
])
})
})
\ No newline at end of file
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