From 7a156cb880213cee847808931ee72151889f59bb Mon Sep 17 00:00:00 2001 From: AdamFinkle <77808710+AdamFinkle@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:31:17 -0500 Subject: [PATCH] Refactored return of _refine_balance_point to be a dictionary Co-authored-by: Ethan-Strominger --- python/src/rules_engine/engine.py | 40 +++++++++++++++++++------------ 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/python/src/rules_engine/engine.py b/python/src/rules_engine/engine.py index 1f4a7626..d6776192 100644 --- a/python/src/rules_engine/engine.py +++ b/python/src/rules_engine/engine.py @@ -416,6 +416,7 @@ class Home: avg_non_heating_usage = 0.0 avg_ua = 0.0 stdev_pct = 0.0 + balance_point_graph = BalancePointGraph(records=[]) def _init( self, @@ -558,20 +559,22 @@ def _calculate_balance_point_and_ua( self.balance_point_graph.records.append(balance_point_graph_row) - ( - self.balance_point, - self.avg_ua, - self.stdev_pct, - balance_point_graph_records_extension, - ) = self._refine_balance_point( + results = self._refine_balance_point( balance_point=self.balance_point, - balance_point_sensitivity=initial_balance_point_sensitivity, + balance_point_sensitivity=next_balance_point_sensitivity, avg_ua=self.avg_ua, stdev_pct=self.stdev_pct, thermostat_set_point=self.thermostat_set_point, winter_processed_energy_bills=self.winter_processed_energy_bills, ) + self.balance_point = results["balance_point"] + self.avg_ua = results["avg_ua"] + self.stdev_pct = results["stdev_pct"] + balance_point_graph_records_extension = results[ + "balance_point_graph_records_extension" + ] + self.balance_point_graph.records.extend(balance_point_graph_records_extension) while self.stdev_pct > stdev_pct_max: @@ -607,12 +610,7 @@ def _calculate_balance_point_and_ua( else: self.uas, self.avg_ua, self.stdev_pct = uas_i, avg_ua_i, stdev_pct_i - ( - self.balance_point, - self.avg_ua, - self.stdev_pct, - balance_point_graph_records_extension, - ) = self._refine_balance_point( + results = self._refine_balance_point( balance_point=self.balance_point, balance_point_sensitivity=next_balance_point_sensitivity, avg_ua=self.avg_ua, @@ -621,6 +619,13 @@ def _calculate_balance_point_and_ua( winter_processed_energy_bills=self.winter_processed_energy_bills, ) + self.balance_point = results["balance_point"] + self.avg_ua = results["avg_ua"] + self.stdev_pct = results["stdev_pct"] + balance_point_graph_records_extension = results[ + "balance_point_graph_records_extension" + ] + self.balance_point_graph.records.extend( balance_point_graph_records_extension ) @@ -634,7 +639,7 @@ def _refine_balance_point( stdev_pct: float, thermostat_set_point: float, winter_processed_energy_bills: list[IntermediateEnergyBill], - ) -> None: + ) -> dict[str, float | list[IntermediateEnergyBill]]: """ Tries different balance points plus or minus a given number of degrees, choosing whichever one minimizes the standard @@ -698,7 +703,12 @@ def _refine_balance_point( if len(directions_to_check) == 2: directions_to_check.pop(-1) - return balance_point, avg_ua, stdev_pct, balance_point_graph_records_extension + return { + "balance_point": balance_point, + "avg_ua": avg_ua, + "stdev_pct": stdev_pct, + "balance_point_graph_records_extension": balance_point_graph_records_extension, + } @classmethod def calculate(