show days without measurements in battery history

This commit is contained in:
arne 2025-11-13 12:02:19 +01:00
commit 4220a6bba3

View file

@ -38,7 +38,7 @@ export default {
// today will be considered. // today will be considered.
const today = new RegExp(`^${new Date().toISOString().split('T')[0]}`) const today = new RegExp(`^${new Date().toISOString().split('T')[0]}`)
const measurementsPerDay = [...iterator( let measurementsPerDay = [...iterator(
comp( comp(
takeWhile(d => d.timestamp.match(today) == null), takeWhile(d => d.timestamp.match(today) == null),
partitionBy(d => d.timestamp.split('T')[0]), partitionBy(d => d.timestamp.split('T')[0]),
@ -63,9 +63,20 @@ export default {
}) })
), ),
data["power-history"] data["power-history"]
)].sort((a, b) => a.date > b.date ? -1 : 1) )]
return measurementsPerDay // Fill holes that may appear for days without measurements
const datesWithValues = new Set(measurementsPerDay.map((m) => m.date))
for (let offset = 1; offset < 7; offset++) {
const day = new Date()
day.setDate(day.getDate() - offset)
const date = day.toISOString().split('T')[0]
if (!datesWithValues.has(date)) {
measurementsPerDay.push({ date, measurements: Array.from({ length: 24 }) })
}
}
return measurementsPerDay.sort((a, b) => a.date > b.date ? -1 : 1)
} }
} }
} }