Skip to content

Commit

Permalink
Fixed issues with balance point differences from test cases
Browse files Browse the repository at this point in the history
Co-authored-by: dwindleduck <[email protected]>
Co-authored-by: Debajyoti Debnath <[email protected]>
Co-authored-by: harry <[email protected]>
Co-authored-by: Alan Pinkert <[email protected]>
Co-authored-by: Jonathan Kwan <[email protected]>
Co-authored-by: David Egan <[email protected]>
Co-authored-by: Tyler Monaghan <[email protected]>
Co-authored-by: Chad Stoughton <[email protected]>
Co-authored-by: thatoldplatitude <[email protected]>
  • Loading branch information
10 people committed Feb 14, 2024
1 parent 97743f4 commit 9629736
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
8 changes: 6 additions & 2 deletions rules-engine/src/rules_engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def _calculate_avg_non_heating_usage(self) -> None:

def _calculate_balance_point_and_ua(
self,
initial_balance_point_sensitivity: float = 2,
initial_balance_point_sensitivity: float = 0.5,
stdev_pct_max: float = 0.10,
max_stdev_pct_diff: float = 0.01,
next_balance_point_sensitivity: float = 0.5,
Expand Down Expand Up @@ -392,6 +392,8 @@ def _calculate_balance_point_and_ua(

self._refine_balance_point(initial_balance_point_sensitivity)

print(self.stdev_pct, stdev_pct_max)

while self.stdev_pct > stdev_pct_max:
outliers = [abs(bill.ua - self.avg_ua) for bill in self.bills_winter]
biggest_outlier = max(outliers)
Expand Down Expand Up @@ -470,12 +472,14 @@ def _refine_balance_point(self, balance_point_sensitivity: float) -> None:
bill.total_hdd = period_hdds_i[n]
bill.ua = uas_i[n]

print(self.balance_point, self.stdev_pct)

if len(directions_to_check) == 2:
directions_to_check.pop(-1)

def calculate(
self,
initial_balance_point_sensitivity: float = 2,
initial_balance_point_sensitivity: float = 0.5,
stdev_pct_max: float = 0.10,
max_stdev_pct_diff: float = 0.01,
next_balance_point_sensitivity: float = 0.5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"thermostat_set_point": 69.0,
"setback_temperature": 62.0,
"setback_hours_per_day": 8.0,
"estimated_balance_point": 56.0,
"estimated_balance_point": 55.5,
"balance_point_sensitivity": 2.0,
"average_indoor_temperature": 66.7,
"difference_between_ti_and_tbp": 10.7,
"difference_between_ti_and_tbp": 11.2,
"design_temperature": 8.4,
"whole_home_heat_loss_rate": 733,
"whole_home_heat_loss_rate": 748,
"standard_deviation_of_heat_loss_rate": 0.0651,
"average_heat_load": 37318,
"maximum_heat_load": 45133
"average_heat_load": 37743,
"maximum_heat_load": 46099
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"thermostat_set_point": 67.0,
"setback_temperature": 63.0,
"setback_hours_per_day": 7.0,
"estimated_balance_point": 61.0,
"estimated_balance_point": 61.5,
"balance_point_sensitivity": 1.0,
"average_indoor_temperature": 65.8,
"difference_between_ti_and_tbp": 4.8,
"difference_between_ti_and_tbp": 4.3,
"design_temperature": 8.4,
"whole_home_heat_loss_rate": 775,
"whole_home_heat_loss_rate": 761,
"standard_deviation_of_heat_loss_rate": 0.0776,
"average_heat_load": 43987,
"maximum_heat_load": 47732
"average_heat_load": 43564,
"maximum_heat_load": 46860
}
13 changes: 6 additions & 7 deletions rules-engine/tests/test_rules_engine/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,12 @@ def test_bp_ua_estimates(sample_summary_inputs, sample_billing_periods):

ua_1, ua_2, ua_3 = [bill.ua for bill in home.bills_winter]

assert home.balance_point == 60
assert ua_1 == approx(1478.50, abs=0.01)
assert ua_2 == approx(1650.00, abs=0.01)
assert ua_3 == approx(1527.78, abs=0.01)
assert home.avg_ua == approx(1552.09, abs=0.01)
assert home.stdev_pct == approx(0.0465, abs=0.01)

assert home.balance_point == 60.5
assert ua_1 == approx(1455.03, abs=0.01)
assert ua_2 == approx(1617.65, abs=0.01)
assert ua_3 == approx(1486.49, abs=0.01)
assert home.avg_ua == approx(1519.72, abs=1)
assert home.stdev_pct == approx(0.0463, abs=0.01)

def test_bp_ua_with_outlier(sample_summary_inputs, sample_billing_periods_with_outlier):
home = engine.Home(
Expand Down
16 changes: 13 additions & 3 deletions rules-engine/tests/test_rules_engine/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,26 @@ def test_average_indoor_temp(data: Example) -> None:
assert data.summary.average_indoor_temperature == approx(avg_indoor_temp, rel=0.01)


def test_get_outputs_natural_gas(data: Example) -> None:
def test_balance_point_natural_gas(data: Example) -> None:
summary_output, balance_point_graph = engine.get_outputs_natural_gas(
data.summary, data.temperature_data, data.natural_gas_usage
)

assert data.summary.estimated_balance_point == approx(
summary_output.estimated_balance_point, abs=0.1
)
assert summary_output.whole_home_heat_loss_rate == approx(data.summary.whole_home_heat_loss_rate, abs=0.01)
assert summary_output.standard_deviation_of_heat_loss_rate == approx(data.summary.standard_deviation_of_heat_loss_rate, abs=0.01)


def test_whole_home_heat_loss_rate_natural_gas(data: Example) -> None:
summary_output, balance_point_graph = engine.get_outputs_natural_gas(
data.summary, data.temperature_data, data.natural_gas_usage
)
assert summary_output.whole_home_heat_loss_rate == approx(data.summary.whole_home_heat_loss_rate, abs=1)

def test_standard_deviation_of_heat_loss_rate_natural_gas(data: Example) -> None:
summary_output, balance_point_graph = engine.get_outputs_natural_gas(
data.summary, data.temperature_data, data.natural_gas_usage
)

assert summary_output.standard_deviation_of_heat_loss_rate == approx(data.summary.standard_deviation_of_heat_loss_rate, abs=0.01)

0 comments on commit 9629736

Please sign in to comment.