### =============================================================================================================== ###
### ###
### viiaReporting.py ###
### ###
### =============================================================================================================== ###
# This module ``viiaReporting`` contains functions for automatically (parts of) the report.
# Module is based on:
# VIIA_QE_R376 Basis of Design Retrofit Advice NLTH, v11.0, d.d. 29 August 2024
# This script was based upon the Constitution For Python At VIIA
# For use by VIIA
# Copyright RHDHV
### ===================================================================================================================
### Contents script
### ===================================================================================================================
# 1. Import modules
# 2. Create the reports for VIIA
# 3. End of script
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General Imports
from __future__ import annotations
from typing import TYPE_CHECKING, List, Optional, Dict, Union
from pathlib import Path
# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
from viiapackage.viiaStatus import ViiaProject
from viiapackage.reporting import viia_create_beoordelings_report, viia_create_bkg_report, viia_create_cost_report, \
viia_create_crm, viia_create_engineering_report, viia_create_inspection_report, viia_create_uo_report, \
viia_create_uren_monitor_report, viia_report_input_check, viia_collect_templates, viia_templating_data, \
viia_collect_folders_reporting, viia_create_ontwerpnotitie_report, viia_create_bevindingen_report
from viiapackage.database import viia_get_project_images
from viiapackage.viiaSettings import ViiaSettings
### ===================================================================================================================
### 2. Functions to prepare the TVA report for VIIA
### ===================================================================================================================
[docs]def viia_prepare_for_engineering_report(
project: ViiaProject, governing_analysis: str, folder_a7: Optional[Path] = None,
folder_a10: Optional[Path] = None, folders_a12: Optional[Dict[str, Path]] = None,
folder_a13: Optional[Path] = None, folders_a15: Optional[Dict[str, Path]] = None) -> Dict[str, Path]:
"""
This function collects the folders with analyses relevant for the reporting in TVA of the NLTH. It provides options
for the user to check the inputs and overrule if needed. It will load the model of the governing analysis, which is
used for the automated reporting (mesh data, applied strengthening measures, etc.).
.. note:: This function should be run in the report script, there should not be a model loaded prior to this
function. Checks are performed if all required data is found and correct. Please follow VIIA workflow.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- governing_analysis (str): Governing analysis for NLTH results. For NLTH report the governing analysis can be
selected from 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10' or 'S11'.
- folder_a7 (Path): Path of the A7 analysis folder where the results of the analysis can be found. Default value
is None, in which case the folder is automatically retrieved based on naming conventions in VIIA.
- folder_a10 (Path): Path of the A10 analysis folder where the results of the analysis can be found. Default
value is None, in which case the folder is automatically retrieved based on naming conventions in VIIA.
- folders_a12 (dict): Dictionary with the paths of the A12 analysis to be used. Default value is None, in which
case the folder is automatically retrieved based on naming conventions in VIIA.
- folder_a13 (Path): Path of the A13 analysis folder where the results of the analysis can be found. Default
value is None, in which case the folder is automatically retrieved based on naming conventions in VIIA. Only
used for objects with strengthening.
- folders_a15 (dict): Dictionary with the paths of the A15 analysis to be used. Default value is None, in which
case the folder is automatically retrieved based on naming conventions in VIIA. Only required for strengthened
objects.
Output:
- Returns dictionary with the folders with the results to be used in the report. Notifications are printed to
inform the user which folders are used.
"""
# Function only available for 'NLTH' analysis
if project.analysis_type != 'NLTH':
raise NotImplementedError(
f"ERROR: This function should only be used for objects with analysis type 'NLTH'. Current analysis type is "
f"{project.analysis_type}, which is not supported.")
reporting_folders, main_results_folder = viia_collect_folders_reporting(
project=project, governing_analysis=governing_analysis, folder_a7=folder_a7, folder_a10=folder_a10,
folders_a12=folders_a12, folder_a13=folder_a13, folders_a15=folders_a15)
# Check if there is a main result folder
if main_results_folder is None:
raise RuntimeError(
"ERROR: The reporting script should be executed only after generating results in A12 or A15 and at least "
"providing results for the governing signal.")
# Check if there is already a model loaded
if project.collections.shapes:
raise RuntimeError(
"ERROR: A model has already been loaded, this should not be the case and conflicts with this "
"functionality. Please correct your script.")
# Load the model
if 'A12' in main_results_folder.as_posix():
json_file = main_results_folder / f'{project.name}_{governing_analysis}_v1.json'
else:
json_file = main_results_folder / f'{project.name}_{governing_analysis}_v{project.version}.json'
if not json_file.exists():
raise FileNotFoundError(
"ERROR: The json-file of the model could not be found. Make sure that the file-names comply to the naming "
f"convention in VIIA. Expected file with the model is {json_file.as_posix()}.\nFound json-files are: "
f"{', '.join(j_file.as_posix() for j_file in list(main_results_folder.rglob('*.json')))} ")
project.write_log(f"Loading model: {json_file.as_posix()}")
project.viia_read_dump(filename=json_file, remove_collections=False)
# Set the support-type for the reporting
project.viia_settings.support_type = 'FlexBaseGlobal'
for material in project.collections.materials:
if 'MYVIIA' in material.name:
project.viia_settings.support_type = 'FlexBaseFinal'
break
# Return the folders for the reporting
return reporting_folders
### ===================================================================================================================
### 2. Create the reports for VIIA
### ===================================================================================================================
[docs]def viia_create_report(
project: ViiaProject, report_type: str = 'TVA', governing_analysis: str = None, soil_investigation: bool = True,
scope_change_id: Optional[int] = None, werkpakket_lst: Optional[List[str]] = None,
extra_object_parts: Optional[List[str]] = None, output_folder: Path = None, images_folder: Path = None,
input_folders: Dict[str, Union[Path, Dict[str, Path]]] = None) -> List[Path]:
"""
This function creates the required report for VIIA. It will collect the correct template (depending on the tender
specification which is defined on MYVIIA), collect the required data for the report (from local work-folder sources
and/or MYVIIA) and generate the report.
.. note:: The tender specification (NL: vraagspecificatie) is retrieved from MYVIIA. If this is incorrect inform the
project-leader. The projectleader can check and make sure that MYVIIA is updated.
With this function you can create different reports for VIIA. Some reports require specific additional input. The
following report-types are available; these require input for the items mentioned. Input for other items is ignored.
- **TVA (default)**: Engineering report, input required for the governing analysis.
- **Opnameplan**: Inspection plan document, input required if soil investigation is required (default True). This
report template is used by project support.
- **Opname**: Inspection report, no input required. This report template is used by the inspector of the object.
- **bkg**: Form to be used for requesting scope changes for NCG. Form is used by the projectleader of the object.
No additional input required. This is a report in Excel.
- **Kostenraming**: Report template filled with data from MYVIIA to be used by the cost engineer of the object. This
is a report in Excel.
- **crm**: Administration form for the client NCG. This report template is used by the editor of the object. No
additional input required. This is a report in Excel.
- **Beoordeling**: Final assessment document for the owner, also called EVVA. This report template is used by the
editor of the object. Requires no additional input.
- **UrenMonitor**: Excel sheet with an overview of the progress. This report template is used by the projectleader
and management.
- **UO**: UO report, no input required. This report template is used by the engineer and lead engineer of the
object.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- report_type (str): Select the report to be generated. Default value TVA, creating the engineering report
including all of its annexes.
- governing_analysis (str): Governing analysis for NLTH results. For NLTH report the governing analysis can be
selected from 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10' or 'S11'. Default value is None,
which should be selected for other report-types than the NLTH TVA report.
- soil_investigation (bool): Boolean for soil investigation (required for Opnameplan report). If soil
investigation is to be done, the value is True. Otherwise, the value is False. Default value is True.
- scope_change_id (int): ID of the selected object scope-change in MYVIIA database. Default value is None, only
required when the BKG report is created with this function.
- werkpakket_lst (list of str): List of names of the werkpakket to create the Excel for. Default value is None,
only required when the uren monitor report is created with this function.
- extra_object_parts (list of str): List of names of extra object parts to include in the report. Default value
is None, only required when the UO report is created with this function.
- 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!
- images_folder (Path): Optional input for location where to store the images for the report. Default value is
None, indicating the default location is used. In normal production objects do not change this!
- 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:
- The requested report is generated with the information of the object in py-memory, databases and local
(image-) files. It is saved in sub-folder of the working folder, depending on the type of report. The user is
notified where the document is created.
- Returns list of files created for the report type selected.
"""
# Check the inputs for the report generation
report_type, tender_specification = viia_report_input_check(
project=project, report_type=report_type, governing_analysis=governing_analysis,
scope_change_id=scope_change_id, werkpakket_lst=werkpakket_lst)
# Collect template
template_locations = viia_collect_templates(
project=project,
report_type=report_type,
tender_specification=tender_specification)
# Load folders for NLTH if not provided
if report_type == 'engineering' and project.analysis_type in ['NLTH', 'NLTH-REF'] and input_folders is None:
input_folders, _ = viia_collect_folders_reporting(project=project, governing_analysis=governing_analysis)
# Load tb file results
# if report_type == 'engineering' and governing_analysis:
# load_l2_measure_data(project=project, governing_analysis=governing_analysis)
# Collect data for reporting
report_data = viia_templating_data(
project=project,
report_type=report_type,
tender_specification=tender_specification,
governing_analysis=governing_analysis,
input_folders=input_folders,
extra_object_parts=extra_object_parts)
# Generate report
if report_type == 'crm':
return viia_create_crm(project=project, template_locations=template_locations, output_folder=output_folder)
elif report_type == 'bkg':
return viia_create_bkg_report(
project=project, template_locations=template_locations, output_folder=output_folder,
scope_change_id=scope_change_id)
elif report_type == 'kostenraming':
return viia_create_cost_report(
project=project, template_locations=template_locations, output_folder=output_folder)
elif report_type == 'urenmonitor':
return viia_create_uren_monitor_report(
project=project, werkpakket_lst=werkpakket_lst, template_locations=template_locations,
output_folder=output_folder)
# Download required project images from MYVIIA
if images_folder is None:
images_folder = project.workfolder_location / ViiaSettings.DEFAULT_IMAGES_FOLDER
if not images_folder.exists():
images_folder.mkdir(parents=True, exist_ok=True)
project.diana_settings.analysis_settings['MANUAL']['folder_name'] = images_folder
if 'test-' != project.name[:5]:
# Download images from MYVIIA depending on the report-type
viia_get_project_images(project=project, folder_location=images_folder, report_type=report_type)
report_data['manual_images'] = images_folder.as_posix()
if report_type == 'opname':
return viia_create_inspection_report(
project=project, template_locations=template_locations, report_data=report_data,
output_folder=output_folder)
if report_type == 'opnameplan':
return viia_create_inspection_report(
project=project, template_locations=template_locations, report_data=report_data,
output_folder=output_folder, soil_investigation=soil_investigation)
if report_type == 'beoordeling':
return viia_create_beoordelings_report(
project=project, template_locations=template_locations, report_data=report_data,
output_folder=output_folder)
if report_type == 'ontwerpnotitie':
return viia_create_ontwerpnotitie_report(
project=project, template_locations=template_locations, report_data=report_data,
output_folder=output_folder)
if report_type == 'uo':
return viia_create_uo_report(
project=project, template_locations=template_locations, report_data=report_data,
output_folder=output_folder)
if report_type == 'bevindingen':
return viia_create_bevindingen_report(
project=project, template_locations=template_locations, report_data=report_data,
output_folder=output_folder)
if 'Manual Images' not in images_folder.as_posix() and not ViiaSettings.MYVIIA_REPORT:
raise NotImplementedError(
"ERROR: This template is not updated for application of other than default image folder. "
"Please use default.")
return viia_create_engineering_report(
project=project, template_version=tender_specification, template_locations=template_locations,
report_data=report_data, output_folder=output_folder, images_folder=images_folder,
input_folders=input_folders)
### ===================================================================================================================
### 3. End of script
### ===================================================================================================================