From af2e8b3843b03f4c8851f4cc1092f98d4cce658d Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 24 Jun 2026 17:09:59 +0000 Subject: [PATCH] =?UTF-8?q?Blend=20an=20off-peak=20meter's=20day/night=20r?= =?UTF-8?q?ate=20by=20high-rate=20fraction=20=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- domain/fuel_rates/fuel_rates.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/domain/fuel_rates/fuel_rates.py b/domain/fuel_rates/fuel_rates.py index 569c6f17..81f78ab0 100644 --- a/domain/fuel_rates/fuel_rates.py +++ b/domain/fuel_rates/fuel_rates.py @@ -35,7 +35,10 @@ class OffPeakRate: def blended_p_per_kwh(self, high_rate_fraction: float) -> float: """Effective p/kWh for an end use billing ``high_rate_fraction`` of its kWh at the day (high) rate and the remainder at the night (low) rate.""" - raise NotImplementedError + return ( + high_rate_fraction * self.day_p_per_kwh + + (1.0 - high_rate_fraction) * self.night_p_per_kwh + ) @dataclass(frozen=True) @@ -58,7 +61,9 @@ class FuelRates: """Blended day/night p/kWh for an Off-Peak Meter end use at the given High-Rate Fraction. Raises ``UnpricedFuel`` when the snapshot carries no off-peak entry.""" - raise NotImplementedError + if self.off_peak is None: + raise UnpricedFuel(Fuel.ELECTRICITY_OFF_PEAK) + return self.off_peak.blended_p_per_kwh(high_rate_fraction) def unit_rate_p_per_kwh(self, fuel: Fuel) -> float: return self._rate(fuel).unit_rate_p_per_kwh