Skip to content

Commit

Permalink
added SummaryInput to home
Browse files Browse the repository at this point in the history
  • Loading branch information
jkwan2011 committed Nov 8, 2023
1 parent aa0f826 commit cadc25a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 28 deletions.
31 changes: 14 additions & 17 deletions rules-engine/src/rules_engine/engine.py
Original file line number Diff line number Diff line change
@@ -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):

Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions rules-engine/src/rules_engine/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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")
Expand Down
40 changes: 31 additions & 9 deletions rules-engine/tests/test_rules_engine/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit cadc25a

Please sign in to comment.