import React, { Component } from 'react' import { View, Text, ScrollView } from 'react-native' import { LocalDate, ChronoUnit } from 'js-joda' import styles from '../styles/index' import cycleModule from '../lib/cycle' import getPeriodInfo from '../lib/period-length' export default class Stats extends Component { constructor(props) { super(props) 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 ( based on {this.numberOfCycles} periods: min: {this.periodInfo.minimum} mean: {this.periodInfo.mean} max: {this.periodInfo.maximum} median: {this.periodInfo.median} standard deviation: {this.periodInfo.stdDeviation} ) } } 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() }