Fix zero consumption for open-period reports with sparse readings
getPeriodConsumption()'s fallback branch picked the "first" baseline reading via readingOnOrAfter(periodStart) before readingOnOrBefore(), so a manually-read meter with only one reading entered this month collapsed first and last onto the same row and reported no_data/£0, even with a valid prior-month baseline available. Prefer the pre-period reading first. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
fc15b48527
commit
68dab06b0a
1 changed files with 1 additions and 1 deletions
|
|
@ -136,7 +136,7 @@ export async function getPeriodConsumption(meterId, periodStart, periodEnd) {
|
|||
const endPoint = await interpolatedValueAtDate(meterId, periodEnd)
|
||||
|
||||
if (!startPoint || !endPoint) {
|
||||
const first = (await readingOnOrAfter(meterId, periodStart)) || (await readingOnOrBefore(meterId, periodStart))
|
||||
const first = (await readingOnOrBefore(meterId, periodStart)) || (await readingOnOrAfter(meterId, periodStart))
|
||||
const last = await readingOnOrBefore(meterId, periodEnd)
|
||||
const hasData = !!(first && last && last.reading_date > first.reading_date)
|
||||
const basis = classifyBasis(hasData, periodStart, periodEnd, first, last)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue