Merge branch 'master' into 82-chart-improvements
This commit is contained in:
@@ -5,6 +5,7 @@ import Calendar from './components/calendar'
|
|||||||
import CycleDay from './components/cycle-day'
|
import CycleDay from './components/cycle-day'
|
||||||
import Chart from './components/chart/chart'
|
import Chart from './components/chart/chart'
|
||||||
import Settings from './components/settings'
|
import Settings from './components/settings'
|
||||||
|
import Stats from './components/stats'
|
||||||
|
|
||||||
// this is until react native fixes this bugg, see
|
// this is until react native fixes this bugg, see
|
||||||
// https://github.com/facebook/react-native/issues/18868#issuecomment-382671739
|
// https://github.com/facebook/react-native/issues/18868#issuecomment-382671739
|
||||||
@@ -16,5 +17,6 @@ export default createStackNavigator({
|
|||||||
calendar: { screen: Calendar },
|
calendar: { screen: Calendar },
|
||||||
cycleDay: { screen: CycleDay },
|
cycleDay: { screen: CycleDay },
|
||||||
chart: { screen: Chart },
|
chart: { screen: Chart },
|
||||||
settings: { screen: Settings }
|
settings: { screen: Settings },
|
||||||
|
stats: { screen: Stats}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { View } from 'react-native'
|
import { View } from 'react-native'
|
||||||
import { Calendar } from 'react-native-calendars'
|
import { CalendarList } from 'react-native-calendars'
|
||||||
import * as styles from '../styles'
|
import * as styles from '../styles'
|
||||||
import { getOrCreateCycleDay, bleedingDaysSortedByDate } from '../db'
|
import { getOrCreateCycleDay, bleedingDaysSortedByDate } from '../db'
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ export default class CalendarView extends Component {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Calendar
|
<CalendarList
|
||||||
onDayPress={ this.passDateToDayView.bind(this) }
|
onDayPress={ this.passDateToDayView.bind(this) }
|
||||||
markedDates = { this.state.bleedingDaysInCalFormat }
|
markedDates = { this.state.bleedingDaysInCalFormat }
|
||||||
markingType = {'period'}
|
markingType = {'period'}
|
||||||
|
|||||||
@@ -87,6 +87,12 @@ export default class Home extends Component {
|
|||||||
title="delete everything">
|
title="delete everything">
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
|
<View style={styles.homeButton}>
|
||||||
|
<Button
|
||||||
|
onPress={() => navigate('stats')}
|
||||||
|
title="Go to stats">
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import React, { Component } from 'react'
|
||||||
|
import {
|
||||||
|
Text,
|
||||||
|
View,
|
||||||
|
ScrollView
|
||||||
|
} from 'react-native'
|
||||||
|
import { LocalDate, ChronoUnit } from 'js-joda'
|
||||||
|
import styles from '../styles/index'
|
||||||
|
import cycleModule from '../lib/cycle'
|
||||||
|
import getCycleInfo from '../lib/cycle-length'
|
||||||
|
|
||||||
|
export default class Stats extends Component {
|
||||||
|
render() {
|
||||||
|
const allMensesStarts = cycleModule().getAllMensesStarts()
|
||||||
|
const statsText = determineStatsText(allMensesStarts)
|
||||||
|
return (
|
||||||
|
<ScrollView>
|
||||||
|
<View>
|
||||||
|
<Text style={styles.stats}>{statsText}</Text>
|
||||||
|
</View>
|
||||||
|
</ScrollView>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCycleLength(cycleStartDates) {
|
||||||
|
const cycleLengths = []
|
||||||
|
for (let i = 0; i < cycleStartDates.length - 1; i++) {
|
||||||
|
const nextCycleStart = LocalDate.parse(cycleStartDates[i])
|
||||||
|
const cycleStart = LocalDate.parse(cycleStartDates[i + 1])
|
||||||
|
cycleLengths.push(cycleStart.until(nextCycleStart, ChronoUnit.DAYS))
|
||||||
|
}
|
||||||
|
return cycleLengths
|
||||||
|
}
|
||||||
|
|
||||||
|
function determineStatsText(allMensesStarts) {
|
||||||
|
const emptyStats = 'At least one completed cycle is needed to present you with stats here.'
|
||||||
|
if (allMensesStarts.length < 2) {
|
||||||
|
return emptyStats
|
||||||
|
} else {
|
||||||
|
const cycleLengths = getCycleLength(allMensesStarts)
|
||||||
|
const numberOfCycles = cycleLengths.length
|
||||||
|
if (numberOfCycles === 1) {
|
||||||
|
return `You have documented one cycle of ${cycleLengths[0]} days.`
|
||||||
|
}
|
||||||
|
const cycleInfo = getCycleInfo(cycleLengths)
|
||||||
|
const statsText = `Stats are based on ${numberOfCycles} completed cycles.\n\n\
|
||||||
|
Average cycle length: ${cycleInfo.mean} days\n\nShortest cycle: ${cycleInfo.minimum} days\nLongest cycle: ${cycleInfo.maximum} days\nMedian length (meaning 50% of cycles are of this length or shorter): ${cycleInfo.median} days\nStandard deviation: ${cycleInfo.stdDeviation}`
|
||||||
|
return statsText
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,38 +1,38 @@
|
|||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
|
|
||||||
export default function getPeriodLengthStats(cycleLengths) {
|
export default function getCycleLengthStats(cycleLengths) {
|
||||||
throwIfArgsAreNotInRequiredFormat(cycleLengths)
|
throwIfArgsAreNotInRequiredFormat(cycleLengths)
|
||||||
const periodLengthStats = {}
|
const cycleLengthStats = {}
|
||||||
const sortedCycleLengths = cycleLengths.sort((a, b) => {
|
const sortedCycleLengths = cycleLengths.sort((a, b) => {
|
||||||
return a - b
|
return a - b
|
||||||
})
|
})
|
||||||
periodLengthStats.minimum = sortedCycleLengths[0]
|
cycleLengthStats.minimum = sortedCycleLengths[0]
|
||||||
periodLengthStats.maximum = sortedCycleLengths[cycleLengths.length - 1]
|
cycleLengthStats.maximum = sortedCycleLengths[cycleLengths.length - 1]
|
||||||
periodLengthStats.mean = Math.round(
|
cycleLengthStats.mean = Math.round(
|
||||||
cycleLengths.reduce(getSum) / cycleLengths.length * 100
|
cycleLengths.reduce(getSum) / cycleLengths.length * 100
|
||||||
) / 100
|
) / 100
|
||||||
// median
|
// median
|
||||||
if (cycleLengths.length % 2 == 1) {
|
if (cycleLengths.length % 2 == 1) {
|
||||||
periodLengthStats.median = sortedCycleLengths[
|
cycleLengthStats.median = sortedCycleLengths[
|
||||||
(cycleLengths.length + 1) / 2 - 1
|
(cycleLengths.length + 1) / 2 - 1
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
const middle = cycleLengths.length / 2
|
const middle = cycleLengths.length / 2
|
||||||
periodLengthStats.median = (sortedCycleLengths[middle - 1] +
|
cycleLengthStats.median = (sortedCycleLengths[middle - 1] +
|
||||||
sortedCycleLengths[middle]) / 2
|
sortedCycleLengths[middle]) / 2
|
||||||
}
|
}
|
||||||
// corrected standard deviation (based on unbiased sample variance)
|
// corrected standard deviation (based on unbiased sample variance)
|
||||||
if (cycleLengths.length > 1) {
|
if (cycleLengths.length > 1) {
|
||||||
const sumOfSquares = cycleLengths.map(cycleLength => {
|
const sumOfSquares = cycleLengths.map(cycleLength => {
|
||||||
return Math.pow(cycleLength - periodLengthStats.mean, 2)
|
return Math.pow(cycleLength - cycleLengthStats.mean, 2)
|
||||||
}).reduce(getSum)
|
}).reduce(getSum)
|
||||||
periodLengthStats.stdDeviation = Math.round(
|
cycleLengthStats.stdDeviation = Math.round(
|
||||||
Math.sqrt(sumOfSquares / (cycleLengths.length - 1 )) * 100
|
Math.sqrt(sumOfSquares / (cycleLengths.length - 1 )) * 100
|
||||||
) / 100
|
) / 100
|
||||||
} else {
|
} else {
|
||||||
periodLengthStats.stdDeviation = null
|
cycleLengthStats.stdDeviation = null
|
||||||
}
|
}
|
||||||
return periodLengthStats
|
return cycleLengthStats
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSum(total, num) {
|
function getSum(total, num) {
|
||||||
+15
-1
@@ -130,10 +130,24 @@ export default function config(opts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAllMensesStarts(day, collectedDates) {
|
||||||
|
day = day || LocalDate.now().toString()
|
||||||
|
collectedDates = collectedDates || []
|
||||||
|
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
|
getCyclesBefore,
|
||||||
|
getAllMensesStarts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Generated
+99
-85
@@ -3479,8 +3479,8 @@
|
|||||||
"integrity": "sha512-z8H8/diyk76B7q5wg+Ud0+CqzcAF3mBBI/bA5ne5zrRUUIvNkJY//D3BqyH571KuAC4Nr7Rw7CjWX4r0y9DvNg==",
|
"integrity": "sha512-z8H8/diyk76B7q5wg+Ud0+CqzcAF3mBBI/bA5ne5zrRUUIvNkJY//D3BqyH571KuAC4Nr7Rw7CjWX4r0y9DvNg==",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"nan": "^2.9.2",
|
"nan": "2.10.0",
|
||||||
"node-pre-gyp": "^0.10.0"
|
"node-pre-gyp": "0.10.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"abbrev": {
|
"abbrev": {
|
||||||
@@ -3502,19 +3502,21 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"delegates": "^1.0.0",
|
"delegates": "1.0.0",
|
||||||
"readable-stream": "^2.0.6"
|
"readable-stream": "2.3.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true
|
"bundled": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"balanced-match": "^1.0.0",
|
"balanced-match": "1.0.0",
|
||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -3525,15 +3527,18 @@
|
|||||||
},
|
},
|
||||||
"code-point-at": {
|
"code-point-at": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true
|
"bundled": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"bundled": true
|
"bundled": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"console-control-strings": {
|
"console-control-strings": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true
|
"bundled": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"core-util-is": {
|
"core-util-is": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
@@ -3568,7 +3573,7 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"minipass": "^2.2.1"
|
"minipass": "2.2.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"fs.realpath": {
|
"fs.realpath": {
|
||||||
@@ -3581,14 +3586,14 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"aproba": "^1.0.3",
|
"aproba": "1.2.0",
|
||||||
"console-control-strings": "^1.0.0",
|
"console-control-strings": "1.1.0",
|
||||||
"has-unicode": "^2.0.0",
|
"has-unicode": "2.0.1",
|
||||||
"object-assign": "^4.1.0",
|
"object-assign": "4.1.1",
|
||||||
"signal-exit": "^3.0.0",
|
"signal-exit": "3.0.2",
|
||||||
"string-width": "^1.0.1",
|
"string-width": "1.0.2",
|
||||||
"strip-ansi": "^3.0.1",
|
"strip-ansi": "3.0.1",
|
||||||
"wide-align": "^1.1.0"
|
"wide-align": "1.1.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"glob": {
|
"glob": {
|
||||||
@@ -3596,12 +3601,12 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"fs.realpath": "^1.0.0",
|
"fs.realpath": "1.0.0",
|
||||||
"inflight": "^1.0.4",
|
"inflight": "1.0.6",
|
||||||
"inherits": "2",
|
"inherits": "2.0.3",
|
||||||
"minimatch": "^3.0.4",
|
"minimatch": "3.0.4",
|
||||||
"once": "^1.3.0",
|
"once": "1.4.0",
|
||||||
"path-is-absolute": "^1.0.0"
|
"path-is-absolute": "1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"has-unicode": {
|
"has-unicode": {
|
||||||
@@ -3614,7 +3619,7 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"safer-buffer": "^2.1.0"
|
"safer-buffer": "2.1.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ignore-walk": {
|
"ignore-walk": {
|
||||||
@@ -3622,7 +3627,7 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"minimatch": "^3.0.4"
|
"minimatch": "3.0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"inflight": {
|
"inflight": {
|
||||||
@@ -3630,13 +3635,14 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"once": "^1.3.0",
|
"once": "1.4.0",
|
||||||
"wrappy": "1"
|
"wrappy": "1.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"inherits": {
|
"inherits": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"bundled": true
|
"bundled": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"ini": {
|
"ini": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
@@ -3646,8 +3652,9 @@
|
|||||||
"is-fullwidth-code-point": {
|
"is-fullwidth-code-point": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"number-is-nan": "^1.0.0"
|
"number-is-nan": "1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"isarray": {
|
"isarray": {
|
||||||
@@ -3658,20 +3665,23 @@
|
|||||||
"minimatch": {
|
"minimatch": {
|
||||||
"version": "3.0.4",
|
"version": "3.0.4",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"brace-expansion": "^1.1.7"
|
"brace-expansion": "1.1.11"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "0.0.8",
|
"version": "0.0.8",
|
||||||
"bundled": true
|
"bundled": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"minipass": {
|
"minipass": {
|
||||||
"version": "2.2.4",
|
"version": "2.2.4",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"safe-buffer": "^5.1.1",
|
"safe-buffer": "5.1.1",
|
||||||
"yallist": "^3.0.0"
|
"yallist": "3.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minizlib": {
|
"minizlib": {
|
||||||
@@ -3679,12 +3689,13 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"minipass": "^2.2.1"
|
"minipass": "2.2.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mkdirp": {
|
"mkdirp": {
|
||||||
"version": "0.5.1",
|
"version": "0.5.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"minimist": "0.0.8"
|
"minimist": "0.0.8"
|
||||||
}
|
}
|
||||||
@@ -3699,9 +3710,9 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"debug": "^2.1.2",
|
"debug": "2.6.9",
|
||||||
"iconv-lite": "^0.4.4",
|
"iconv-lite": "0.4.21",
|
||||||
"sax": "^1.2.4"
|
"sax": "1.2.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node-pre-gyp": {
|
"node-pre-gyp": {
|
||||||
@@ -3709,16 +3720,16 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"detect-libc": "^1.0.2",
|
"detect-libc": "1.0.3",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "0.5.1",
|
||||||
"needle": "^2.2.0",
|
"needle": "2.2.0",
|
||||||
"nopt": "^4.0.1",
|
"nopt": "4.0.1",
|
||||||
"npm-packlist": "^1.1.6",
|
"npm-packlist": "1.1.10",
|
||||||
"npmlog": "^4.0.2",
|
"npmlog": "4.1.2",
|
||||||
"rc": "^1.1.7",
|
"rc": "1.2.7",
|
||||||
"rimraf": "^2.6.1",
|
"rimraf": "2.6.2",
|
||||||
"semver": "^5.3.0",
|
"semver": "5.5.0",
|
||||||
"tar": "^4"
|
"tar": "4.4.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nopt": {
|
"nopt": {
|
||||||
@@ -3726,8 +3737,8 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"abbrev": "1",
|
"abbrev": "1.1.1",
|
||||||
"osenv": "^0.1.4"
|
"osenv": "0.1.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npm-bundled": {
|
"npm-bundled": {
|
||||||
@@ -3740,8 +3751,8 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"ignore-walk": "^3.0.1",
|
"ignore-walk": "3.0.1",
|
||||||
"npm-bundled": "^1.0.1"
|
"npm-bundled": "1.0.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmlog": {
|
"npmlog": {
|
||||||
@@ -3749,15 +3760,16 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"are-we-there-yet": "~1.1.2",
|
"are-we-there-yet": "1.1.4",
|
||||||
"console-control-strings": "~1.1.0",
|
"console-control-strings": "1.1.0",
|
||||||
"gauge": "~2.7.3",
|
"gauge": "2.7.4",
|
||||||
"set-blocking": "~2.0.0"
|
"set-blocking": "2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"number-is-nan": {
|
"number-is-nan": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"bundled": true
|
"bundled": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"object-assign": {
|
"object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
@@ -3767,8 +3779,9 @@
|
|||||||
"once": {
|
"once": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"wrappy": "1"
|
"wrappy": "1.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"os-homedir": {
|
"os-homedir": {
|
||||||
@@ -3786,8 +3799,8 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"os-homedir": "^1.0.0",
|
"os-homedir": "1.0.2",
|
||||||
"os-tmpdir": "^1.0.0"
|
"os-tmpdir": "1.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"path-is-absolute": {
|
"path-is-absolute": {
|
||||||
@@ -3805,10 +3818,10 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"deep-extend": "^0.5.1",
|
"deep-extend": "0.5.1",
|
||||||
"ini": "~1.3.0",
|
"ini": "1.3.5",
|
||||||
"minimist": "^1.2.0",
|
"minimist": "1.2.0",
|
||||||
"strip-json-comments": "~2.0.1"
|
"strip-json-comments": "2.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minimist": {
|
"minimist": {
|
||||||
@@ -3823,13 +3836,13 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"core-util-is": "~1.0.0",
|
"core-util-is": "1.0.2",
|
||||||
"inherits": "~2.0.3",
|
"inherits": "2.0.3",
|
||||||
"isarray": "~1.0.0",
|
"isarray": "1.0.0",
|
||||||
"process-nextick-args": "~2.0.0",
|
"process-nextick-args": "2.0.0",
|
||||||
"safe-buffer": "~5.1.1",
|
"safe-buffer": "5.1.1",
|
||||||
"string_decoder": "~1.1.1",
|
"string_decoder": "1.1.1",
|
||||||
"util-deprecate": "~1.0.1"
|
"util-deprecate": "1.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rimraf": {
|
"rimraf": {
|
||||||
@@ -3837,7 +3850,7 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"glob": "^7.0.5"
|
"glob": "7.1.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"safe-buffer": {
|
"safe-buffer": {
|
||||||
@@ -3872,10 +3885,11 @@
|
|||||||
"string-width": {
|
"string-width": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"code-point-at": "^1.0.0",
|
"code-point-at": "1.1.0",
|
||||||
"is-fullwidth-code-point": "^1.0.0",
|
"is-fullwidth-code-point": "1.0.0",
|
||||||
"strip-ansi": "^3.0.0"
|
"strip-ansi": "3.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"string_decoder": {
|
"string_decoder": {
|
||||||
@@ -3883,14 +3897,14 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"safe-buffer": "~5.1.0"
|
"safe-buffer": "5.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"strip-ansi": {
|
"strip-ansi": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"ansi-regex": "^2.0.0"
|
"ansi-regex": "2.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"strip-json-comments": {
|
"strip-json-comments": {
|
||||||
@@ -3903,13 +3917,13 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"chownr": "^1.0.1",
|
"chownr": "1.0.1",
|
||||||
"fs-minipass": "^1.2.5",
|
"fs-minipass": "1.2.5",
|
||||||
"minipass": "^2.2.4",
|
"minipass": "2.2.4",
|
||||||
"minizlib": "^1.1.0",
|
"minizlib": "1.1.0",
|
||||||
"mkdirp": "^0.5.0",
|
"mkdirp": "0.5.1",
|
||||||
"safe-buffer": "^5.1.1",
|
"safe-buffer": "5.1.1",
|
||||||
"yallist": "^3.0.2"
|
"yallist": "3.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"util-deprecate": {
|
"util-deprecate": {
|
||||||
@@ -3922,7 +3936,7 @@
|
|||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"string-width": "^1.0.2"
|
"string-width": "1.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"wrappy": {
|
"wrappy": {
|
||||||
|
|||||||
@@ -82,5 +82,11 @@ export default StyleSheet.create({
|
|||||||
marginTop: 15,
|
marginTop: 15,
|
||||||
marginLeft: 'auto',
|
marginLeft: 'auto',
|
||||||
marginRight: 'auto'
|
marginRight: 'auto'
|
||||||
|
},
|
||||||
|
stats: {
|
||||||
|
fontSize: 18,
|
||||||
|
margin: 30,
|
||||||
|
textAlign: 'left',
|
||||||
|
textAlignVertical: 'center'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
import chai from 'chai'
|
import chai from 'chai'
|
||||||
import { AssertionError } from 'assert'
|
import { AssertionError } from 'assert'
|
||||||
|
|
||||||
import periodInfo from '../lib/period-length'
|
import cycleInfo from '../lib/cycle-length'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('getPeriodLengthStats', () => {
|
describe('getCycleLengthStats', () => {
|
||||||
it('works for a simple odd-numbered array', () => {
|
it('works for a simple odd-numbered array', () => {
|
||||||
const periodLengths = [99, 5, 1, 2, 100]
|
const cycleLengths = [99, 5, 1, 2, 100]
|
||||||
const result = periodInfo(periodLengths)
|
const result = cycleInfo(cycleLengths)
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
minimum: 1,
|
minimum: 1,
|
||||||
maximum: 100,
|
maximum: 100,
|
||||||
@@ -20,8 +20,8 @@ describe('getPeriodLengthStats', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('works for a simple even-numbered array', () => {
|
it('works for a simple even-numbered array', () => {
|
||||||
const periodLengths = [4, 1, 15, 2, 20, 5]
|
const cycleLengths = [4, 1, 15, 2, 20, 5]
|
||||||
const result = periodInfo(periodLengths)
|
const result = cycleInfo(cycleLengths)
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
minimum: 1,
|
minimum: 1,
|
||||||
maximum: 20,
|
maximum: 20,
|
||||||
@@ -32,8 +32,8 @@ describe('getPeriodLengthStats', () => {
|
|||||||
expect(result).to.eql(expectedResult)
|
expect(result).to.eql(expectedResult)
|
||||||
})
|
})
|
||||||
it('works for an one-element array', () => {
|
it('works for an one-element array', () => {
|
||||||
const periodLengths = [42]
|
const cycleLengths = [42]
|
||||||
const result = periodInfo(periodLengths)
|
const result = cycleInfo(cycleLengths)
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
minimum: 42,
|
minimum: 42,
|
||||||
maximum: 42,
|
maximum: 42,
|
||||||
@@ -45,20 +45,20 @@ describe('getPeriodLengthStats', () => {
|
|||||||
})
|
})
|
||||||
describe('when args are wrong', () => {
|
describe('when args are wrong', () => {
|
||||||
it('throws when arg object is an empty array', () => {
|
it('throws when arg object is an empty array', () => {
|
||||||
const periodLengths = []
|
const cycleLengths = []
|
||||||
expect(() => periodInfo(periodLengths).to.throw(AssertionError))
|
expect(() => cycleInfo(cycleLengths).to.throw(AssertionError))
|
||||||
})
|
})
|
||||||
it('throws when arg object is not in right format', () => {
|
it('throws when arg object is not in right format', () => {
|
||||||
const wrongObject = { hello: 'world' }
|
const wrongObject = { hello: 'world' }
|
||||||
expect(() => periodInfo(wrongObject).to.throw(AssertionError))
|
expect(() => cycleInfo(wrongObject).to.throw(AssertionError))
|
||||||
})
|
})
|
||||||
it('throws when arg array contains a string', () => {
|
it('throws when arg array contains a string', () => {
|
||||||
const wrongElement = [4, 1, 15, '2', 20, 5]
|
const wrongElement = [4, 1, 15, '2', 20, 5]
|
||||||
expect(() => periodInfo(wrongElement).to.throw(AssertionError))
|
expect(() => cycleInfo(wrongElement).to.throw(AssertionError))
|
||||||
})
|
})
|
||||||
it('throws when arg array contains a NaN', () => {
|
it('throws when arg array contains a NaN', () => {
|
||||||
const wrongElement = [4, 1, 15, NaN, 20, 5]
|
const wrongElement = [4, 1, 15, NaN, 20, 5]
|
||||||
expect(() => periodInfo(wrongElement).to.throw(AssertionError))
|
expect(() => cycleInfo(wrongElement).to.throw(AssertionError))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user