This commit is contained in:
1 parent
cd7ddd3cf6
commit
89621bc7c3
15 files changed
+289
-74
No files matched your search
@@ -61,7 +61,8 @@ def daily_coverage(rows, timezone_name, days, now=None):
|
||||
date = datetime.fromtimestamp(observed / 1000, zone).date().isoformat()
|
||||
observations[date] += 1
|
||||
bucket = observed // BUCKET_MS * BUCKET_MS
|
||||
mask = sum(1 << index for index in range(3) if row[2 + index * 2])
|
||||
# Archive rows retain meter flags, but status coverage tracks Energy and Boiler only.
|
||||
mask = int(bool(row[2])) | (int(bool(row[6])) << 1)
|
||||
slots_by_time[bucket] = slots_by_time.get(bucket, 0) | mask
|
||||
result = []
|
||||
for offset in range(days + 1):
|
||||
@@ -71,18 +72,22 @@ def daily_coverage(rows, timezone_name, days, now=None):
|
||||
start_ms = round(start.timestamp() * 1000)
|
||||
expected = round((end.timestamp() - start.timestamp()) * 1000) // BUCKET_MS
|
||||
elapsed = expected if date < today else max(0, min(expected, (upper - start_ms) // BUCKET_MS))
|
||||
# This is extraction coverage: show the current slot as soon as its
|
||||
# record is saved, without waiting for the five-minute period to end.
|
||||
# An unrecorded current slot stays pending and is not counted missing.
|
||||
if date == today and elapsed < expected and start_ms + elapsed * BUCKET_MS in slots_by_time:
|
||||
elapsed += 1
|
||||
slots = []
|
||||
for index in range(expected):
|
||||
slots.append(slots_by_time.get(start_ms + index * BUCKET_MS, 0) if index < elapsed else -1)
|
||||
complete = sum(mask == 7 for mask in slots)
|
||||
complete = sum(mask == 3 for mask in slots)
|
||||
count = observations[date.isoformat()]
|
||||
status = "in_progress" if date == today else "complete" if complete == expected else "partial" if count else "missing"
|
||||
result.append({
|
||||
"date": date.isoformat(), "day_start": utc_text(start), "expected": expected, "elapsed": elapsed,
|
||||
"complete": complete, "missing": elapsed - complete, "samples": count, "status": status,
|
||||
"energy_complete": sum(mask >= 0 and bool(mask & 1) for mask in slots),
|
||||
"meter_complete": sum(mask >= 0 and bool(mask & 2) for mask in slots),
|
||||
"boiler_complete": sum(mask >= 0 and bool(mask & 4) for mask in slots),
|
||||
"boiler_complete": sum(mask >= 0 and bool(mask & 2) for mask in slots),
|
||||
"slots": slots,
|
||||
})
|
||||
return result
|
||||
Reference in new issue
Block a user