information about bleeding data is shown on home screen

This commit is contained in:
tina
2018-08-29 17:29:33 +02:00
parent e047440068
commit 432c56c0c6
3 changed files with 1588 additions and 1551 deletions
+34 -6
View File
@@ -5,10 +5,11 @@ import {
Text,
ScrollView
} from 'react-native'
import { LocalDate } from 'js-joda'
import { LocalDate, ChronoUnit } from 'js-joda'
import styles from '../styles/index'
import cycleModule from '../lib/cycle'
import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithDummyData, deleteAll } from '../db'
import {bleedingPrediction as labels} from './labels'
const getCycleDayNumber = cycleModule().getCycleDayNumber
@@ -19,23 +20,25 @@ export default class Home extends Component {
const cycleDayNumber = getCycleDayNumber(this.todayDateString)
this.state = {
welcomeText: determineWelcomeText(cycleDayNumber)
welcomeText: determineWelcomeText(cycleDayNumber),
predictionText: determinePredictionText()
}
this.setStateWithCurrentWelcomeText = (function (HomeComponent) {
this.setStateWithCurrentText = (function (HomeComponent) {
return function () {
const cycleDayNumber = getCycleDayNumber(HomeComponent.todayDateString)
HomeComponent.setState({
welcomeText: determineWelcomeText(cycleDayNumber)
welcomeText: determineWelcomeText(cycleDayNumber),
predictionText: determinePredictionText()
})
}
})(this)
bleedingDaysSortedByDate.addListener(this.setStateWithCurrentWelcomeText)
bleedingDaysSortedByDate.addListener(this.setStateWithCurrentText)
}
componentWillUnmount() {
bleedingDaysSortedByDate.removeListener(this.setStateWithCurrentWelcomeText)
bleedingDaysSortedByDate.removeListener(this.setStateWithCurrentText)
}
passTodayToDayView() {
@@ -49,6 +52,7 @@ export default class Home extends Component {
return (
<ScrollView>
<Text style={styles.welcome}>{this.state.welcomeText}</Text>
<Text style={styles.welcome}>{this.state.predictionText}</Text>
<View style={styles.homeButtons}>
<View style={styles.homeButton}>
<Button
@@ -80,3 +84,27 @@ function determineWelcomeText(cycleDayNumber) {
return cycleDayNumber ? welcomeTextWithCycleDay : welcomeText
}
function determinePredictionText() {
const bleedingPrediction = cycleModule().getPredictedMenses()
if (!bleedingPrediction.length) return labels.noPrediction
const todayDate = LocalDate.now()
const bleedingStart = LocalDate.parse(bleedingPrediction[0][0])
const bleedingEnd = LocalDate.parse(bleedingPrediction[0][ bleedingPrediction[0].length - 1 ])
if (todayDate.isBefore(bleedingStart)) {
return labels.predictionInFuture(
todayDate.until(bleedingStart, ChronoUnit.DAYS),
todayDate.until(bleedingEnd, ChronoUnit.DAYS)
)
}
if (todayDate.isAfter(bleedingEnd)) {
return labels.predictionInPast(bleedingStart.toString(), bleedingEnd.toString())
}
const daysToEnd = todayDate.until(bleedingEnd, ChronoUnit.DAYS)
if (daysToEnd === 0) {
return labels.predictionStartedNoDaysLeft
} else if (daysToEnd === 1) {
return labels.predictionStarted1DayLeft
} else {
return labels.predictionStartedXDaysLeft(daysToEnd)
}
}
+9
View File
@@ -56,4 +56,13 @@ export const stats = {
minLabel: 'Shortest cycle',
maxLabel: 'Longest cycle',
stdLabel: 'Standard deviation'
}
export const bleedingPrediction = {
noPrediction: 'There is not enough period data to predict the next one.',
predictionInFuture: (startDays, endDays) => `Your next period is likely to start in ${startDays} to ${endDays} days.`,
predictionStartedXDaysLeft: (numberOfDays) => `Your period is likely to start today or during the next ${numberOfDays} days.`,
predictionStarted1DayLeft: 'Your period is likely to start today or tomorrow.',
predictionStartedNoDaysLeft: 'Your period is likely to start today.',
predictionInPast: (startDate, endDate) => `Based on your documented data, your period was likely to start between ${startDate} and ${endDate}.`
}
+1545 -1545
View File
File diff suppressed because it is too large Load Diff