diff --git a/applications/audit_generator/d1_ventilation_template.xlsx b/applications/audit_generator/d1_ventilation_template.xlsx index 057da026..f42272e0 100644 Binary files a/applications/audit_generator/d1_ventilation_template.xlsx and b/applications/audit_generator/d1_ventilation_template.xlsx differ diff --git a/orchestration/audit_generator_orchestrator.py b/orchestration/audit_generator_orchestrator.py index 1cea614f..a22979c4 100644 --- a/orchestration/audit_generator_orchestrator.py +++ b/orchestration/audit_generator_orchestrator.py @@ -7,6 +7,10 @@ from pathlib import Path from typing import TYPE_CHECKING, Any, cast import openpyxl +from openpyxl.cell.rich_text import CellRichText, TextBlock +from openpyxl.cell.text import InlineFont +from openpyxl.formatting.rule import CellIsRule # type: ignore[reportUnknownVariableType] +from openpyxl.styles import Color, Font from domain.magicplan.models import Door, Plan, Room, Window from infrastructure.postgres.uploaded_file_table import ( @@ -23,6 +27,26 @@ _TEMPLATE_PATH = Path(__file__).parent.parent / "applications" / "audit_generato _SHEET_NAME = "D1 Ventilation" _DATA_START_ROW = 6 _MAX_ROWS = 50 +_Y_CF_RANGE = f"Y{_DATA_START_ROW}:Y{_DATA_START_ROW + _MAX_ROWS - 1}" +_Y_THRESHOLD = 7600 +_Y_HEADER = CellRichText( + TextBlock(InlineFont(b=True, sz=11, rFont="Aptos Narrow"), "Area (mm2)\n"), + TextBlock(InlineFont(b=True, sz=11, color=Color(rgb="FF0000"), rFont="Aptos Narrow"), "<"), + TextBlock(InlineFont(b=True, sz=11, rFont="Aptos Narrow"), " 7600 "), + TextBlock(InlineFont(b=True, sz=11, color=Color(rgb="196B24"), rFont="Aptos Narrow"), "<"), +) + + +def _apply_column_y_formatting(sheet: Any) -> None: + sheet.conditional_formatting.add( + _Y_CF_RANGE, + CellIsRule(operator="lessThan", formula=[str(_Y_THRESHOLD)], font=Font(color=Color(rgb="FF0000"))), + ) + sheet.conditional_formatting.add( + _Y_CF_RANGE, + CellIsRule(operator="greaterThan", formula=[str(_Y_THRESHOLD)], font=Font(color=Color(rgb="196B24"))), + ) + sheet["Y3"] = _Y_HEADER def _write_cell(sheet: Any, row: int, col: str, value: Any) -> None: @@ -75,6 +99,8 @@ def _populate_sheet(sheet: Any, plan: Plan) -> None: _write_cell(sheet, row, "X", vent.undercut_mm if vent else 0) # Y = formula =W*X — do not write + _apply_column_y_formatting(sheet) + def _serialise_workbook(wb: Any) -> bytes: buf = BytesIO()