diff --git a/.idea/Model.iml b/.idea/Model.iml index b03b31b1..05b9012b 100644 --- a/.idea/Model.iml +++ b/.idea/Model.iml @@ -7,7 +7,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index ca0e1cd9..3b05c6ac 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/backend/app/db/models/materials.py b/backend/app/db/models/materials.py new file mode 100644 index 00000000..4c4a8a09 --- /dev/null +++ b/backend/app/db/models/materials.py @@ -0,0 +1,51 @@ +import enum + +from sqlalchemy import Column, Integer, String, Float, Enum, TIMESTAMP +from sqlalchemy.orm import declarative_base +from sqlalchemy.sql import func + +Base = declarative_base() + + +class MaterialType(enum.Enum): + suspended_floor_insulation = "suspended_floor_insulation" + solid_floor_insulation = "solid_floor_insulation" + external_wall_insulation = "external_wall_insulation" + internal_wall_insulation = "internal_wall_insulation" + + +class DepthUnit(enum.Enum): + mm = "mm" + + +class CostUnit(enum.Enum): + gbp_sq_meter = "gbp_sq_meter" + + +class RValueUnit(enum.Enum): + square_meter_kelvin_per_watt = "square_meter_kelvin_per_watt" + + +class ThermalConductivityUnit(enum.Enum): + watt_per_meter_kelvin = "watt_per_meter_kelvin" + + +class Material(Base): + __tablename__ = 'material' + + id = Column(Integer, primary_key=True, autoincrement=True) + type = Column(Enum(MaterialType, values_callable=lambda x: [e.value for e in x]), nullable=False) + description = Column(String, nullable=False) + depths = Column(String) # You may want to use a specific JSON type depending on the database + depth_unit = Column(Enum(DepthUnit, values_callable=lambda x: [e.value for e in x]), nullable=False) + cost = Column(Float) + cost_unit = Column(Enum(CostUnit, values_callable=lambda x: [e.value for e in x]), nullable=False) + r_value_per_mm = Column(Float) + r_value_unit = Column(Enum(RValueUnit, values_callable=lambda x: [e.value for e in x]), nullable=False) + thermal_conductivity = Column(Float) + thermal_conductivity_unit = Column( + Enum(ThermalConductivityUnit, values_callable=lambda x: [e.value for e in x]), + nullable=False + ) + link = Column(String) + created_at = Column(TIMESTAMP, nullable=False, server_default=func.now()) diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index f06ca2ed..c119c79e 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -155,11 +155,17 @@ async def trigger_plan(body: PlanTriggerRequest): # The materials data could be cached or local so we don't need to make # consistent requrests to the backend for # the same data + # TODO: It might not be the best choice to store the materials data in a database table since thi + # table probably won't be very large and won't be updated that often. It might be better to + # store this data in s3 load it into memory when the app starts up. We will test this materials_by_type = get_materials(materials) logger.info("Getting components and properties recommendations") - recommendations = [] + for property_id, p in enumerate(input_properties): + + property_recommendations = [] + # For each property, classiy floor area decide total_floor_area_group_decile = classify_decile_newvalues( decile_boundaries=floors_decile_data["decile_boundaries"], @@ -191,7 +197,7 @@ async def trigger_plan(body: PlanTriggerRequest): for rec in floor_recommender.recommendations: rec["property_id"] = property_id - recommendations.extend(floor_recommender.recommendations) + property_recommendations.extend(floor_recommender.recommendations) # Wall recommendations # We would make this u-value query directly to the database @@ -223,7 +229,10 @@ async def trigger_plan(body: PlanTriggerRequest): for rec in wall_recomendations.recommendations: rec["property_id"] = property_id - recommendations.extend(wall_recomendations.recommendations) + property_recommendations.extend(wall_recomendations.recommendations) + + if property_recommendations: + blah # Once we're done, we'll store: # 1) the property data diff --git a/model_data/simulation_system/app.py b/model_data/simulation_system/app.py index 545fae16..2875925f 100644 --- a/model_data/simulation_system/app.py +++ b/model_data/simulation_system/app.py @@ -237,6 +237,7 @@ def app(): # Clean using averages avgs = iterative_filtering(cleaning_averages, property_data) + # TODO: Should probably do a mean/median? field_value = avgs[field].iloc[0] if pd.isnull(field_value): @@ -281,6 +282,7 @@ def app(): rdsap_change = ending_record[RDSAP_RESPONSE] - starting_record[RDSAP_RESPONSE] heat_demand_change = ending_record[HEAT_DEMAND_RESPONSE] - starting_record[HEAT_DEMAND_RESPONSE] + # TODO: Should this be <= 0? if rdsap_change == 0: # Assumption: We aren't interested in records that exhibit no change continue