mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
62 lines
2.5 KiB
Python
62 lines
2.5 KiB
Python
from __future__ import annotations
|
|
from dataclasses import replace
|
|
from typing import Optional
|
|
|
|
from backend.app.db.models.portfolio import PortfolioGoal
|
|
from backend.app.db.models.recommendations import PlanModel
|
|
from backend.app.domain.classes.scenario import Scenario
|
|
from backend.app.domain.records.plan_record import PlanRecord
|
|
|
|
|
|
class Plan:
|
|
def __init__(
|
|
self, record: PlanRecord, scenario: Scenario, id: Optional[int] = None
|
|
):
|
|
self.id: Optional[int] = id
|
|
self.record: PlanRecord = record
|
|
self.scenario: Scenario = scenario
|
|
|
|
@classmethod
|
|
def from_sqlalchemy(cls, plan_model: PlanModel, scenario: Scenario) -> Plan:
|
|
if not scenario:
|
|
raise ValueError(f"No Scenario associated with Plan of ID {plan_model.id}")
|
|
|
|
record = PlanRecord(
|
|
property_id=plan_model.property_id,
|
|
portfolio_id=plan_model.portfolio_id,
|
|
created_at=plan_model.created_at,
|
|
is_default=plan_model.is_default,
|
|
valuation_increase_lower_bound=plan_model.valuation_increase_lower_bound,
|
|
valuation_increase_upper_bound=plan_model.valuation_increase_upper_bound,
|
|
valuation_increase_average=plan_model.valuation_increase_average,
|
|
plan_type=plan_model.plan_type,
|
|
post_sap_points=plan_model.post_sap_points,
|
|
post_epc_rating=plan_model.post_epc_rating,
|
|
post_co2_emissions=plan_model.post_co2_emissions,
|
|
co2_savings=plan_model.co2_savings,
|
|
post_energy_bill=plan_model.post_energy_bill,
|
|
energy_bill_savings=plan_model.energy_bill_savings,
|
|
post_energy_consumption=plan_model.post_energy_consumption,
|
|
energy_consumption_savings=plan_model.energy_consumption_savings,
|
|
valuation_post_retrofit=plan_model.valuation_post_retrofit,
|
|
valuation_increase=plan_model.valuation_increase,
|
|
cost_of_works=plan_model.cost_of_works,
|
|
contingency_cost=plan_model.contingency_cost,
|
|
)
|
|
return cls(record=record, scenario=scenario, id=plan_model.id)
|
|
|
|
@property
|
|
def is_compliant(self) -> bool:
|
|
raise NotImplementedError
|
|
|
|
goal: PortfolioGoal = self.scenario.record.goal
|
|
goal_value: str = self.scenario.record.goal_value
|
|
|
|
match goal:
|
|
case PortfolioGoal.INCREASING_EPC:
|
|
return True
|
|
case _:
|
|
raise NotImplementedError
|
|
|
|
def set_default(self, value: bool) -> None:
|
|
self.record = replace(self.record, is_default=value)
|