mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Added materials table to fastapi backend
This commit is contained in:
parent
07af58eb85
commit
b278e557fb
5 changed files with 67 additions and 5 deletions
2
.idea/Model.iml
generated
2
.idea/Model.iml
generated
|
|
@ -7,7 +7,7 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/open_uprn" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/recommendations" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (model_data)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (backend)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (model_data)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (backend)" project-jdk-type="Python SDK" />
|
||||
<component name="PythonCompatibilityInspectionAdvertiser">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
|
|
|
|||
51
backend/app/db/models/materials.py
Normal file
51
backend/app/db/models/materials.py
Normal file
|
|
@ -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())
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue