From 9629736e24b6c010159b93dfa456169b17bfe221 Mon Sep 17 00:00:00 2001 From: Erika Nesse Date: Wed, 14 Feb 2024 01:28:19 +0000 Subject: [PATCH] Fixed issues with balance point differences from test cases Co-authored-by: dwindleduck Co-authored-by: Debajyoti Debnath Co-authored-by: harry Co-authored-by: Alan Pinkert Co-authored-by: Jonathan Kwan Co-authored-by: David Egan Co-authored-by: Tyler Monaghan Co-authored-by: Chad Stoughton Co-authored-by: thatoldplatitude --- rules-engine/src/rules_engine/engine.py | 8 ++++++-- .../cases/examples/cali/summary.json | 10 +++++----- .../cases/examples/feldman/summary.json | 10 +++++----- .../tests/test_rules_engine/test_engine.py | 13 ++++++------- .../tests/test_rules_engine/test_examples.py | 16 +++++++++++++--- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/rules-engine/src/rules_engine/engine.py b/rules-engine/src/rules_engine/engine.py index 8e43e156..9e5a1622 100644 --- a/rules-engine/src/rules_engine/engine.py +++ b/rules-engine/src/rules_engine/engine.py @@ -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, @@ -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) @@ -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, diff --git a/rules-engine/tests/test_rules_engine/cases/examples/cali/summary.json b/rules-engine/tests/test_rules_engine/cases/examples/cali/summary.json index 119d4de8..d64361d9 100644 --- a/rules-engine/tests/test_rules_engine/cases/examples/cali/summary.json +++ b/rules-engine/tests/test_rules_engine/cases/examples/cali/summary.json @@ -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 } \ No newline at end of file diff --git a/rules-engine/tests/test_rules_engine/cases/examples/feldman/summary.json b/rules-engine/tests/test_rules_engine/cases/examples/feldman/summary.json index 0ad73aea..a2cc9d1b 100644 --- a/rules-engine/tests/test_rules_engine/cases/examples/feldman/summary.json +++ b/rules-engine/tests/test_rules_engine/cases/examples/feldman/summary.json @@ -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 } \ No newline at end of file diff --git a/rules-engine/tests/test_rules_engine/test_engine.py b/rules-engine/tests/test_rules_engine/test_engine.py index 06b2c70d..e1404930 100644 --- a/rules-engine/tests/test_rules_engine/test_engine.py +++ b/rules-engine/tests/test_rules_engine/test_engine.py @@ -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( diff --git a/rules-engine/tests/test_rules_engine/test_examples.py b/rules-engine/tests/test_rules_engine/test_examples.py index 16909c77..5de6a3d3 100644 --- a/rules-engine/tests/test_rules_engine/test_examples.py +++ b/rules-engine/tests/test_rules_engine/test_examples.py @@ -112,7 +112,7 @@ 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 ) @@ -120,8 +120,18 @@ def test_get_outputs_natural_gas(data: Example) -> None: 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)