Skip to content
Snippets Groups Projects
stats.js 2.5 KiB
Newer Older
import React, { Component } from 'react'
import {
import styles from '../styles/index'
import cycleModule from '../lib/cycle'
import {getCycleLengthStats as getCycleInfo} from '../lib/cycle-length'
import {stats as labels} from '../i18n/en/labels'
Julia Friesel's avatar
Julia Friesel committed
import AppText from './app-text'
import FramedSegment from './framed-segment'

export default class Stats extends Component {
  render() {
    const cycleLengths = cycleModule().getAllCycleLengths()
    const atLeastOneCycle = cycleLengths.length >= 1
    let numberOfCycles
    let cycleInfo
    if (atLeastOneCycle) {
      numberOfCycles = cycleLengths.length
      if (numberOfCycles > 1) {
        cycleInfo = getCycleInfo(cycleLengths)
      }
    }
        <FramedSegment
          style={styles.framedSegmentLast}
          title={labels.cycleLengthTitle}
        >
emelko's avatar
emelko committed
          <AppText style={styles.paragraph}>
            {labels.cycleLengthExplainer}
          </AppText>

          {!atLeastOneCycle &&
tina's avatar
tina committed
            <AppText>{labels.emptyStats}</AppText>
          }
          {atLeastOneCycle && numberOfCycles === 1 &&
emelko's avatar
emelko committed
            <View style={[styles.statsRow, styles.paragraph]}>
              <AppText>{labels.oneCycleStats}</AppText>
emelko's avatar
emelko committed
              <AppText style={styles.emphasis}> {cycleLengths[0]} </AppText>
              <AppText>{labels.daysLabel}.</AppText>
          }
          {atLeastOneCycle && numberOfCycles > 1 && <View>
emelko's avatar
emelko committed
            <View style={styles.paragraph}>
              <AppText style={styles.emphasis}>
                {labels.averageLabel}: {cycleInfo.mean} {labels.daysLabel}
              </AppText>
emelko's avatar
emelko committed
            <View>
              <AppText>
                {labels.minLabel}: {cycleInfo.minimum} {labels.daysLabel}
              </AppText>
emelko's avatar
emelko committed
            <View>
              <AppText>
                {labels.maxLabel}: {cycleInfo.maximum} {labels.daysLabel}
              </AppText>
emelko's avatar
emelko committed
            <View style={styles.paragraph}>
              <AppText>
                {labels.stdLabel}: {cycleInfo.stdDeviation} {labels.daysLabel}
              </AppText>
            <View style={styles.statsRow}>
              <AppText>{labels.basisOfStatsBeginning}</AppText>
emelko's avatar
emelko committed
              <AppText style={styles.emphasis}> {numberOfCycles} </AppText>
              <AppText>{labels.basisOfStatsEnd}</AppText>
            </View>
          </View>}