This commit is contained in:
Mateusz Gruszczyński
2026-03-24 15:49:06 +01:00
parent 55a3c1ab7b
commit 84fe898a74
9 changed files with 203 additions and 42 deletions

View File

@@ -104,7 +104,7 @@ class EnergyService:
return rows
def bucketize_daily(self, records: list[DailyEnergyRecord], bucket: str) -> list[BucketPoint]:
grouped: dict[str, dict] = defaultdict(lambda: {"value": 0.0, "start": None, "end": None, "label": ""})
grouped: dict[str, dict] = defaultdict(lambda: {"value": 0.0, "start": None, "end": None, "label": "", "has_data": False})
for record in records:
start = datetime.combine(record.day, time.min, tzinfo=self.tz)
@@ -137,7 +137,9 @@ class EnergyService:
current = grouped[key]
current["label"] = label
current["value"] += record.energy_kwh
if record.samples_count > 0:
current["value"] += record.energy_kwh
current["has_data"] = True
current["start"] = bucket_start if current["start"] is None else min(current["start"], bucket_start)
current["end"] = bucket_end if current["end"] is None else max(current["end"], bucket_end)
@@ -149,7 +151,7 @@ class EnergyService:
label=item["label"],
start=item["start"],
end=item["end"],
value=round(item["value"], 2),
value=round(item["value"], 2) if item["has_data"] else None,
)
)
return rows