Skip to content

Commit

Permalink
Merge branch 'main' into add-billing-record-ua-to-rules-engine-exampl…
Browse files Browse the repository at this point in the history
…e-input
  • Loading branch information
eriksynn authored May 19, 2024
2 parents b88f697 + 3830bed commit e7ac445
Show file tree
Hide file tree
Showing 9 changed files with 465 additions and 98 deletions.
6 changes: 5 additions & 1 deletion heat-stack/app/routes/_heat+/single.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ export async function action({ request, params }: ActionFunctionArgs) {
})

if (submission.status !== 'success') {
console.error("submission failed",submission)

if( process.env.NODE_ENV === "development" ) {
// this can have personal identifying information, so only active in development.
console.error("submission failed", submission)
}
return submission.reply()
// submission.reply({
// // You can also pass additional error to the `reply` method
Expand Down
8 changes: 3 additions & 5 deletions heat-stack/app/utils/GeocodeUtil.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
const BASE_URL = "https://geocoding.geo.census.gov";
const ADDRESS_ENDPOINT = "/geocoder/locations/address";
const ADDRESS_ENDPOINT = "/geocoder/locations/onelineaddress";
const params = new URLSearchParams();

class GeocodeUtil {

/**
*
* @param {*} street
* @param {*} city
* @param {*} state
* @param {*} address
* @returns x,y {x,y} lon/lat. If the given address was valid. I've implemented 0 handling here.
* This is the happiest of paths, with hardcoded values also...
*/
async getLL(address) {
params.append("onelineaddress",address);
params.append("address",address);
params.append("format","json");
params.append("benchmark",2020);

Expand Down
500 changes: 435 additions & 65 deletions heat-stack/app/utils/pyodide.test.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rules-engine/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
9 changes: 1 addition & 8 deletions rules-engine/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rules-engine/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 10 additions & 10 deletions rules-engine/src/rules_engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
):
Expand All @@ -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 = []
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 8 additions & 6 deletions rules-engine/src/rules_engine/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from dataclasses import dataclass
from datetime import date
from enum import Enum
from typing import Annotated, Any, List, Optional, Sequence

from typing import Annotated, Any, Optional, Sequence


from pydantic import BaseModel, BeforeValidator, ConfigDict, Field

Expand Down Expand Up @@ -88,7 +90,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")


Expand Down Expand Up @@ -143,8 +145,8 @@ class NormalizedBillingPeriodRecord(NormalizedBillingPeriodRecordBase):


class TemperatureInput(BaseModel):
dates: List[date]
temperatures: List[float]
dates: list[date]
temperatures: list[float]


class SummaryOutput(BaseModel):
Expand Down Expand Up @@ -184,13 +186,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
Expand Down
2 changes: 1 addition & 1 deletion rules-engine/tests/test_rules_engine/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e7ac445

Please sign in to comment.