Add more data to stats

This commit is contained in:
Maria Zadnepryanets
2022-09-19 14:23:55 +00:00
parent c847270159
commit 974d081f40
10 changed files with 229 additions and 61 deletions
+23 -3
View File
@@ -3,6 +3,8 @@ import { getCycleLengthStats } from './cycle-length'
const LocalDate = joda.LocalDate
const DAYS = joda.ChronoUnit.DAYS
const toJSON = (realmObj) => JSON.parse(JSON.stringify(realmObj))
export default function config(opts) {
let bleedingDaysSortedByDate
let cycleStartsSortedByDate
@@ -14,9 +16,13 @@ export default function config(opts) {
if (!opts) {
// we only want to require (and run) the db module
// when not running the tests
bleedingDaysSortedByDate = require('../db').getBleedingDaysSortedByDate()
cycleStartsSortedByDate = require('../db').getCycleStartsSortedByDate()
cycleDaysSortedByDate = require('../db').getCycleDaysSortedByDate()
bleedingDaysSortedByDate = toJSON(
require('../db').getBleedingDaysSortedByDate()
)
cycleStartsSortedByDate = toJSON(
require('../db').getCycleStartsSortedByDate()
)
cycleDaysSortedByDate = toJSON(require('../db').getCycleDaysSortedByDate())
maxBreakInBleeding = 1
maxCycleLength = 99
minCyclesForPrediction = 3
@@ -222,6 +228,19 @@ export default function config(opts) {
return predictedMenses
}
const getStats = () =>
cycleStartsSortedByDate.map((day, i) => {
const today = getTodayDate()
const cycleLength =
i === 0 ? getCycleDayNumber(today) : getAllCycleLengths()[i - 1]
return {
date: day.date,
cycleLength,
bleedingLength: ++getMensesDaysRightAfter(day).length,
}
})
return {
getCycleDayNumber,
getCycleForDay,
@@ -232,5 +251,6 @@ export default function config(opts) {
isMensesStart,
getMensesDaysRightAfter,
getCycleByStartDay,
getStats,
}
}