mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
uploading plan and recommendations wip
This commit is contained in:
parent
e4aeb204ca
commit
cbed2d6b86
2 changed files with 20 additions and 11 deletions
|
|
@ -2,7 +2,10 @@ import enum
|
|||
|
||||
|
||||
def row2dict(row):
|
||||
""" Generic function to convert a SQLAlchemy row to a dictionary."""
|
||||
"""
|
||||
Generic function to convert a SQLAlchemy row to a dictionary.
|
||||
May not be the best practice implementing like this but works for the moment
|
||||
"""
|
||||
|
||||
d = {}
|
||||
for column in row.__table__.columns:
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from recommendations.FloorRecommendations import FloorRecommendations
|
|||
from recommendations.WallRecommendations import WallRecommendations
|
||||
from utils.uvalue_estimates import classify_decile_newvalues
|
||||
from backend.app.db.utils import row2dict
|
||||
from starlette.responses import Response
|
||||
|
||||
# database interaction functions
|
||||
from backend.app.db.functions.property_functions import (
|
||||
|
|
@ -136,6 +137,9 @@ async def trigger_plan(body: PlanTriggerRequest):
|
|||
)
|
||||
)
|
||||
|
||||
if not input_properties:
|
||||
return Response(status_code=204)
|
||||
|
||||
logger.info("Getting EPC data")
|
||||
for p in input_properties:
|
||||
p.search_address_epc()
|
||||
|
|
@ -166,8 +170,8 @@ async def trigger_plan(body: PlanTriggerRequest):
|
|||
|
||||
logger.info("Getting components and properties recommendations")
|
||||
|
||||
for property_id, p in enumerate(input_properties):
|
||||
|
||||
recommendations = {}
|
||||
for p in input_properties:
|
||||
property_recommendations = []
|
||||
|
||||
# For each property, classiy floor area decide
|
||||
|
|
@ -197,9 +201,6 @@ async def trigger_plan(body: PlanTriggerRequest):
|
|||
total_floor_area_group_decile=total_floor_area_group_decile
|
||||
)
|
||||
floor_recommender.recommend()
|
||||
# insert property id
|
||||
for rec in floor_recommender.recommendations:
|
||||
rec["property_id"] = property_id
|
||||
|
||||
property_recommendations.extend(floor_recommender.recommendations)
|
||||
|
||||
|
|
@ -229,13 +230,12 @@ async def trigger_plan(body: PlanTriggerRequest):
|
|||
materials=materials_by_type["external_wall_insulation"] + materials_by_type["internal_wall_insulation"]
|
||||
)
|
||||
wall_recomendations.recommend()
|
||||
# insert property id
|
||||
for rec in wall_recomendations.recommendations:
|
||||
rec["property_id"] = property_id
|
||||
|
||||
property_recommendations.extend(wall_recomendations.recommendations)
|
||||
|
||||
# Once we're done, we'll store:
|
||||
recommendations[p.id] = property_recommendations
|
||||
|
||||
# Once we're done, we'll store:
|
||||
# 1) the property data
|
||||
# 2) the property details (epc)
|
||||
# 3) the recommendations
|
||||
|
|
@ -248,4 +248,10 @@ async def trigger_plan(body: PlanTriggerRequest):
|
|||
property_data = p.get_full_property_data()
|
||||
update_property_data(property_id=p.id, portfolio_id=body.portfolio_id, property_data=property_data)
|
||||
|
||||
return {"recommendations": recommendations}
|
||||
# Upload recommendations
|
||||
recommendations_to_upload = recommendations[p.id]
|
||||
if not recommendations:
|
||||
continue
|
||||
# Create a plan
|
||||
|
||||
return Response(status_code=200)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue