possible to get all cycle lengths, which get evaluated in stats
This commit is contained in:
+22
-12
@@ -4,7 +4,7 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
ScrollView
|
ScrollView
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import { LocalDate } from 'js-joda'
|
import { LocalDate, ChronoUnit } from 'js-joda'
|
||||||
import styles from '../styles/index'
|
import styles from '../styles/index'
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
import getPeriodInfo from '../lib/period-length'
|
import getPeriodInfo from '../lib/period-length'
|
||||||
@@ -12,21 +12,20 @@ import getPeriodInfo from '../lib/period-length'
|
|||||||
export default class Stats extends Component {
|
export default class Stats extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
const lastMensStart = cycleModule().getLastMensesStart(
|
const allMensesStarts = cycleModule().getAllMensesStarts()
|
||||||
LocalDate.now().toString()
|
this.test = allMensesStarts
|
||||||
)
|
|
||||||
const completedCycles = cycleModule().getCyclesBefore(lastMensStart)
|
const cycleLengths = getCycleLength(allMensesStarts)
|
||||||
this.numberOfCycles = completedCycles.length
|
this.bla = cycleLengths
|
||||||
// TODO get first days, compare with joda
|
this.numberOfCycles = cycleLengths.length
|
||||||
const periodLengths = completedCycles.map(cycle => {
|
this.periodInfo = getPeriodInfo(cycleLengths)
|
||||||
return cycle.length
|
|
||||||
})
|
|
||||||
// until this point
|
|
||||||
this.periodInfo = getPeriodInfo(periodLengths)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
console.log('...............')
|
||||||
|
console.log(this.test)
|
||||||
|
console.log(this.bla)
|
||||||
return (
|
return (
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<Text style={styles.welcome}>based on {this.numberOfCycles} periods:</Text>
|
<Text style={styles.welcome}>based on {this.numberOfCycles} periods:</Text>
|
||||||
@@ -38,4 +37,15 @@ export default class Stats extends Component {
|
|||||||
</ScrollView>
|
</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()
|
||||||
}
|
}
|
||||||
+19
-2
@@ -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 {
|
return {
|
||||||
getCycleDayNumber,
|
getCycleDayNumber,
|
||||||
getCycleForDay,
|
getCycleForDay,
|
||||||
getPreviousCycle,
|
getPreviousCycle,
|
||||||
getCyclesBefore,
|
getLastMensesStart,
|
||||||
getLastMensesStart
|
getAllMensesStarts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user