Skip to content

Commit

Permalink
Continued filling out the summary outputs
Browse files Browse the repository at this point in the history
Co-authored-by: Erika Nesse <[email protected]>
Co-authored-by: Debajyoti Debnath <[email protected]>
Co-authored-by: thatoldplatitude <[email protected]>
Co-authored-by: dwindleduck <[email protected]>
Co-authored-by: mdfasano <[email protected]>
  • Loading branch information
6 people committed Dec 13, 2023
1 parent ec9d5fa commit 53af648
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 39 deletions.
68 changes: 35 additions & 33 deletions rules-engine/src/rules_engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rules_engine.pydantic_models import (
AnalysisType,
BalancePointGraph,
Constants,
DhwInput,
FuelType,
NaturalGasBillingInput,
Expand Down Expand Up @@ -115,35 +116,36 @@ def get_outputs_normalized(
)
home.calculate()

# TODO: rename functions to "get_..." and don't use "_output" suffix
# average_indoor_temperature_output = average_indoor_temp(
# tstat_set=summary_input.thermostat_set_point,
# tstat_setback=summary_input.setback_temperature,
# setback_daily_hrs=summary_input.setback_hours_per_day
# )
# average_heat_load_output = average_heat_load(
# design_set_point=..., # TODO: where does this come from?
# avg_indoor_temp=average_indoor_temperature_output,
# balance_point=home.balance_point,
# design_temp=home.,
# ua,
# )
# maximum_heat_load_output = max_heat_load(...)

# summary_output = SummaryOutput(
# estimated_balance_point=,
# other_fuel_usage=home.avg_non_heating_usage,
# average_indoor_temperature=average_indoor_temperature_output,
# difference_between_ti_and_tbp=,
# design_temperature=,
# whole_home_heat_loss_rate=home.avg_ua,
# standard_deviation_of_heat_loss_rate=home.stdev_pct,
# average_heat_load=,
# maximum_heat_load=,
# )
# return (home.summaryOutput, home.balancePointGraph)
average_indoor_temperature = get_average_indoor_temperature(
thermostat_set_point=summary_input.thermostat_set_point,
setback_temperature=summary_input.setback_temperature,
setback_hours_per_day=summary_input.setback_hours_per_day
)
average_heat_load = get_average_heat_load(
design_set_point=Constants.DESIGN_SET_POINT,
avg_indoor_temp=average_indoor_temperature,
balance_point=home.balance_point,
design_temp=summary_input.design_temperature,
ua=home.avg_ua,
)
maximum_heat_load= get_maximum_heat_load(
design_set_point=Constants.DESIGN_SET_POINT,
design_temp=summary_input.design_temperature,
ua=home.avg_ua)

summary_output = SummaryOutput(
estimated_balance_point=home.balance_point,
other_fuel_usage=home.avg_non_heating_usage,
average_indoor_temperature=average_indoor_temperature,
difference_between_ti_and_tbp=average_indoor_temperature - home.balance_point,
design_temperature=summary_input.design_temperature,
whole_home_heat_loss_rate=home.avg_ua,
standard_deviation_of_heat_loss_rate=home.stdev_pct,
average_heat_load=average_heat_load,
maximum_heat_load=maximum_heat_load,
)
return (summary_output) # TODO: add BalancePointGraph

raise NotImplementedError


def date_to_analysis_type(d: date) -> AnalysisType:
Expand Down Expand Up @@ -193,8 +195,8 @@ def period_hdd(avg_temps: List[float], balance_point: float) -> float:
return sum([hdd(temp, balance_point) for temp in avg_temps])


def average_indoor_temp(
tstat_set: float, tstat_setback: float, setback_daily_hrs: float
def get_average_indoor_temperature(
thermostat_set_point: float, setback_temperature: float, setback_hours_per_day: float
) -> float:
"""
Calculates the average indoor temperature.
Expand All @@ -209,11 +211,11 @@ def average_indoor_temp(
# again, not sure if we should check for valid values here or whether we can
# assume those kinds of checks will be handled at the point of user entry
return (
(24 - setback_daily_hrs) * tstat_set + setback_daily_hrs * tstat_setback
(24 - setback_hours_per_day) * thermostat_set_point + setback_hours_per_day * setback_temperature
) / 24


def average_heat_load(
def get_average_heat_load(
design_set_point: float,
avg_indoor_temp: float,
balance_point: float,
Expand All @@ -237,7 +239,7 @@ def average_heat_load(
return (design_set_point - (avg_indoor_temp - balance_point) - design_temp) * ua


def max_heat_load(design_set_point: float, design_temp: float, ua: float) -> float:
def get_maximum_heat_load(design_set_point: float, design_temp: float, ua: float) -> float:
"""
Calculate the max heat load.
Expand Down
7 changes: 5 additions & 2 deletions rules-engine/src/rules_engine/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from datetime import date
from dataclasses import dataclass
from enum import Enum
from typing import Annotated, Any, List, Optional

Expand Down Expand Up @@ -47,6 +48,7 @@ class SummaryInput(BaseModel):
thermostat_set_point: float = Field(description="Summary!B17")
setback_temperature: Optional[float] = Field(description="Summary!B18")
setback_hours_per_day: Optional[float] = Field(description="Summary!B19")
design_temperature: float = Field(description="TDesign")


class DhwInput(BaseModel):
Expand Down Expand Up @@ -132,6 +134,7 @@ class BalancePointGraph(BaseModel):

records: List[BalancePointGraphRow]


@dataclass
class Constants:
balance_point_sensitivity: float = 0.5
BALANCE_POINT_SENSITIVITY: float = 0.5
DESIGN_SET_POINT: float = 70
10 changes: 7 additions & 3 deletions rules-engine/tests/test_rules_engine/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ def test_period_hdd(temps, expected_result):
assert engine.period_hdd(temps, 60) == expected_result


def test_average_indoor_temp():
def test_get_average_indoor_temperature():
set_temp = 68
setback = 62
setback_hrs = 8

# when there is no setback, just put 0 for the setback parameters
assert engine.average_indoor_temp(set_temp, 0, 0) == set_temp
assert engine.average_indoor_temp(set_temp, setback, setback_hrs) == 66
assert engine.get_average_indoor_temperature(set_temp, 0, 0) == set_temp
assert engine.get_average_indoor_temperature(set_temp, setback, setback_hrs) == 66


def test_bp_ua_estimates():
Expand All @@ -60,13 +60,15 @@ def test_bp_ua_estimates():
setback_temperature = 60
setback_hours_per_day = 8
fuel_type = FuelType.GAS
design_temperature = 60
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,
design_temperature=design_temperature
)

home = engine.Home(
Expand Down Expand Up @@ -103,13 +105,15 @@ def test_bp_ua_with_outlier():
setback_temperature = 60
setback_hours_per_day = 8
fuel_type = FuelType.GAS
design_temperature = 60
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,
design_temperature=design_temperature
)

home = engine.Home(
Expand Down
2 changes: 1 addition & 1 deletion rules-engine/tests/test_rules_engine/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def data(request):


def test_average_indoor_temp(data: Example) -> None:
avg_indoor_temp = engine.average_indoor_temp(
avg_indoor_temp = engine.get_average_indoor_temperature(
data.summary.thermostat_set_point,
data.summary.setback_temperature or 0,
data.summary.setback_hours_per_day or 0,
Expand Down

0 comments on commit 53af648

Please sign in to comment.