This commit is contained in:
Khalim Conn-Kowlessar 2025-12-14 22:06:35 +08:00
parent 2a33a66470
commit bf7f05108d

View file

@ -1330,9 +1330,7 @@ async def model_engine(body: PlanTriggerRequest):
)
scenario_id = engine_scenario.id
# property_valuation_increases = []
new_epc_bands = {}
# property_value_increase_ranges = {}
for i in range(0, len(input_properties), BATCH_SIZE):
try:
# Take a slice of the input_properties list to make a batch
@ -1351,7 +1349,6 @@ async def model_engine(body: PlanTriggerRequest):
valuations = PropertyValuation.estimate(
property_instance=p, target_epc=new_epc, total_cost=total_cost
)
# property_value_increase_ranges[p.id] = valuations
property_plan_data = db_funcs.recommendations_functions.prepare_plan_data(
p, body, scenario_id, eco_packages, valuations, new_sap_points, new_epc,
@ -1386,47 +1383,13 @@ async def model_engine(body: PlanTriggerRequest):
session, p, new_plan_id, recommendations_to_upload
)
# if valuations["current_value"] > 0:
# property_valuation_increases.append(
# valuations["average_increased_value"] - valuations["current_value"]
# )
except Exception as e:
# Rollback the session if an error occurs
logger.warning("Failed i = %s" % str(i))
logger.error(f"An error occurred during batch starting at index {i}: {e}")
logger.error(f"property is uprn {p.uprn} id {p.id} address {p.address}")
logger.info("Creating portfolio aggregations")
# We implement this in the simplest way possible which will be just to query the database for all
# recommendations associated to the portfolio and then aggregate them. This is not the most efficient
# way to do this, but it's the simplest and will be a process that we can re-use since when we change a
# recommendation from being default to not default, we'll need to re-run this process to re-calculate the
# the portfolion level impact
# total_valuation_increase = sum(property_valuation_increases)
# labour_days = round(max(
# [sum(r["labour_days"] for r in rec_group if r["default"]) for p_id, rec_group in recommendations.items()]
# ))
#
# # TODO - This code only pulls in the properties that have been updated in this run, but we need to
# # aggregate all properties in the portfolio. We likely need to trigger a re-aggregation
# aggregated_data = extract_portfolio_aggregation_data(
# input_properties=input_properties,
# total_valuation_increase=total_valuation_increase,
# recommendations=recommendations,
# new_epc_bands=new_epc_bands,
# property_value_increase_ranges=property_value_increase_ranges
# )
# with db_session() as session:
# db_funcs.portfolio_functions.aggregate_portfolio_recommendations(
# session,
# portfolio_id=body.portfolio_id,
# scenario_id=scenario_id,
# total_valuation_increase=total_valuation_increase,
# labour_days=labour_days,
# aggregated_data=aggregated_data
# )
logger.info("Work completed, updating log status")
except IntegrityError as e:
return handle_error("Database integrity error.", e, body.subtask_id, 500, start_ms)