Source code for viiapackage.reporting.viia_create_psse_nsce_appendix

### ===================================================================================================================
###   VIIA create appendix for assessment of NSCEs
### ===================================================================================================================
# Copyright ©VIIA 2024

### ===================================================================================================================
###   1. Import modules
### ===================================================================================================================

# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, Dict, List, Optional
from pathlib import Path

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject
from viiapackage.reporting.helper_functions.viia_get_general_info import viia_get_general_info


### ===================================================================================================================
###   2. Functions to create the appendix
### ===================================================================================================================

[docs]def viia_create_psse_nsce_appendix( project: ViiaProject, template_file: Path, output_file: Path, pictures_folder: Optional[Path] = None, report_data: Optional[dict] = None) -> Path: """ This function creates Appendix of NSCE assessment for the engineering report. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - template_file (Path): File reference for the template to be used. - output_file (Path): File reference for the generated output, this includes the folder, file name and suffix, as path. - pictures_folder (Path): Folder with the PSSE-NSCE pictures. Optional input, if not provided an empty document will be created. - report_data (dict): Optional input to pass the general info (if already collected). If not provided this general info will be collected first. Output: - The requested report is generated with the information of the object in py-memory, databases and local (image-) files. It is saved in the location of the folder mentioned in the input. """ # Add general data if not yet provided if not report_data: report_data = viia_get_general_info(project) # Add necessary data to the context report_data['nsce_pictures'] = _get_all_pictures(project=project, pictures_folder=pictures_folder) # Create report generated_report = project.create_report( template_file=template_file, data=report_data, output_file=output_file, images=True) project.write_log( f"The appendix for the assessment of NSCE is generated and saved in '{output_file.as_posix()}'.") return generated_report.output_file
### =================================================================================================================== ### 3. Functions to get info for the appendix ### =================================================================================================================== def _get_all_pictures(project: ViiaProject, pictures_folder: Optional[Path] = None) -> List[Dict[str, str]]: """ Function collects all pictures for the NSCE assessment appendix. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - pictures_folder (Path): Folder with the PSSE-NSCE pictures. Optional input, if not provided an empty document will be created. Output: - Returns a list of dictionaries of pictures to be added in the report for the plan views of the PSSE NSCE plots. The list is ordered for pictures from the lowest level upward. - The dictionaries contain the file location (file) and the name for the context (name). """ # Collect all pictures in list all_pictures = [] # Check if folder for NSCE-PSSE pictures is provided if pictures_folder is None: return all_pictures # Collect the ordered present layers layer_order = project.viia_get_layers(names=True) # Figur name text requires the layer as text layer_mapping = { 'B2': 'Second Basement', 'B1': 'Basement', 'F': 'Foundation', 'N0': 'Ground Floor', 'N1': 'First Floor', 'N2': 'Second Floor', 'N3': 'Third Floor', 'N4': 'Fourth Floor', 'N5': 'Fifth Floor', 'N6': 'Sixth Floor', 'N7': 'Seventh Floor', 'N8': 'Eighth Floor', 'N9': 'Ninth Floor', 'N10': 'Tenth Floor', 'N11': 'Eleventh Floor', 'N12': 'Twelth Floor'} if pictures_folder.exists(): pictures = [x.name for x in pictures_folder.iterdir() if x.is_file()] ordered_section_pictures = [] for layer in layer_order: for picture in pictures: if layer in picture: layer_name = layer_mapping.get(layer, 'Unknown level') ordered_section_pictures.append({ 'file': picture, 'name': f'PSSEs (shown in red) and NSCEs (shown in blue) on {layer_name}, NSCEs have been ' f'assigned a number, exits shown with arrows.'}) all_pictures = ordered_section_pictures # Notification if no pictures are found if len(all_pictures) < 1: project.write_log("WARNING: No PSSE-NSCE plots for the building have been found. Please create them first.") return all_pictures ### =================================================================================================================== ### 4. End of script ### ===================================================================================================================