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

Issue 253 #260

Merged
merged 2 commits into from
Oct 2, 2024
Merged
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
3 changes: 1 addition & 2 deletions heat-stack/app/utils/pyodide.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ test('pyodide solves climate change', async () => {
}

const executePy = await pyodide.runPythonAsync(`
from datetime import date
from rules_engine import parser
from rules_engine.pydantic_models import (
FuelType,
Expand All @@ -238,7 +237,7 @@ test('pyodide solves climate change', async () => {


summaryInput = SummaryInput(**summaryInputFromJs)
temperatureInput = TemperatureInput(dates=[date.fromisoformat(date_) for date_ in temperatureInputFromJs["dates"]], temperatures=temperatureInputFromJs["temperatures"])
temperatureInput = TemperatureInput(**temperatureInputFromJs)

outputs = engine.get_outputs_natural_gas(summaryInput,temperatureInput, naturalGasInputRecords)

Expand Down
6 changes: 5 additions & 1 deletion rules-engine/src/rules_engine/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,12 @@ class NormalizedBillingPeriodRecord(NormalizedBillingPeriodRecordBase):
whole_home_heat_loss_rate: Optional[float] = Field(frozen=True)


def _date_string_parser(rate: str) -> datetime:
return datetime.strptime(rate, "%Y-%m-%d")


class TemperatureInput(BaseModel):
dates: list[datetime]
dates: list[Annotated[datetime, BeforeValidator(_date_string_parser)]]
temperatures: list[float]


Expand Down
2 changes: 1 addition & 1 deletion rules-engine/tests/test_rules_engine/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def sample_temp_inputs() -> TemperatureInput:

return TemperatureInput(
temperatures=temperature_dict["temperatures"],
dates=[datetime.fromisoformat(x) for x in temperature_dict["dates"]],
dates=temperature_dict["dates"],
)


Expand Down
2 changes: 1 addition & 1 deletion rules-engine/tests/test_rules_engine/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def load_temperature_data(path: Path, weather_station: str) -> TemperatureInput:

row: Any
for row in reader:
dates.append(datetime.strptime(row["Date"], "%Y-%m-%d"))
dates.append(row["Date"])
temperatures.append(row[weather_station])

return TemperatureInput(dates=dates, temperatures=temperatures)
Loading