From 897e99e6af72a52bd8ef226193b9c3f4955785ca Mon Sep 17 00:00:00 2001
From: tina <lt-bloody@riox.eu>
Date: Wed, 1 Aug 2018 17:20:13 +0200
Subject: [PATCH] adds stats button on home screen, and creates stats screen,
 length still needs to be calculated

---
 app.js              |  4 +++-
 components/home.js  |  6 ++++++
 components/stats.js | 41 +++++++++++++++++++++++++++++++++++++++++
 lib/cycle.js        |  3 ++-
 4 files changed, 52 insertions(+), 2 deletions(-)
 create mode 100644 components/stats.js

diff --git a/app.js b/app.js
index bb31b220..fae73d63 100644
--- a/app.js
+++ b/app.js
@@ -5,6 +5,7 @@ import Calendar from './components/calendar'
 import CycleDay from './components/cycle-day'
 import Chart from './components/chart/chart'
 import Settings from './components/settings'
+import Stats from './components/stats'
 
 // this is until react native fixes this bugg, see
 // https://github.com/facebook/react-native/issues/18868#issuecomment-382671739
@@ -16,5 +17,6 @@ export default createStackNavigator({
   calendar: { screen: Calendar },
   cycleDay: { screen: CycleDay },
   chart: { screen: Chart },
-  settings: { screen: Settings }
+  settings: { screen: Settings },
+  stats: { screen: Stats}
 })
diff --git a/components/home.js b/components/home.js
index 623821d4..315ea504 100644
--- a/components/home.js
+++ b/components/home.js
@@ -87,6 +87,12 @@ export default class Home extends Component {
               title="delete everything">
             </Button>
           </View>
+          <View style={styles.homeButton}>
+            <Button
+              onPress={() => navigate('stats')}
+              title="Go to stats">
+            </Button>
+          </View>
         </View>
       </ScrollView>
     )
diff --git a/components/stats.js b/components/stats.js
new file mode 100644
index 00000000..6d8a0855
--- /dev/null
+++ b/components/stats.js
@@ -0,0 +1,41 @@
+import React, { Component } from 'react'
+import {
+  View,
+  Text,
+  ScrollView
+} from 'react-native'
+import { LocalDate } 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 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)
+
+  }
+
+  render() {
+    return (
+      <ScrollView>
+        <Text style={styles.welcome}>based on {this.numberOfCycles} periods:</Text>
+        <Text style={styles.welcome}>min: {this.periodInfo.minimum}</Text>
+        <Text style={styles.welcome}>mean: {this.periodInfo.mean}</Text>
+        <Text style={styles.welcome}>max: {this.periodInfo.maximum}</Text>
+        <Text style={styles.welcome}>median: {this.periodInfo.median}</Text>
+        <Text style={styles.welcome}>standard deviation: {this.periodInfo.stdDeviation}</Text>
+      </ScrollView>
+    )
+  }
+}
\ No newline at end of file
diff --git a/lib/cycle.js b/lib/cycle.js
index f350ff82..00a19855 100644
--- a/lib/cycle.js
+++ b/lib/cycle.js
@@ -134,6 +134,7 @@ export default function config(opts) {
     getCycleDayNumber,
     getCycleForDay,
     getPreviousCycle,
-    getCyclesBefore
+    getCyclesBefore,
+    getLastMensesStart
   }
 }
\ No newline at end of file
-- 
GitLab