mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
set up recommendation structure for mds
This commit is contained in:
parent
332393a4fc
commit
f91cbec883
2 changed files with 165 additions and 0 deletions
|
|
@ -35,6 +35,7 @@ from recommendations.optimiser.CostOptimiser import CostOptimiser
|
||||||
from recommendations.optimiser.GainOptimiser import GainOptimiser
|
from recommendations.optimiser.GainOptimiser import GainOptimiser
|
||||||
from recommendations.optimiser.optimiser_functions import prepare_input_measures
|
from recommendations.optimiser.optimiser_functions import prepare_input_measures
|
||||||
from recommendations.Recommendations import Recommendations
|
from recommendations.Recommendations import Recommendations
|
||||||
|
from recommendations.Mds import Mds
|
||||||
from utils.logger import setup_logger
|
from utils.logger import setup_logger
|
||||||
from utils.s3 import read_dataframe_from_s3_parquet, read_csv_from_s3
|
from utils.s3 import read_dataframe_from_s3_parquet, read_csv_from_s3
|
||||||
from backend.ml_models.Valuation import PropertyValuation
|
from backend.ml_models.Valuation import PropertyValuation
|
||||||
|
|
@ -713,6 +714,31 @@ async def build_mds(body: PlanTriggerRequest):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logger.info("Reading in materials and cleaned datasets")
|
||||||
|
materials = get_materials(session)
|
||||||
|
cleaned = get_cleaned()
|
||||||
|
|
||||||
|
uprn_filenames = read_dataframe_from_s3_parquet(
|
||||||
|
bucket_name=get_settings().DATA_BUCKET, file_key="spatial/filename_meta.parquet"
|
||||||
|
)
|
||||||
|
photo_supply_lookup, floor_area_decile_thresholds = SolarPhotoSupply.load(bucket=get_settings().DATA_BUCKET)
|
||||||
|
|
||||||
|
logger.info("Getting spatial data")
|
||||||
|
for p in input_properties:
|
||||||
|
p.get_spatial_data(uprn_filenames)
|
||||||
|
|
||||||
|
logger.info("Getting components and epc recommendations")
|
||||||
|
recommendations = {}
|
||||||
|
recommendations_scoring_data = []
|
||||||
|
representative_recommendations = {}
|
||||||
|
|
||||||
|
for p in tqdm(input_properties):
|
||||||
|
p.get_components(cleaned, photo_supply_lookup, floor_area_decile_thresholds)
|
||||||
|
|
||||||
|
mds = Mds(property_instance=p, materials=materials)
|
||||||
|
mds.build()
|
||||||
|
|
||||||
|
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
logger.error("Database integrity error occurred", exc_info=True)
|
logger.error("Database integrity error occurred", exc_info=True)
|
||||||
session.rollback()
|
session.rollback()
|
||||||
|
|
|
||||||
139
recommendations/Mds.py
Normal file
139
recommendations/Mds.py
Normal file
|
|
@ -0,0 +1,139 @@
|
||||||
|
from backend.Property import Property
|
||||||
|
from recommendations.FloorRecommendations import FloorRecommendations
|
||||||
|
from recommendations.WallRecommendations import WallRecommendations
|
||||||
|
from recommendations.RoofRecommendations import RoofRecommendations
|
||||||
|
from recommendations.VentilationRecommendations import VentilationRecommendations
|
||||||
|
from recommendations.FireplaceRecommendations import FireplaceRecommendations
|
||||||
|
from recommendations.LightingRecommendations import LightingRecommendations
|
||||||
|
from recommendations.SolarPvRecommendations import SolarPvRecommendations
|
||||||
|
from recommendations.WindowsRecommendations import WindowsRecommendations
|
||||||
|
from recommendations.HeatingRecommender import HeatingRecommender
|
||||||
|
from recommendations.HotwaterRecommendations import HotwaterRecommendations
|
||||||
|
from recommendations.SecondaryHeating import SecondaryHeating
|
||||||
|
|
||||||
|
|
||||||
|
class Mds:
|
||||||
|
"""
|
||||||
|
Handles the contruction of the MDS report
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, property_instance: Property, materials):
|
||||||
|
self.property_instance = property_instance
|
||||||
|
|
||||||
|
self.floor_recommender = FloorRecommendations(property_instance=property_instance, materials=materials)
|
||||||
|
self.wall_recommender = WallRecommendations(property_instance=property_instance, materials=materials)
|
||||||
|
self.roof_recommender = RoofRecommendations(property_instance=property_instance, materials=materials)
|
||||||
|
self.ventilation_recomender = VentilationRecommendations(
|
||||||
|
property_instance=property_instance, materials=materials
|
||||||
|
)
|
||||||
|
self.fireplace_recommender = FireplaceRecommendations(property_instance=property_instance)
|
||||||
|
self.lighting_recommender = LightingRecommendations(property_instance=property_instance, materials=materials)
|
||||||
|
self.windows_recommender = WindowsRecommendations(property_instance=property_instance, materials=materials)
|
||||||
|
self.solar_recommender = SolarPvRecommendations(property_instance=property_instance)
|
||||||
|
self.heating_recommender = HeatingRecommender(property_instance=property_instance)
|
||||||
|
self.hotwater_recommender = HotwaterRecommendations(property_instance=property_instance)
|
||||||
|
self.secondary_heating_recommender = SecondaryHeating(property_instance=property_instance)
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
if self.property_instance.measures is None:
|
||||||
|
raise NotImplementedError("No measures in the property - implement me")
|
||||||
|
|
||||||
|
measures = self.property_instance.measures
|
||||||
|
|
||||||
|
measure_config_list = [list(m.keys())[0] for m in measures]
|
||||||
|
|
||||||
|
not_implemented_measures = [
|
||||||
|
"party_wall_insulation",
|
||||||
|
"ground_source_heat_pump",
|
||||||
|
"shared_ground_loops",
|
||||||
|
"communal_heat_networks",
|
||||||
|
"district_heating_networks",
|
||||||
|
"solar_thermal",
|
||||||
|
"draught_proofing",
|
||||||
|
"ev_charging",
|
||||||
|
"battery",
|
||||||
|
]
|
||||||
|
# Check if we have a not implemented measure
|
||||||
|
if any([m in not_implemented_measures for m in measure_config_list]):
|
||||||
|
raise NotImplementedError("Not implemented measure in the property - implement me")
|
||||||
|
|
||||||
|
if "external_wall_insulation" in measure_config_list:
|
||||||
|
raise Exception("check me out")
|
||||||
|
self.wall_recommender.recommend(phase=0)
|
||||||
|
# TODO: Get just ewi
|
||||||
|
ewi_recommendations = self.wall_recommender.recommendations
|
||||||
|
# TODO: Insert the recommendation identifier into this recommendation
|
||||||
|
|
||||||
|
if "cavity_wall_insulation" in measure_config_list:
|
||||||
|
raise Exception("check me out 2")
|
||||||
|
# TODO: get cwi
|
||||||
|
self.wall_recommender.recommend(phase=0)
|
||||||
|
cwi_recommendations = self.wall_recommender.recommendations
|
||||||
|
|
||||||
|
if "loft_insulation" in measure_config_list:
|
||||||
|
raise Exception("check me out 3")
|
||||||
|
self.roof_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "internal_wall_insulation" in measure_config_list:
|
||||||
|
raise Exception("check me out 4")
|
||||||
|
self.wall_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "suspended_floor_insulation" in measure_config_list:
|
||||||
|
raise Exception("check me out 5")
|
||||||
|
self.floor_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "solid_floor_insulation" in measure_config_list:
|
||||||
|
raise Exception("check me out 6")
|
||||||
|
self.floor_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "air_source_heat_pump" in measure_config_list:
|
||||||
|
raise Exception("check me out 7")
|
||||||
|
self.heating_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "electric_storage_heaters" in measure_config_list:
|
||||||
|
raise Exception("check me out 8")
|
||||||
|
self.heating_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "low_energy_lighting" in measure_config_list:
|
||||||
|
raise Exception("check me out 9")
|
||||||
|
self.lighting_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "cylinder_insulation" in measure_config_list:
|
||||||
|
raise Exception("check me out 10")
|
||||||
|
self.hotwater_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "smart_controls" in measure_config_list:
|
||||||
|
raise Exception("check me out 11")
|
||||||
|
self.heating_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "zone_controls" in measure_config_list:
|
||||||
|
raise Exception("check me out 12")
|
||||||
|
self.heating_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "trvs" in measure_config_list:
|
||||||
|
raise Exception("check me out 13")
|
||||||
|
self.heating_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "solar_pv" in measure_config_list:
|
||||||
|
raise Exception("check me out 14")
|
||||||
|
self.solar_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "double_glazing" in measure_config_list:
|
||||||
|
raise Exception("check me out 15")
|
||||||
|
self.windows_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "mechanical_ventilation" in measure_config_list:
|
||||||
|
raise Exception("check me out 16")
|
||||||
|
self.ventilation_recomender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "gas_boiler" in measure_config_list:
|
||||||
|
raise Exception("check me out 17")
|
||||||
|
self.heating_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "flat_roof_insulation" in measure_config_list:
|
||||||
|
raise Exception("check me out 18")
|
||||||
|
self.roof_recommender.recommend(phase=0)
|
||||||
|
|
||||||
|
if "room_in_roof_insulation" in measure_config_list:
|
||||||
|
raise Exception("check me out 19")
|
||||||
|
self.roof_recommender.recommend(phase=0)
|
||||||
Loading…
Add table
Reference in a new issue