Blend an off-peak meter's day/night rate by high-rate fraction 🟩

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-06-24 17:09:59 +00:00
parent 4641717c90
commit af2e8b3843

View file

@ -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