Skip to content

Commit

Permalink
Refactor: rename + setup-python.sh
Browse files Browse the repository at this point in the history
1. Renamed to "IntermediateProcessedEnergyBill"
2. Created the "setup-python.sh" file.

Co-authored-by: Ethan-Strominger <[email protected]>
  • Loading branch information
stemgene and ethanstrominger committed Dec 2, 2024
1 parent 84bb5b6 commit 2c5d0b5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
4 changes: 4 additions & 0 deletions python/setup-python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
python -m venv .venv
source .venv/bin/activate
pip install -e .
pip install -r requirements-dev.txt
16 changes: 8 additions & 8 deletions python/src/rules_engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def convert_to_intermediate_billing_periods(
temperature_input: TemperatureInput,
billing_periods: list[ProcessedEnergyBillInput],
fuel_type: FuelType,
) -> list[ProcessedEnergyBillIntermediate]:
) -> list[IntermediateProcessedEnergyBill]:
"""
Converts temperature data and billing period inputs into internal classes used for heat loss calculations.
Expand Down Expand Up @@ -194,7 +194,7 @@ def convert_to_intermediate_billing_periods(
else:
raise ValueError("Unsupported fuel type.")

intermediate_billing_period = ProcessedEnergyBillIntermediate(
intermediate_billing_period = IntermediateProcessedEnergyBill(
input=billing_period,
avg_temps=temperature_input.temperatures[start_idx:end_idx],
usage=billing_period.usage,
Expand Down Expand Up @@ -401,7 +401,7 @@ class Home:
def _init(
self,
heat_load_input: HeatLoadInput,
billing_periods: list[ProcessedEnergyBillIntermediate],
billing_periods: list[IntermediateProcessedEnergyBill],
dhw_input: Optional[DhwInput],
initial_balance_point: float = 60,
) -> None:
Expand All @@ -413,7 +413,7 @@ def _init(
self._initialize_billing_periods(billing_periods)

def _initialize_billing_periods(
self, billing_periods: list[ProcessedEnergyBillIntermediate]
self, billing_periods: list[IntermediateProcessedEnergyBill]
) -> None:
self.bills_winter = []
self.bills_summer = []
Expand Down Expand Up @@ -626,7 +626,7 @@ def _refine_balance_point(self, balance_point_sensitivity: float) -> None:
def calculate(
cls,
heat_load_input: HeatLoadInput,
billing_periods: list[ProcessedEnergyBillIntermediate],
billing_periods: list[IntermediateProcessedEnergyBill],
dhw_input: Optional[DhwInput],
initial_balance_point: float = 60,
initial_balance_point_sensitivity: float = 0.5,
Expand Down Expand Up @@ -656,7 +656,7 @@ def calculate(

return home_instance

def initialize_ua(self, billing_period: ProcessedEnergyBillIntermediate) -> None:
def initialize_ua(self, billing_period: IntermediateProcessedEnergyBill) -> None:
"""
Average heating usage, partial UA, initial UA. requires that
self.home have non heating usage calculated.
Expand All @@ -668,7 +668,7 @@ def initialize_ua(self, billing_period: ProcessedEnergyBillIntermediate) -> None
billing_period.ua = billing_period.partial_ua / billing_period.total_hdd

def calculate_partial_ua(
self, billing_period: ProcessedEnergyBillIntermediate
self, billing_period: IntermediateProcessedEnergyBill
) -> float:
"""
The portion of UA that is not dependent on the balance point
Expand All @@ -684,7 +684,7 @@ def calculate_partial_ua(
)


class ProcessedEnergyBillIntermediate:
class IntermediateProcessedEnergyBill:
"""
An internal class storing data whence heating usage per billing
period is calculated.
Expand Down
4 changes: 2 additions & 2 deletions python/src/rules_engine/refactor.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ home variables used
1. Remove temporary_rules_engine.py
2. Rename rules-engine to "python"
3. Rename NormalizedBillingRecordBase class to BillingInput
4. Rename BillingPeriod to ProcessedEnergyBillIntermediate and billing_period to processed_energy_bill_intermediate
4. Rename BillingPeriod to IntermediateProcessedEnergyBill and billing_period to processed_energy_bill_intermediate
5. Combine get_outputs_normalized and convert_to_intermediate_billing_record and get rid of NormalizedBillingRecord. There is only one place NormalizedBillingRecord is used and combining code
gets rid of the need for the class.
- Change
Expand Down Expand Up @@ -55,7 +55,7 @@ to
inputBill.start_date,
inputBill.end_date
)
processedBill = ProcessedEnergyBillIntermediate(
processedBill = IntermediateProcessedEnergyBill(
input = inputBill,
avg_temps = avg_temps,
default_analysis_type = default_analysis_type
Expand Down
32 changes: 16 additions & 16 deletions python/tests/test_rules_engine/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,33 @@


@pytest.fixture()
def sample_billing_periods() -> list[engine.ProcessedEnergyBillIntermediate]:
def sample_billing_periods() -> list[engine.IntermediateProcessedEnergyBill]:
billing_periods = [
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[28, 29, 30, 29],
50,
AnalysisType.ALLOWED_HEATING_USAGE,
True,
False,
),
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[32, 35, 35, 38],
45,
AnalysisType.ALLOWED_HEATING_USAGE,
True,
False,
),
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[41, 43, 42, 42],
30,
AnalysisType.ALLOWED_HEATING_USAGE,
True,
False,
),
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[72, 71, 70, 69],
0.96,
Expand All @@ -66,42 +66,42 @@ def sample_billing_periods() -> list[engine.ProcessedEnergyBillIntermediate]:

@pytest.fixture()
def sample_billing_periods_with_outlier() -> (
list[engine.ProcessedEnergyBillIntermediate]
list[engine.IntermediateProcessedEnergyBill]
):
billing_periods = [
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[41.7, 41.6, 32, 25.4],
60,
AnalysisType.ALLOWED_HEATING_USAGE,
True,
False,
),
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[28, 29, 30, 29],
50,
AnalysisType.ALLOWED_HEATING_USAGE,
True,
False,
),
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[32, 35, 35, 38],
45,
AnalysisType.ALLOWED_HEATING_USAGE,
True,
False,
),
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[41, 43, 42, 42],
30,
AnalysisType.ALLOWED_HEATING_USAGE,
True,
False,
),
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[72, 71, 70, 69],
0.96,
Expand Down Expand Up @@ -361,39 +361,39 @@ def test_convert_to_intermediate_billing_periods(
)

expected_results = [
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[41.7, 41.6, 32, 25.4],
60,
AnalysisType.ALLOWED_HEATING_USAGE,
False,
False,
),
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[28, 29, 30, 29],
50,
AnalysisType.ALLOWED_HEATING_USAGE,
False,
False,
),
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[32, 35, 35, 38],
45,
AnalysisType.ALLOWED_HEATING_USAGE,
False,
False,
),
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[41, 43, 42, 42],
30,
AnalysisType.ALLOWED_HEATING_USAGE,
False,
False,
),
engine.ProcessedEnergyBillIntermediate(
engine.IntermediateProcessedEnergyBill(
dummy_billing_period_record,
[72, 71, 70, 69],
0.96,
Expand Down

0 comments on commit 2c5d0b5

Please sign in to comment.