diff --git a/orchestration/scenario_export_orchestrator.py b/orchestration/scenario_export_orchestrator.py index 5accfc951..a45f912e7 100644 --- a/orchestration/scenario_export_orchestrator.py +++ b/orchestration/scenario_export_orchestrator.py @@ -16,6 +16,7 @@ from dataclasses import dataclass from typing import Protocol, Sequence from domain.scenario_export.scenario_sheet import ( + ExportSheet, PropertyScenarioData, shape_scenario_sheet, ) @@ -78,4 +79,26 @@ class ScenarioExportOrchestrator: recipient_email: str, export_name: str, ) -> ScenarioExportResult: - raise NotImplementedError + named_sheets: list[tuple[str, ExportSheet]] = [] + row_count = 0 + for scenario_id in scenario_ids: + rows = self._rows.rows_for( + portfolio_id=portfolio_id, + scenario_id=scenario_id, + property_ids=property_ids, + ) + sheet = shape_scenario_sheet(rows) + named_sheets.append((self._scenarios.name_for(scenario_id), sheet)) + row_count += len(sheet.rows) + + data = render_workbook(named_sheets) + key = f"{self._key_prefix}/{export_name}.xlsx" + self._exports.put_object(key, data) + url = self._exports.generate_presigned_url(key, self._url_ttl_seconds) + + return ScenarioExportResult( + presigned_url=url, + export_s3_key=key, + sheet_count=len(named_sheets), + row_count=row_count, + )