Skip to content

Commit

Permalink
Refactored return of _refine_balance_point to be a dictionary
Browse files Browse the repository at this point in the history
Co-authored-by: Ethan-Strominger <[email protected]>
  • Loading branch information
AdamFinkle and ethanstrominger committed Dec 20, 2024
1 parent 0edf8e2 commit 7a156cb
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions python/src/rules_engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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
)
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7a156cb

Please sign in to comment.