Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated test_engine to use JSON inputs #130

Merged
merged 6 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions rules-engine/src/rules_engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ def get_outputs_normalized(
maximum_heat_load=maximum_heat_load,
)

# TODO: fill out balance point graph
balance_point_graph = BalancePointGraph(records=[])
balance_point_graph = home.balance_point_graph
return (summary_output, balance_point_graph)


Expand Down Expand Up @@ -314,9 +313,9 @@ def _initialize_billing_periods(self, billing_periods: List[BillingPeriod]) -> N
if billing_period.analysis_type == AnalysisType.INCLUDE:
self.bills_winter.append(billing_period)
elif billing_period.analysis_type == AnalysisType.DO_NOT_INCLUDE:
self.bills_summer.append(billing_period)
else:
self.bills_shoulder.append(billing_period)
else:
self.bills_summer.append(billing_period)

self._calculate_avg_summer_usage()
self._calculate_avg_non_heating_usage()
Expand Down Expand Up @@ -374,9 +373,23 @@ def _calculate_balance_point_and_ua(
the home, removing UA outliers based on a normalized standard
deviation threshold.
"""
self.uas = [bp.ua for bp in self.bills_winter]

self.balance_point_graph = BalancePointGraph(records=[])

self.uas = [billing_period.ua for billing_period in self.bills_winter]
self.avg_ua = sts.mean(self.uas)
self.stdev_pct = sts.pstdev(self.uas) / self.avg_ua

balance_point_graph_row = BalancePointGraphRow(
balance_point=self.balance_point,
heat_loss_rate=self.avg_ua,
change_in_heat_loss_rate=0,
percent_change_in_heat_loss_rate=0,
standard_deviation=self.stdev_pct,
)

self.balance_point_graph.records.append(balance_point_graph_row)

self._refine_balance_point(initial_balance_point_sensitivity)

while self.stdev_pct > stdev_pct_max:
Expand All @@ -386,7 +399,7 @@ def _calculate_balance_point_and_ua(
outlier = self.bills_winter.pop(
biggest_outlier_idx
) # removes the biggest outlier
uas_i = [bp.ua for bp in self.bills_winter]
uas_i = [billing_period.ua for billing_period in self.bills_winter]
avg_ua_i = sts.mean(uas_i)
stdev_pct_i = sts.pstdev(uas_i) / avg_ua_i
if (
Expand Down Expand Up @@ -433,12 +446,26 @@ def _refine_balance_point(self, balance_point_sensitivity: float) -> None:
# TODO: For balance point graph, store the old balance
# point in a list to keep track of all intermediate balance
# point temperatures?

change_in_heat_loss_rate = avg_ua_i - self.avg_ua
percent_change_in_heat_loss_rate = (
100 * change_in_heat_loss_rate / avg_ua_i
)
self.balance_point, self.avg_ua, self.stdev_pct = (
bp_i,
avg_ua_i,
stdev_pct_i,
)

balance_point_graph_row = BalancePointGraphRow(
balance_point=self.balance_point,
heat_loss_rate=self.avg_ua,
change_in_heat_loss_rate=change_in_heat_loss_rate,
percent_change_in_heat_loss_rate=percent_change_in_heat_loss_rate,
standard_deviation=self.stdev_pct,
)
self.balance_point_graph.records.append(balance_point_graph_row)

for n, bill in enumerate(self.bills_winter):
bill.total_hdd = period_hdds_i[n]
bill.ua = uas_i[n]
Expand Down Expand Up @@ -483,10 +510,12 @@ def calculate_partial_ua(self, billing_period: BillingPeriod) -> float:
"""
return (
billing_period.days
* billing_period.avg_heating_usage
* self.fuel_type.value
* self.heat_sys_efficiency
* billing_period.avg_heating_usage # gallons or therms
* self.fuel_type.value # therm or gallon to BTU
* self.heat_sys_efficiency # unitless
/ 24
# days * gallons/day * (BTU/gallon)/1 day (24 hours)
# BTUs/hour
)


Expand Down
12 changes: 8 additions & 4 deletions rules-engine/src/rules_engine/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ class SummaryOutput(BaseModel):
design_temperature: float = Field(description="Summary!B26")
whole_home_heat_loss_rate: float = Field(
description="Summary!B27"
) # UA = heat loss rate
standard_deviation_of_heat_loss_rate: float = Field(description="Summary!B28")
) # Whole Home UA. UA = heat loss rate
standard_deviation_of_heat_loss_rate: float = Field(
description="Summary!B28"
) # Standard deviation of UA
average_heat_load: float = Field(description="Summary!B29")
maximum_heat_load: float = Field(description="Summary!B30")

Expand All @@ -123,10 +125,12 @@ class BalancePointGraphRow(BaseModel):
"""From Summary page"""

balance_point: float = Field(description="Summary!G33:35") # degree F
heat_loss_rate: float = Field(description="Summary!H33:35") # BTU / (hr-deg. F)
heat_loss_rate: float = Field(
description="Summary!H33:35"
) # BTU / (hr-deg. F) (UA)
change_in_heat_loss_rate: float = Field(
description="Summary!I33:35"
) # BTU / (hr-deg. F)
) # BTU / (hr-deg. F) (change in UA)
percent_change_in_heat_loss_rate: float = Field(description="Summary!J33:35")
standard_deviation: float = Field(description="Summary!K33:35")

Expand Down
Loading
Loading