From 5cc03df0b142466376275404577c387c3a447c7c Mon Sep 17 00:00:00 2001 From: Debajyoti Debnath Date: Wed, 15 May 2024 19:31:33 -0400 Subject: [PATCH 1/3] Modify python version to 3.11.3 in pyproject.toml. --- rules-engine/pyproject.toml | 2 +- rules-engine/requirements-dev.txt | 9 +-------- rules-engine/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/rules-engine/pyproject.toml b/rules-engine/pyproject.toml index b6a3c442..2c6e66f1 100644 --- a/rules-engine/pyproject.toml +++ b/rules-engine/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name="rules-engine" version="0.0.1" -requires-python=">=3.8" +requires-python=">=3.11.3" dependencies = [ "pydantic" ] diff --git a/rules-engine/requirements-dev.txt b/rules-engine/requirements-dev.txt index 039ada18..b8ca940d 100644 --- a/rules-engine/requirements-dev.txt +++ b/rules-engine/requirements-dev.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile --extra=dev --output-file=requirements-dev.txt pyproject.toml @@ -10,8 +10,6 @@ black==23.3.0 # via rules-engine (pyproject.toml) click==8.1.3 # via black -exceptiongroup==1.1.1 - # via pytest iniconfig==2.0.0 # via pytest isort==5.12.0 @@ -42,11 +40,6 @@ pytest==7.3.2 # via rules-engine (pyproject.toml) snowballstemmer==2.2.0 # via pydocstyle -tomli==2.0.1 - # via - # black - # mypy - # pytest typing-extensions==4.6.3 # via # mypy diff --git a/rules-engine/requirements.txt b/rules-engine/requirements.txt index dff10bbb..2afeaaa2 100644 --- a/rules-engine/requirements.txt +++ b/rules-engine/requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile pyproject.toml From fbf03a0b27498d857a21066145a93d40ddde97e1 Mon Sep 17 00:00:00 2001 From: Debajyoti Debnath Date: Wed, 15 May 2024 19:42:18 -0400 Subject: [PATCH 2/3] Replace List with list in type annotations. --- rules-engine/src/rules_engine/engine.py | 20 +++++++++---------- .../src/rules_engine/pydantic_models.py | 14 ++++++------- .../tests/test_rules_engine/test_examples.py | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/rules-engine/src/rules_engine/engine.py b/rules-engine/src/rules_engine/engine.py index f09be7d5..6966af7b 100644 --- a/rules-engine/src/rules_engine/engine.py +++ b/rules-engine/src/rules_engine/engine.py @@ -6,7 +6,7 @@ import bisect import statistics as sts from datetime import date, timedelta -from typing import Any, List, Optional, Tuple +from typing import Any, Optional from rules_engine.pydantic_models import ( AnalysisType, @@ -35,7 +35,7 @@ def get_outputs_oil_propane( """ Analyze the heat load for a home that is using oil or propane as its current heating system fuel. """ - billing_periods: List[NormalizedBillingPeriodRecordBase] = [] + billing_periods: list[NormalizedBillingPeriodRecordBase] = [] last_date = oil_propane_billing_input.preceding_delivery_date for input_val in oil_propane_billing_input.records: @@ -69,7 +69,7 @@ def get_outputs_natural_gas( """ Analyze the heat load for a home that is using natural gas as its current heating system fuel. """ - billing_periods: List[NormalizedBillingPeriodRecordBase] = [] + billing_periods: list[NormalizedBillingPeriodRecordBase] = [] for input_val in natural_gas_billing_input.records: billing_periods.append( @@ -91,7 +91,7 @@ def get_outputs_normalized( summary_input: SummaryInput, dhw_input: Optional[DhwInput], temperature_input: TemperatureInput, - billing_periods: List[NormalizedBillingPeriodRecordBase], + billing_periods: list[NormalizedBillingPeriodRecordBase], ) -> RulesEngineResult: """ Analyze the heat load for a home based on normalized, fuel-type-agnostic billing records. @@ -171,8 +171,8 @@ def get_outputs_normalized( def convert_to_intermediate_billing_periods( temperature_input: TemperatureInput, - billing_periods: List[NormalizedBillingPeriodRecordBase], -) -> List[BillingPeriod]: + billing_periods: list[NormalizedBillingPeriodRecordBase], +) -> list[BillingPeriod]: """ Converts temperature data and billing period inputs into internal classes used for heat loss calculations. @@ -243,7 +243,7 @@ def hdd(avg_temp: float, balance_point: float) -> float: return max(0, balance_point - avg_temp) -def period_hdd(avg_temps: List[float], balance_point: float) -> float: +def period_hdd(avg_temps: list[float], balance_point: float) -> float: """ Sum up total heating degree days in a given time period for a given home. @@ -364,7 +364,7 @@ class Home: def __init__( self, summary_input: SummaryInput, - billing_periods: List[BillingPeriod], + billing_periods: list[BillingPeriod], dhw_input: Optional[DhwInput], initial_balance_point: float = 60, ): @@ -375,7 +375,7 @@ def __init__( self.dhw_input = dhw_input self._initialize_billing_periods(billing_periods) - def _initialize_billing_periods(self, billing_periods: List[BillingPeriod]) -> None: + def _initialize_billing_periods(self, billing_periods: list[BillingPeriod]) -> None: self.bills_winter = [] self.bills_summer = [] self.bills_shoulder = [] @@ -608,7 +608,7 @@ class BillingPeriod: def __init__( self, input: NormalizedBillingPeriodRecordBase, - avg_temps: List[float], + avg_temps: list[float], usage: float, analysis_type: AnalysisType, ) -> None: diff --git a/rules-engine/src/rules_engine/pydantic_models.py b/rules-engine/src/rules_engine/pydantic_models.py index 908961e0..d65e5a0f 100644 --- a/rules-engine/src/rules_engine/pydantic_models.py +++ b/rules-engine/src/rules_engine/pydantic_models.py @@ -5,7 +5,7 @@ from dataclasses import dataclass from datetime import date from enum import Enum -from typing import Annotated, Any, List, Optional +from typing import Annotated, Any, Optional from pydantic import BaseModel, BeforeValidator, ConfigDict, Field @@ -88,7 +88,7 @@ class OilPropaneBillingRecordInput(BaseModel): class OilPropaneBillingInput(BaseModel): """From Oil-Propane tab. Container for holding all rows of the billing input table.""" - records: List[OilPropaneBillingRecordInput] + records: list[OilPropaneBillingRecordInput] preceding_delivery_date: date = Field(description="Oil-Propane!B6") @@ -104,7 +104,7 @@ class NaturalGasBillingRecordInput(BaseModel): class NaturalGasBillingInput(BaseModel): """From Natural Gas tab. Container for holding all rows of the billing input table.""" - records: List[NaturalGasBillingRecordInput] + records: list[NaturalGasBillingRecordInput] class NormalizedBillingPeriodRecordBase(BaseModel): @@ -143,8 +143,8 @@ class NormalizedBillingPeriodRecord(NormalizedBillingPeriodRecordBase): class TemperatureInput(BaseModel): - dates: List[date] - temperatures: List[float] + dates: list[date] + temperatures: list[float] class SummaryOutput(BaseModel): @@ -184,13 +184,13 @@ class BalancePointGraphRow(BaseModel): class BalancePointGraph(BaseModel): """From Summary page""" - records: List[BalancePointGraphRow] + records: list[BalancePointGraphRow] class RulesEngineResult(BaseModel): summary_output: SummaryOutput balance_point_graph: BalancePointGraph - billing_records: List[NormalizedBillingPeriodRecord] + billing_records: list[NormalizedBillingPeriodRecord] @dataclass diff --git a/rules-engine/tests/test_rules_engine/test_examples.py b/rules-engine/tests/test_rules_engine/test_examples.py index 595a889c..cab80ee8 100644 --- a/rules-engine/tests/test_rules_engine/test_examples.py +++ b/rules-engine/tests/test_rules_engine/test_examples.py @@ -3,7 +3,7 @@ import os import pathlib from datetime import date, datetime, timedelta -from typing import Any, List, Literal, Optional +from typing import Any, Literal, Optional import pytest from pydantic import BaseModel From 9cbff0ecafb766e4cdffc00e67cd13469c4548f7 Mon Sep 17 00:00:00 2001 From: Debajyoti Debnath Date: Wed, 15 May 2024 19:45:51 -0400 Subject: [PATCH 3/3] Change mixin of str and Enum to StrEnum in NaturalGasCompany. --- rules-engine/src/rules_engine/parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules-engine/src/rules_engine/parser.py b/rules-engine/src/rules_engine/parser.py index 93e89ac8..54aff093 100644 --- a/rules-engine/src/rules_engine/parser.py +++ b/rules-engine/src/rules_engine/parser.py @@ -5,12 +5,12 @@ import csv import io from datetime import datetime, timedelta -from enum import Enum +from enum import StrEnum from .pydantic_models import NaturalGasBillingInput, NaturalGasBillingRecordInput -class NaturalGasCompany(str, Enum): +class NaturalGasCompany(StrEnum): EVERSOURCE = "eversource" NATIONAL_GRID = "national_grid"