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

Suggested logic changes around Inclusion and AnalysisType #155

Closed
Closed
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
51 changes: 51 additions & 0 deletions rules-engine/src/rules_engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,53 @@ def _initialize_billing_periods(self, billing_periods: List[BillingPeriod]) -> N
self.bills_summer = []
self.bills_shoulder = []


# #####
# Logic Change:
# 'Inclusion' in calculations is now determined by two variables:
# billing_period.inclusion_calculated: bool
# billing_period.inclusion_override: bool (False by default)
#
# Our logic around the AnalysisType can now disallow
# a billing_period from being included or overridden
# by marking it as NOT_ALLOWED_IN_CALCULATIONS
#
# Options for billing_period.analysis_type:
# ALLOWED_HEATING_USAGE = 1 # winter months - allowed in heating usage calculations
# ALLOWED_NON_HEATING_USAGE = -1 # summer months - allowed in non-heating usage calculations
# NOT_ALLOWED_IN_CALCULATIONS = 0 # shoulder months that fall outside reasonable bounds
#
# Use HDDs to determine if shoulder months
Copy link
Collaborator

@stevebreit stevebreit Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I proposed the approach of using HDDs during a March hackathon discussion, but let's defer implementing it until after the MVP release. A change like this could make it difficult to verify the Rules Engine vs. the original spreadsheet.

# are heating or non-heating or not allowed,
# or included or excluded
#
# Rough calculations from Steve, this will be ammended:
# IF hdds is within 70% or higher of max, allowed
# less than 25% of max, not allowed
#
#
# IF winter months
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the table in this Google sheet. The column headings map to variable names in the pseudo code as follows: Column B maps to analysis_type and column C maps to inclusion_calculated. As mentioned in my previous comment, the table lookup approach should be used for all months, i.e. don't use the hdd-based algorithm for shoulder months.

# analysis_type = ALLOWED_HEATING_USAGE
# inclusion_calculated = True
# ELSE IF summer months
# analysis_type = ALLOWED_NON_HEATING_USAGE
# inclusion_calculated = True
# ELSE IF shoulder months
# IF hdds < 25% || hdds > 70%
# analysis_type = NOT_ALLOWED_IN_CALCULATIONS
# inclusion_calculated = False
# IF 25% < hdds < 50%
# analysis_type = ALLOWED_NON_HEATING_USAGE
# inclusion_calculated = False
# IF 50% < hdds < 70%
# analysis_type = ALLOWED_HEATING_USAGE
# inclusion_calculated = False
#
#
# #####



# winter months 1; summer months -1; shoulder months 0
for billing_period in billing_periods:
billing_period.set_initial_balance_point(self.balance_point)
Expand Down Expand Up @@ -545,10 +592,14 @@ def __init__(
avg_temps: List[float],
usage: float,
analysis_type: AnalysisType,
# inclusion_calculated: bool
# inclusion_override: bool
) -> None:
self.avg_temps = avg_temps
self.usage = usage
self.analysis_type = analysis_type
# self.inclusion_calculated: inclusion_calculated
# self.inclusion_override: inclusion_override
self.days = len(self.avg_temps)

def set_initial_balance_point(self, balance_point: float) -> None:
Expand Down
23 changes: 21 additions & 2 deletions rules-engine/src/rules_engine/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,21 @@


class AnalysisType(Enum):
DO_NOT_INCLUDE = 0
"""Enum for analysis type.

'Inclusion' in calculations is now determined by
the inclusion_calculated and inclusion_override variables

Use HDDs to determine if shoulder months
are heating or non-heating or not allowed,
or included or excluded
"""

# ALLOWED_HEATING_USAGE = 1 # winter months - allowed in heating usage calculations
# ALLOWED_NON_HEATING_USAGE = -1 # summer months - allowed in non-heating usage calculations
# NOT_ALLOWED_IN_CALCULATIONS = 0 # shoulder months that fall outside reasonable bounds

DO_NOT_INCLUDE = 0
INCLUDE = 1
INCLUDE_IN_OTHER_ANALYSIS = -1

Expand Down Expand Up @@ -93,7 +107,12 @@ class NormalizedBillingPeriodRecordInput(BaseModel):
period_start_date: date
period_end_date: date
usage: float
inclusion_override: Optional[AnalysisType]
inclusion_override: Optional[AnalysisType]

#change the logic here
# analysis_type: Optional[AnalysisType]
# inclusion_calculated: bool
# inclusion_override: False # by default do not override the rules-engine's choices


class TemperatureInput(BaseModel):
Expand Down
Loading