### ===================================================================================================================
### VIIA create engineering report
### ===================================================================================================================
# Copyright ©VIIA 2024
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General imports
from __future__ import annotations
from typing import TYPE_CHECKING
from pathlib import Path
from copy import deepcopy
from datetime import datetime
from typing import Dict, Optional, List, Union
# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.fem_tools import fem_create_folder
# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
from viiapackage.viiaStatus import ViiaProject
from viiapackage.reporting.viia_create_psse_nsce_appendix import viia_create_psse_nsce_appendix
from viiapackage.reporting.viia_create_model_plots_appendix import viia_create_model_plots_appendix
from viiapackage.reporting.viia_create_evva_report_engineering_input import viia_create_evva_report_engineering_input
from viiapackage.reporting.viia_create_a3_appendix_pdf import viia_create_a3_appendix_pdf
from viiapackage.pictures import viia_create_response_spectrum_graph
from viiapackage.pictures.psse_nsce_plots import PSSENSCEPlotSettings
### ===================================================================================================================
### 2. Functions to create engineering report
### ===================================================================================================================
[docs]def viia_create_engineering_report(
project: ViiaProject, template_locations: Dict[str, str], template_version: str, report_data: Optional[dict],
images_folder: Path, input_folders: Dict[str, Union[Path, Dict[str, Path]]],
output_folder: Optional[Path] = None) -> List[Path]:
"""
This function creates engineering report.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- template_locations (dict): Dictionary which stores the path of all requested template files.
- report_data (dict): Dictionary which includes all project specific data for reporting.
- images_folder (Path): Location where the manual images are stored and should be retrieved from.
- input_folders (dict): Dictionary with the folders where the results of the analyses should be collected from.
Default value None. Input is only required for the engineering report of NLTH assessment.
- output_folder (Path): Optional input for location where to create the report. Default value is None,
indicating the default location is used. In normal production objects do not change this!
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 'ER' folder (and 'EVVA' folder if EVVA report is generated) of the
working folder.
"""
# Create or check the location where the report is generated
if output_folder is None:
# Create sub-folder
fem_create_folder('ER', ref_folder=project.workfolder_location)
time_reference = datetime.now().strftime('%Y%m%d%H%M%S')
folder = f'{time_reference}-v{str(project.version).zfill(3)}'
fem_create_folder(
folder, ref_folder=project.workfolder_location / 'ER')
report_location = project.workfolder_location / 'ER' / folder
else:
if isinstance(output_folder, str):
output_folder = Path(output_folder)
report_location = output_folder
# Check if output-folder is created
if not report_location.exists():
raise FileNotFoundError("ERROR: The specified output-folder does not exist, please check input.")
# Create the response spectrum plot for the object
figure = None
if 'test-' != project.name[:5]:
for response_spectrum in project.collections.response_spectra:
if '2475' in response_spectrum.name and 'horizontaal' in response_spectrum.name:
figure = viia_create_response_spectrum_graph(
project=project, response_spectrum=response_spectrum, save_folder=images_folder)
if figure is None or not figure.exists():
project.write_log(
"WARNING: No response spectrum found for the object or issue with the generation of the figure. The "
"response spectrum figure is not generated. Plot is not added in the report.")
# Create reports
generated_reports = []
for key, value in template_locations.items():
output_document_name = f'VIIA-{project.name}-{key}.docx'
if key == 'C3':
generated_reports.append(viia_create_model_plots_appendix(
project=project, template_file=project.viia_settings.project_specific_package_location / value,
output_folder=report_location, pictures_folder=input_folders['appendix_pictures']))
elif key == 'C2':
if input_folders['appendix_pictures']:
generated_reports.append(viia_create_psse_nsce_appendix(
project=project, template_file=project.viia_settings.project_specific_package_location / value,
output_file=report_location / output_document_name, report_data=deepcopy(report_data),
pictures_folder=input_folders['appendix_pictures'] / PSSENSCEPlotSettings.subfolder))
else:
project.write_log(
f"Appendix C2 is not created as there is no PSSE-NSCE folder provided.")
elif key == 'C4' and project.project_information['geotechnical_analysis'] == 'Required':
# In case geotechnical analysis is required, the geotechnical advisor will create the C4 appendix
project.write_log(
f"Geotechnical analysis is required, therefore the geotechnical advisor will provide the C4 appendix.")
elif key == 'EVVA':
generated_reports.append(viia_create_evva_report_engineering_input(
project=project, template_file=project.viia_settings.project_specific_package_location / value,
output_file=report_location / output_document_name, report_data=report_data))
elif key == 'A3' and len(project.project_specific['strengthening_measures']) != 0:
generated_reports.append(viia_create_a3_appendix_pdf(project=project, docx_file=project.create_report(
template_file=project.viia_settings.project_specific_package_location / template_locations[key],
data=report_data, output_file=report_location / output_document_name, render_images=True).output_file,
measures=list(project.project_specific['strengthening_measures'].keys())))
else:
generated_reports.append(project.create_report(
template_file=project.viia_settings.project_specific_package_location / template_locations[key],
data=report_data, output_file=report_location / output_document_name, render_images=True).output_file)
project.write_log(
f"Finished processing {output_document_name}. Generated report can be found in '{report_location}'")
# Return list of all created reports
return generated_reports
### ===================================================================================================================
### 3. End of script
### ===================================================================================================================