diff --git a/rules-engine/src/rules_engine/engine.py b/rules-engine/src/rules_engine/engine.py index 027846c2..4d34b082 100644 --- a/rules-engine/src/rules_engine/engine.py +++ b/rules-engine/src/rules_engine/engine.py @@ -1,11 +1,19 @@ from __future__ import annotations import statistics as sts -from enum import Enum from typing import List, Optional import numpy as np -from rules_engine.pydantic_models import SummaryInput, DhwInput, NaturalGasBillingInput, SummaryOutput, BalancePointGraph + +from rules_engine.pydantic_models import ( + BalancePointGraph, + DhwInput, + FuelType, + NaturalGasBillingInput, + SummaryInput, + SummaryOutput, +) + def getOutputsNaturalGas(summaryInput: SummaryInput, dhwInput: Optional[DhwInput], naturalGasBillingInput: NaturalGasBillingInput)->(SummaryOutput, BalancePointGraph): @@ -101,15 +109,6 @@ def max_heat_load(design_set_point: float, design_temp: float, ua: float) -> flo """ return (design_set_point - design_temp) * ua - -class FuelType(Enum): - """Enum for fuel types. Values are BTU per usage""" - - GAS = 100000 - OIL = 139600 - PROPANE = 91333 - - class Home: """ Defines attributes and methods for calculating home heat metrics. @@ -122,20 +121,18 @@ class Home: def __init__( self, - fuel_type: FuelType, - heat_sys_efficiency: float, + summary_input: SummaryInput, temps: List[List[float]], usages: List[float], inclusion_codes: List[int], initial_balance_point: float = 60, - thermostat_set_point: float = 68, has_boiler_for_dhw: bool = False, same_fuel_dhw_heating: bool = False, ): - self.fuel_type = fuel_type - self.heat_sys_efficiency = heat_sys_efficiency + self.fuel_type = summary_input.fuel_type + self.heat_sys_efficiency = summary_input.heating_system_efficiency + self.thermostat_set_point = summary_input.thermostat_set_point self.balance_point = initial_balance_point - self.thermostat_set_point = thermostat_set_point self.has_boiler_for_dhw = has_boiler_for_dhw self.same_fuel_dhw_heating = same_fuel_dhw_heating self._initialize_billing_periods(temps, usages, inclusion_codes) diff --git a/rules-engine/src/rules_engine/pydantic_models.py b/rules-engine/src/rules_engine/pydantic_models.py index e39f59bc..37ee0362 100644 --- a/rules-engine/src/rules_engine/pydantic_models.py +++ b/rules-engine/src/rules_engine/pydantic_models.py @@ -2,10 +2,11 @@ Data models for input and output data in the rules engine. """ +from datetime import date from enum import Enum from typing import List, Optional + from pydantic import BaseModel, Field -from datetime import date class FuelType(Enum): @@ -17,7 +18,7 @@ class FuelType(Enum): class SummaryInput(BaseModel): """From Summary Tab""" - design_temperature: float + #design_temperature_override: float living_area: float = Field(description="Summary!B10") fuel_type: FuelType = Field(description="Summary!B11") heating_system_efficiency: float = Field(description="Summary!B12") diff --git a/rules-engine/tests/test_rules_engine/test_engine.py b/rules-engine/tests/test_rules_engine/test_engine.py index 0732d886..e31942ab 100644 --- a/rules-engine/tests/test_rules_engine/test_engine.py +++ b/rules-engine/tests/test_rules_engine/test_engine.py @@ -2,6 +2,14 @@ from pytest import approx from rules_engine import engine +from rules_engine.pydantic_models import ( + BalancePointGraph, + DhwInput, + FuelType, + NaturalGasBillingInput, + SummaryInput, + SummaryOutput, +) @pytest.mark.parametrize( @@ -49,13 +57,20 @@ def test_bp_ua_estimates(): usages = [50, 45, 30, 0.96] inclusion_codes = [1, 1, 1, -1] heat_sys_efficiency = 0.88 + living_area = 1000 + thermostat_set_point = 68 + setback_temperature = 60 + setback_hours_per_day = 8 + fuel_type = FuelType.GAS + summary_input = SummaryInput(living_area=living_area, fuel_type=fuel_type, heating_system_efficiency=heat_sys_efficiency, thermostat_set_point=thermostat_set_point, setback_temperature=setback_temperature,setback_hours_per_day=setback_hours_per_day) + + home = engine.Home( - engine.FuelType.GAS,heat_sys_efficiency,daily_temps_lists, usages, inclusion_codes, initial_balance_point=58 + summary_input, daily_temps_lists, usages, inclusion_codes, initial_balance_point=58 ) - #home.initialize_billing_periods(daily_temps_lists, usages, inclusion_codes) - #home.calculate_avg_non_heating_usage() - #home.calculate_balance_point_and_ua() + + home.calculate() ua_1, ua_2, ua_3 = [bill.ua for bill in home.bills_winter] @@ -80,14 +95,21 @@ def test_bp_ua_with_outlier(): ] usages = [60, 50, 45, 30, 0.96] inclusion_codes = [1, 1, 1, 1, -1] - heat_sys_efficiency=0.88 + heat_sys_efficiency = 0.88 + + living_area = 1000 + thermostat_set_point = 68 + setback_temperature = 60 + setback_hours_per_day = 8 + fuel_type = FuelType.GAS + summary_input = SummaryInput(living_area=living_area, fuel_type=fuel_type, heating_system_efficiency=heat_sys_efficiency, thermostat_set_point=thermostat_set_point, setback_temperature=setback_temperature,setback_hours_per_day=setback_hours_per_day) + + home = engine.Home( - engine.FuelType.GAS,heat_sys_efficiency,daily_temps_lists, usages, inclusion_codes, initial_balance_point=58 + summary_input, daily_temps_lists, usages, inclusion_codes, initial_balance_point=58 ) - # home.initialize_billing_periods(daily_temps_lists, usages, inclusion_codes) - # home.calculate_avg_non_heating_usage() - # home.calculate_balance_point_and_ua() + home.calculate() ua_1, ua_2, ua_3 = [bill.ua for bill in home.bills_winter]