diff --git a/asset_list/AssetList.py b/asset_list/AssetList.py index 04cf6d9d..3b5535d5 100644 --- a/asset_list/AssetList.py +++ b/asset_list/AssetList.py @@ -1719,7 +1719,7 @@ class AssetList: solar_reason_map = { "solar_eligible": "Solar Eligible: ", "solar_eligible_needs_heating_upgrade": ( - "Solar Eligible, Solid Floor, Needs Heating Upgrade: " + "Solar Eligible, Needs Heating Upgrade: " ), "solar_eligible_solid_wall_uninsulated": "Solar Eligible, Solid Wall Uninsulated, EPC E or Below: ", } @@ -2140,10 +2140,8 @@ class AssetList: return # TODO: Fetch from Sharepoint - ecosurv_filepath = "/Users/khalimconn-kowlessar/Documents/hestia/Ecosurv/07.csv" - logger.info( - "Getting Ecosurv data from %s", ecosurv_filepath - ) + ecosurv_filepath = "/Users/khalimconn-kowlessar/Documents/hestia/Ecosurv/15.04.csv" + logger.info("Getting Ecosurv data from %s", ecosurv_filepath) self.ecosurv = pd.read_csv( ecosurv_filepath, encoding="cp437" @@ -2214,6 +2212,9 @@ class AssetList: unmatched.append(row["Reference"]) continue + logger.info("Matched %s properties to ecosurv data", len(matched)) + logger.info("%s properties in Ecosurv remain unmatched", len(unmatched)) + # We now match matched = pd.DataFrame(matched) self.standardised_asset_list = self.standardised_asset_list.merge( diff --git a/asset_list/app.py b/asset_list/app.py index 7fa52dd0..8e50c99f 100644 --- a/asset_list/app.py +++ b/asset_list/app.py @@ -124,7 +124,7 @@ def app(): ] master_to_asset_list_filepath = None phase = False - ecosuv_landlords = "paul butler|bromford" + ecosurv_landlords = "paul butler|bromford" # Torus data_folder = "/Users/khalimconn-kowlessar/Documents/hestia/Customers/Torus/Phase 1" @@ -609,6 +609,8 @@ def app(): master_to_asset_list_filepath=master_to_asset_list_filepath ) + asset_list.flag_ecosurv(ecosurv_landlords) + ### We retrieve the EPC data # We chunk up this data into 5000 rows at a time @@ -950,5 +952,8 @@ def app(): if not asset_list.outcomes_no_match.empty: asset_list.outcomes_no_match.to_excel(writer, sheet_name="Unmatched Outcomes", index=False) + if not asset_list.ecosurv_no_match.empty: + asset_list.ecosurv_no_match.to_excel(writer, sheet_name="Unmatched Ecosurv", index=False) + # Store the Hubspot export as a csv hubspot_data.to_csv(os.path.join(data_folder, "Hubspot Export.csv"), index=False) diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index 57349b8a..bc482263 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -1,4 +1,5 @@ import ast +import asyncio import json from datetime import datetime @@ -420,9 +421,23 @@ router = APIRouter( ) -@router.post("/trigger") -async def trigger_plan(body: PlanTriggerRequest): +@router.post("/trigger", status_code=202) +async def trigger_plan_entrypoint(body: PlanTriggerRequest): + """ + This function is the entrypoint for the plan trigger API. It will handle the request and call the + trigger_plan function. + :param body: The request body + :return: + """ logger.info("API triggered with body: %s", body) + # Kick off the async background task + asyncio.create_task(model_engine(body)) + + return {"message": "Plan job accepted"} + + +async def model_engine(body: PlanTriggerRequest): + logger.info("Model Engine triggered with body: %s", body) logger.info("Connecting to db") session = sessionmaker(bind=db_engine)() @@ -1056,4 +1071,6 @@ async def trigger_plan(body: PlanTriggerRequest): finally: session.close() + logger.info("Model Engine completed successfully") + return Response(status_code=200) diff --git a/serverless.yml b/serverless.yml index 893588c6..abca5ade 100644 --- a/serverless.yml +++ b/serverless.yml @@ -81,4 +81,4 @@ functions: - http: path: /{proxy+} method: ANY - timeout: 120 \ No newline at end of file + timeout: 900 # Max timeout to 15 mins for engine runs \ No newline at end of file