Skip to content

Commit

Permalink
fixed mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
alanisaac committed Jul 31, 2024
1 parent 2cf39de commit 891c292
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rules-engine/src/rules_engine/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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: Sequence[OilPropaneBillingRecordInput]
preceding_delivery_date: date = Field(description="Oil-Propane!B6")


Expand Down
2 changes: 1 addition & 1 deletion rules-engine/tests/test_rules_engine/test_fuel_oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def load_summary(folder: str) -> Summary:
return Summary(**data)


def test_get_outputs_oil_propane(data: Example):
def test_get_outputs_oil_propane(data: Example) -> None:
rezzy = engine.get_outputs_oil_propane(
data.summary,
None,
Expand Down
24 changes: 13 additions & 11 deletions rules-engine/tests/test_rules_engine/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import csv
from datetime import date, datetime, timedelta
from pathlib import Path
from typing import Any
from typing import Any, Sequence

from rules_engine.pydantic_models import (
FuelType,
Expand Down Expand Up @@ -43,7 +43,7 @@ class NaturalGasBillingExampleInput(NaturalGasBillingInput):
otherwise intuitively used, and which is used in production.
"""

records: list[NaturalGasBillingRecordExampleInput]
records: Sequence[NaturalGasBillingRecordExampleInput]


class OilPropaneBillingRecordExampleInput(OilPropaneBillingRecordInput):
Expand All @@ -63,8 +63,7 @@ class OilPropaneBillingExampleInput(OilPropaneBillingInput):
otherwise intuitively used, and which is used in production.
"""

records: list[OilPropaneBillingRecordExampleInput]

records: Sequence[OilPropaneBillingRecordExampleInput]

def load_fuel_billing_example_input(
folder: Path, fuel_type: FuelType, estimated_balance_point: float
Expand All @@ -84,11 +83,12 @@ def load_fuel_billing_example_input(
match fuel_type:
case FuelType.GAS:
file_name = "natural-gas.csv"
case FuelType.OIL:
case FuelType.OIL | FuelType.PROPANE:
file_name = "oil-propane.csv"
case _:
raise ValueError("Unsupported fuel type.")

records = []
preceding_delivery_date = None
records: list[Any] = []
with open(folder / file_name) as f:
reader = csv.DictReader(f)
row: Any
Expand Down Expand Up @@ -129,27 +129,27 @@ def load_fuel_billing_example_input(
whole_home_heat_loss_rate = 0

if fuel_type == FuelType.GAS:
item = NaturalGasBillingRecordExampleInput(
natural_gas_item = NaturalGasBillingRecordExampleInput(
period_start_date=_parse_date(row["start_date"]),
period_end_date=_parse_date(row["end_date"]),
usage_therms=row["usage"],
inclusion_override=inclusion_override,
whole_home_heat_loss_rate=whole_home_heat_loss_rate,
)
records.append(item)
records.append(natural_gas_item)
elif fuel_type == FuelType.OIL:
if i == 0:
preceding_delivery_date = _parse_date(
row["start_date"]
) - timedelta(days=1)

item = OilPropaneBillingRecordExampleInput(
oil_propane_item = OilPropaneBillingRecordExampleInput(
period_end_date=_parse_date(row["end_date"]),
gallons=row["usage"],
inclusion_override=inclusion_override,
whole_home_heat_loss_rate=whole_home_heat_loss_rate,
)
records.append(item)
records.append(oil_propane_item)
else:
raise ValueError("Unsupported fuel type.")

Expand All @@ -159,6 +159,8 @@ def load_fuel_billing_example_input(
return OilPropaneBillingExampleInput(
records=records, preceding_delivery_date=preceding_delivery_date
)
else:
raise ValueError("Unsupported fuel type.")


def _parse_date(value: str) -> date:
Expand Down

0 comments on commit 891c292

Please sign in to comment.