Skip to content
Snippets Groups Projects
Commit 6135c922 authored by tina's avatar tina
Browse files

possible to get all cycle lengths, which get evaluated in stats

parent 897e99e6
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ import {
Text,
ScrollView
} from 'react-native'
import { LocalDate } from 'js-joda'
import { LocalDate, ChronoUnit } from 'js-joda'
import styles from '../styles/index'
import cycleModule from '../lib/cycle'
import getPeriodInfo from '../lib/period-length'
......@@ -12,21 +12,20 @@ import getPeriodInfo from '../lib/period-length'
export default class Stats extends Component {
constructor(props) {
super(props)
const lastMensStart = cycleModule().getLastMensesStart(
LocalDate.now().toString()
)
const completedCycles = cycleModule().getCyclesBefore(lastMensStart)
this.numberOfCycles = completedCycles.length
// TODO get first days, compare with joda
const periodLengths = completedCycles.map(cycle => {
return cycle.length
})
// until this point
this.periodInfo = getPeriodInfo(periodLengths)
const allMensesStarts = cycleModule().getAllMensesStarts()
this.test = allMensesStarts
const cycleLengths = getCycleLength(allMensesStarts)
this.bla = cycleLengths
this.numberOfCycles = cycleLengths.length
this.periodInfo = getPeriodInfo(cycleLengths)
}
render() {
console.log('...............')
console.log(this.test)
console.log(this.bla)
return (
<ScrollView>
<Text style={styles.welcome}>based on {this.numberOfCycles} periods:</Text>
......@@ -38,4 +37,15 @@ export default class Stats extends Component {
</ScrollView>
)
}
}
function getCycleLength(cycleStartDates) {
const cycleStartDatesReverse = cycleStartDates.reverse()
const periodLengths = []
for (let i = 0; i < cycleStartDates.length - 1; i++) {
const periodStart = LocalDate.parse(cycleStartDatesReverse[i])
const periodEnd = LocalDate.parse(cycleStartDatesReverse[i + 1])
periodLengths.unshift(periodStart.until(periodEnd, ChronoUnit.DAYS))
}
return periodLengths.reverse()
}
\ No newline at end of file
......@@ -130,11 +130,28 @@ export default function config(opts) {
}
}
function getAllMensesStarts(day, collectedDates) {
day = day || LocalDate.now().toString()
collectedDates = collectedDates || []
if (!day) {
return null
} else {
const lastStart = getLastMensesStart(day)
if (!lastStart) {
return collectedDates
} else {
const newDay = LocalDate.parse(lastStart.date).minusDays(1).toString()
collectedDates.push(lastStart.date)
return getAllMensesStarts(newDay, collectedDates)
}
}
}
return {
getCycleDayNumber,
getCycleForDay,
getPreviousCycle,
getCyclesBefore,
getLastMensesStart
getLastMensesStart,
getAllMensesStarts
}
}
\ 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