show days without measurements in battery history
This commit is contained in:
parent
cd4cf1f0da
commit
4220a6bba3
1 changed files with 14 additions and 3 deletions
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue