diff --git a/lambdas/modelling_e2e/Dockerfile b/applications/modelling_e2e/Dockerfile similarity index 82% rename from lambdas/modelling_e2e/Dockerfile rename to applications/modelling_e2e/Dockerfile index 0f17e99a..fa13f8ef 100644 --- a/lambdas/modelling_e2e/Dockerfile +++ b/applications/modelling_e2e/Dockerfile @@ -2,7 +2,7 @@ FROM public.ecr.aws/lambda/python:3.11 WORKDIR /var/task -COPY lambdas/modelling_e2e/requirements.txt . +COPY applications/modelling_e2e/requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY datatypes/ datatypes/ @@ -19,6 +19,6 @@ COPY tests/__init__.py tests/__init__.py COPY tests/orchestration/__init__.py tests/orchestration/__init__.py COPY tests/orchestration/fakes.py tests/orchestration/fakes.py -COPY lambdas/ lambdas/ +COPY applications/ applications/ -CMD ["lambdas.modelling_e2e.handler.handler"] +CMD ["applications.modelling_e2e.handler.handler"] diff --git a/lambdas/modelling_e2e/handler.py b/applications/modelling_e2e/handler.py similarity index 91% rename from lambdas/modelling_e2e/handler.py rename to applications/modelling_e2e/handler.py index 0fed0fb4..ebea872e 100644 --- a/lambdas/modelling_e2e/handler.py +++ b/applications/modelling_e2e/handler.py @@ -39,6 +39,7 @@ from infrastructure.solar.google_solar_api_client import ( BuildingInsightsNotFoundError, GoogleSolarApiClient, ) +from applications.modelling_e2e.modelling_e2e_trigger_body import ModellingE2ETriggerBody from repositories.geospatial.geospatial_s3_repository import ( GeospatialS3Repository, ParquetReader, @@ -102,11 +103,12 @@ def _solar_insights_for( @task_handler(task_source="modelling_e2e", source=Source.PROPERTY) def handler(body: dict[str, Any], context: Any) -> None: - property_id = int(body["property_id"]) - portfolio_id = int(body["portfolio_id"]) - scenario_id = int(body["scenario_id"]) - no_solar = bool(body.get("no_solar", False)) - dry_run = bool(body.get("dry_run", False)) + trigger = ModellingE2ETriggerBody.model_validate(body) + property_id = trigger.property_id + portfolio_id = trigger.portfolio_id + scenario_id = trigger.scenario_id + no_solar = trigger.no_solar + dry_run = trigger.dry_run engine = _get_engine() epc_client = EpcClientService(os.environ["OPEN_EPC_API_TOKEN"]) @@ -135,7 +137,9 @@ def handler(body: dict[str, Any], context: Any) -> None: effective_epc = overlaid.effective_epc spatial = _spatial_for(geospatial, uprn) - restrictions = spatial.restrictions if spatial is not None else PlanningRestrictions() + restrictions = ( + spatial.restrictions if spatial is not None else PlanningRestrictions() + ) solar_insights = None if no_solar else _solar_insights_for(solar_client, spatial) with Session(engine) as session: @@ -144,9 +148,9 @@ def handler(body: dict[str, Any], context: Any) -> None: # secondary_heating_removal is absent from the live material.type enum; # exclude it unconditionally until the catalogue gap is resolved. - considered: Optional[frozenset[MeasureType]] = ( - frozenset(MeasureType) - {MeasureType.SECONDARY_HEATING_REMOVAL} - ) + considered: Optional[frozenset[MeasureType]] = frozenset(MeasureType) - { + MeasureType.SECONDARY_HEATING_REMOVAL + } plan = run_modelling( effective_epc, diff --git a/applications/modelling_e2e/modelling_e2e_trigger_body.py b/applications/modelling_e2e/modelling_e2e_trigger_body.py new file mode 100644 index 00000000..908f9bd2 --- /dev/null +++ b/applications/modelling_e2e/modelling_e2e_trigger_body.py @@ -0,0 +1,11 @@ +from pydantic import BaseModel, ConfigDict + + +class ModellingE2ETriggerBody(BaseModel): + model_config = ConfigDict(extra="allow") + + property_id: int + portfolio_id: int + scenario_id: int + no_solar: bool = False + dry_run: bool = False diff --git a/lambdas/modelling_e2e/requirements.txt b/applications/modelling_e2e/requirements.txt similarity index 100% rename from lambdas/modelling_e2e/requirements.txt rename to applications/modelling_e2e/requirements.txt diff --git a/lambdas/__init__.py b/lambdas/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/lambdas/modelling_e2e/__init__.py b/lambdas/modelling_e2e/__init__.py deleted file mode 100644 index e69de29b..00000000