Make getCycleLenghts filter for max cycle length
This commit is contained in:
+9
-13
@@ -1,5 +1,5 @@
|
||||
import * as joda from 'js-joda'
|
||||
import {getCycleLengthStats} from './cycle-length'
|
||||
import { getCycleLengthStats } from './cycle-length'
|
||||
const LocalDate = joda.LocalDate
|
||||
const DAYS = joda.ChronoUnit.DAYS
|
||||
|
||||
@@ -142,24 +142,19 @@ export default function config(opts) {
|
||||
function getAllCycleLengths() {
|
||||
return cycleStartsSortedByDate
|
||||
.map(day => LocalDate.parse(day.date))
|
||||
.reduce((lengths, cycleStart, i, startsAsLocalDates) => {
|
||||
if (i === startsAsLocalDates.length - 1) return lengths
|
||||
.map((cycleStart, i, startsAsLocalDates) => {
|
||||
if (i === cycleStartsSortedByDate.length - 1) return null
|
||||
const prevCycleStart = startsAsLocalDates[i + 1]
|
||||
const cycleLength = prevCycleStart.until(cycleStart, DAYS)
|
||||
if (cycleLength <= maxCycleLength) { lengths.push(cycleLength) }
|
||||
return lengths
|
||||
}, [])
|
||||
return prevCycleStart.until(cycleStart, DAYS)
|
||||
})
|
||||
.filter(length => length && length <= maxCycleLength)
|
||||
}
|
||||
|
||||
function getPredictedMenses() {
|
||||
const allMensesStarts = cycleStartsSortedByDate
|
||||
const atLeastOneCycle = allMensesStarts.length > 1
|
||||
if (!atLeastOneCycle ||
|
||||
allMensesStarts.length < minCyclesForPrediction
|
||||
) {
|
||||
const cycleLengths = getAllCycleLengths()
|
||||
if (cycleLengths.length < minCyclesForPrediction) {
|
||||
return []
|
||||
}
|
||||
const cycleLengths = getAllCycleLengths()
|
||||
const cycleInfo = getCycleLengthStats(cycleLengths)
|
||||
const periodDistance = Math.round(cycleInfo.mean)
|
||||
let periodStartVariation
|
||||
@@ -173,6 +168,7 @@ export default function config(opts) {
|
||||
if (periodDistance - 5 < periodStartVariation) { // otherwise predictions overlap
|
||||
return []
|
||||
}
|
||||
const allMensesStarts = cycleStartsSortedByDate
|
||||
let lastStart = LocalDate.parse(allMensesStarts[0].date)
|
||||
const predictedMenses = []
|
||||
for (let i = 0; i < 3; i++) {
|
||||
|
||||
Reference in New Issue
Block a user