mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
simplifying db funtions
This commit is contained in:
parent
7640baec02
commit
3d72d967ec
1 changed files with 11 additions and 16 deletions
|
|
@ -14,8 +14,6 @@ from starlette.responses import Response
|
|||
|
||||
from backend.app.config import get_settings, get_prediction_buckets
|
||||
from backend.app.db.connection import db_engine
|
||||
from backend.app.db.functions.materials_functions import get_materials
|
||||
from backend.app.db.functions.portfolio_functions import aggregate_portfolio_recommendations
|
||||
from backend.app.db.functions.property_functions import (
|
||||
create_property_details_epc, create_property_targets, update_property_data,
|
||||
update_or_create_property_spatial_details, ensure_property_exists
|
||||
|
|
@ -23,8 +21,6 @@ from backend.app.db.functions.property_functions import (
|
|||
from backend.app.db.functions.recommendations_functions import (
|
||||
create_plan, upload_recommendations, create_scenario
|
||||
)
|
||||
from backend.app.db.functions.funding_functions import upload_funding
|
||||
from backend.app.db.functions.energy_assessment_functions import get_latest_assessment_by_uprn
|
||||
import backend.app.db.functions as db_funcs
|
||||
|
||||
from backend.app.db.models.portfolio import rating_lookup
|
||||
|
|
@ -34,9 +30,6 @@ from backend.app.plan.utils import (
|
|||
)
|
||||
from backend.app.utils import sap_to_epc
|
||||
import backend.app.assumptions as assumptions
|
||||
from backend.app.db.functions.inspections_functions import (
|
||||
extract_inspection_data, bulk_upsert_inspections_pg
|
||||
)
|
||||
|
||||
from backend.ml_models.api import ModelApi
|
||||
from backend.Property import Property
|
||||
|
|
@ -46,8 +39,6 @@ from recommendations.optimiser.CostOptimiser import CostOptimiser
|
|||
from recommendations.optimiser.GainOptimiser import GainOptimiser
|
||||
import recommendations.optimiser.optimiser_functions as optimiser_functions
|
||||
from recommendations.Recommendations import Recommendations
|
||||
from utils.logger import setup_logger
|
||||
from utils.s3 import read_dataframe_from_s3_parquet, read_csv_from_s3, read_excel_from_s3
|
||||
from backend.ml_models.Valuation import PropertyValuation
|
||||
|
||||
from etl.bill_savings.KwhData import KwhData
|
||||
|
|
@ -58,6 +49,9 @@ from backend.Funding import Funding
|
|||
from recommendations.optimiser.funding_optimiser import optimise_with_funding_paths
|
||||
from recommendations.recommendation_utils import convert_thickness_to_numeric, get_wall_u_value
|
||||
|
||||
from utils.logger import setup_logger
|
||||
from utils.s3 import read_dataframe_from_s3_parquet, read_csv_from_s3, read_excel_from_s3
|
||||
|
||||
logger = setup_logger()
|
||||
|
||||
BATCH_SIZE = 5
|
||||
|
|
@ -575,7 +569,9 @@ async def model_engine(body: PlanTriggerRequest):
|
|||
epc_searcher.newest_epc["uprn-source"] = epc_searcher.UPRN_SOURCE_SIMULATED
|
||||
|
||||
# We check for an energy assessment we have performed on this property:
|
||||
energy_assessment = get_latest_assessment_by_uprn(session, uprn if uprn is not None else epc_searcher.uprn)
|
||||
energy_assessment = db_funcs.energy_assessment_functions.get_latest_assessment_by_uprn(
|
||||
session, uprn if uprn is not None else epc_searcher.uprn
|
||||
)
|
||||
|
||||
property_id, is_new = ensure_property_exists(
|
||||
session, body, epc_searcher, energy_assessment, landlord_property_id=config.get("landlord_property_id")
|
||||
|
|
@ -651,7 +647,7 @@ async def model_engine(body: PlanTriggerRequest):
|
|||
eco_packages[property_id] = parse_eco_packages(config, prepared_epc)
|
||||
|
||||
# Final step - extract inspections data, if we have it - we inject into property for usage
|
||||
property_inspections = extract_inspection_data(config)
|
||||
property_inspections = db_funcs.inspections_functions.extract_inspection_data(config)
|
||||
if property_inspections:
|
||||
inspections_map[property_id] = property_inspections
|
||||
|
||||
|
|
@ -696,7 +692,7 @@ async def model_engine(body: PlanTriggerRequest):
|
|||
# aginst each property if
|
||||
if inspections_map:
|
||||
logger.info("Inserting inspections data")
|
||||
bulk_upsert_inspections_pg(session, inspections_map)
|
||||
db_funcs.inspections_functions.bulk_upsert_inspections_pg(session, inspections_map)
|
||||
|
||||
# Set up model api and warm up the lambdas
|
||||
model_api = ModelApi(
|
||||
|
|
@ -713,7 +709,7 @@ async def model_engine(body: PlanTriggerRequest):
|
|||
# consistent requests to the backend for
|
||||
# the same data
|
||||
logger.info("Reading in materials and cleaned datasets")
|
||||
materials = get_materials(session)
|
||||
materials = db_funcs.materials_functions.get_materials(session)
|
||||
cleaned = get_cleaned()
|
||||
project_scores_matrix, partial_project_scores_matrix, whlg_eligible_postcodes = get_funding_data()
|
||||
|
||||
|
|
@ -1221,8 +1217,7 @@ async def model_engine(body: PlanTriggerRequest):
|
|||
upload_recommendations(
|
||||
session, recommendations_to_upload, p.id, new_plan_id
|
||||
)
|
||||
|
||||
upload_funding(session, p, new_plan_id, recommendations_to_upload)
|
||||
db_funcs.funding_functions.upload_funding(session, p, new_plan_id, recommendations_to_upload)
|
||||
|
||||
if valuations["current_value"] > 0:
|
||||
property_valuation_increases.append(
|
||||
|
|
@ -1261,7 +1256,7 @@ async def model_engine(body: PlanTriggerRequest):
|
|||
property_value_increase_ranges=property_value_increase_ranges
|
||||
)
|
||||
|
||||
aggregate_portfolio_recommendations(
|
||||
db_funcs.portfolio_functions.aggregate_portfolio_recommendations(
|
||||
session,
|
||||
portfolio_id=body.portfolio_id,
|
||||
scenario_id=scenario_id,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue