Source code for viiapackage.reporting.viia_report_input_check

### ===================================================================================================================
###   Collect and check the inputs for the requested report for VIIA
### ===================================================================================================================
# Copyright ©VIIA 2024

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

# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, Optional, Tuple, List
from warnings import warn

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


### ===================================================================================================================
###   2. Helper function to get the tender specification of the requested report
### ===================================================================================================================

[docs]def viia_get_tender_specification_deliverable(project: ViiaProject, report_type: str) -> str: """ Function to collect the tender specification of the requested deliverable on MYVIIA.""" deliverable_mapping = { 'opnameplan': 'Opnameplan', 'opname': 'Opnamerapport', 'engineering': 'TVA', 'beoordeling': 'EVVA/BVVA', 'crm': 'CRM overzicht', 'kostenraming': 'Kostenraming', 'ontwerpnotitie': 'Ontwerpnotitie', 'uo': 'UO rapport concept', 'bevindingen': 'Opname UO fase'} if report_type in ['bkg']: return project.project_information['opdracht_id']['vraagspecificatie'] if report_type not in deliverable_mapping: raise ValueError("ERROR: The report-type does not match any of the available deliverable names.") deliverable_name = deliverable_mapping[report_type] if project.object_part is not None and 'deliverables' in project.object_part: for deliverable in project.object_part['deliverables']: if deliverable['deliverable_id']['deliverable'] == deliverable_name: return deliverable['deliverable_id']['vraagspecificatie'] if report_type in ['uo', 'ontwerpnotitie', 'bevindingen']: if 'objectdelen' in project.project_information and project.project_information['objectdelen']: for objectpart in project.project_information['objectdelen']: if objectpart['naam'] == 'Gehele object': for deliverable in objectpart['deliverables']: if deliverable['deliverable_id']['deliverable'] == deliverable_name: return deliverable['deliverable_id']['vraagspecificatie'] raise ValueError( f"ERROR: The tender specification for the deliverable {deliverable_name} could not be found on MYVIIA. Please " f"inform the project-leader.")
### =================================================================================================================== ### 3. Function to check the input for the create report function ### ===================================================================================================================
[docs]def viia_report_input_check( project: ViiaProject, report_type: str = 'TVA', governing_analysis: Optional[str] = None, scope_change_id: Optional[int] = None, werkpakket_lst: Optional[List[str]] = None) -> Tuple[str, str]: """ This function checks the required input information for generating the report. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - report_type (str): Input of the user to specify the desired report that needs to be generated. Default value is 'TVA' selecting the engineering report. - 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. - 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. Output: - Raise error messages if the inputs are incomplete/wrong, and the reporting process will be aborted. - Provides warnings if certain input is set by the function. - Returns a tuple with the report-type as string and template version as string. """ # Notification for the user that the report process starts project.write_log("Start reporting process.") # Check report-type if not isinstance(report_type, str): raise TypeError( f"ERROR: Input for the report-type for create report function should be a string, provided was " f"{report_type}.") if report_type.lower() in ['tva', 'bsc', 'er', 'engineering report']: report_type = 'engineering' elif report_type.lower() in ['opnameplan']: report_type = 'opnameplan' elif report_type.lower() in ['opname', 'opnamerapport', 'inspectierapport', 'opname rapport', 'inspectie rapport']: report_type = 'opname' elif report_type.lower() in ['beoordeling', 'evva', 'bvva', 'evva/bvva']: report_type = 'beoordeling' elif report_type.lower() in ['crm']: report_type = 'crm' elif report_type.lower() in ['bkg']: report_type = 'bkg' elif report_type.lower() in ['kostenraming']: report_type = 'kostenraming' elif report_type.lower() in ['ontwerpnotitie', 'ontwerpnotitie rapport']: report_type = 'ontwerpnotitie' elif report_type.lower() in ['uo', 'uo report']: report_type = 'uo' elif report_type.lower() in ['bevindingen', 'bevindingen rapport', 'bevindingen report']: report_type = 'bevindingen' elif report_type.lower() in ['urenmonitor', 'uren monitor']: report_type = 'urenmonitor' elif report_type.lower() == 'memo': raise ValueError("ERROR: The memo (for SBS) is not available anymore in this version of the viiaPackage.") else: raise ValueError(f"ERROR: The requested report {report_type} is unknown. Please check your input.") # Collect the tender specification from the deliverable on MYVIIA tender_specification = None if report_type != 'urenmonitor': tender_specification = viia_get_tender_specification_deliverable(project=project, report_type=report_type) # Input check for building type # Check if the building type is set correctly for the inspection and assessment report # Note that these reports are in Dutch building_type_check = False if 'building_type_simple' in project.project_information.keys(): if project.project_information['building_type_simple'] in ['woning', 'gebouw']: building_type_check = True project.write_log( f"The simplified building type is {project.project_information['building_type_simple']}.") else: warn( f"WARNING: {project.project_information['building_type_simple']} is an invalid value for " f"project.project_information['building_type_simple']. Allowed values are 'woning' and 'gebouw'. " f"Value will automatically be reselected based on building function") if not building_type_check: if 'hoofd_gebruiksfunctie' in project.project_information.keys() and \ project.project_information['hoofd_gebruiksfunctie'] is not None: if 'woon' in project.project_information['hoofd_gebruiksfunctie']: project.project_information['building_type_simple'] = 'woning' else: project.project_information['building_type_simple'] = 'gebouw' project.write_log( f"The simplified building type is {project.project_information['building_type_simple']}.") else: project.project_information['building_type_simple'] = 'gebouw' project.write_log( f"The simplified building type could not be obtained from MYVIIA. The report is generated based on " f"a building type '{project.project_information['building_type_simple']}'.") # Input check for inspection report if report_type == 'opname': # Check inspection type inspection_type_check = False if 'inspection_type' in project.project_information.keys(): if project.project_information['inspection_type'] in ['TYPO', 'LOOV', 'VAL', 'EVS2']: inspection_type_check = True if inspection_type_check: inspection_subtype = project.project_information.get('inspection_subtype', None) if inspection_subtype is None: inspection_subtype = project.project_information['inspection_type'] project.write_log( f"Start generating {inspection_subtype} inspection report. The template version is based on tender " f"specification {tender_specification}.") else: raise ValueError( f"ERROR: Inspection type of {project.name} is not 'TYPO', 'LOOV', 'VAL' or 'EVS2'. " f"Reporting is aborted for generating inspection report.") # Input checks for engineering report elif report_type == 'engineering': # Check analysis type if project.analysis_type not in ['NLTH', 'NLTH-REF']: raise ValueError( "ERROR: Reporting is aborted for generating engineering report, because the functions currently only " "support 'NLTH' and 'NLTH-REF' objects.") # Check the support type if project.analysis_type in ['NLTH'] and not project.viia_settings.support_type: raise ValueError( "ERROR: The support type (i.e. FixedBase, FlexBaseGlobal or FlexBaseFinal) is not set. The engineering " "report could not be created.") # Check analysis type on MYVIIA if project.analysis_type != project.project_information['analysis_subtype']: raise ValueError( "ERROR: The analysis-type used is different than the analysis-type on MYVIIA. This breaks " "functionality for reporting. Please request the projectleader to update MYVIIA if required. The " "engineering report could not be created.") # Check BoD version set in MYVIIA if not project.object_part or project.object_part['upr_versie'] is None: raise ValueError( "ERROR: The Basis of Design was not properly selected on MYVIIA. Make sure to specify the required BoD " "before proceeding the reporting. The engineering report could not be created.") # Check if governing analysis is given if project.analysis_type in ['NLTH']: signal_list = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'S11'] if not governing_analysis: raise ValueError( "ERROR: The governing analysis of the NLTH is not provided. Please add this input in create report " "function. The engineering report could not be created.") if governing_analysis not in signal_list: raise ValueError( f"ERROR: The governing analysis of the NLTH {governing_analysis} is incorrect. Please provide a " f"valid signal name from: {', '.join(signal_list)}. The engineering report could not be created.") # Input checks for BKG report elif report_type == 'bkg': if scope_change_id is None or not isinstance(scope_change_id, int) or scope_change_id < 1: raise ValueError( "ERROR: The scope change number is not provided properly. Please update the input. BKG report could " "not be created.") # Input checks for uren monitor report elif report_type == 'urenmonitor': if not isinstance(werkpakket_lst, list) or not all(isinstance(item, str) for item in werkpakket_lst): raise ValueError( "ERROR: The uren monitor requires a list of strings (werkpakketten) to create the report for. The uren " "monitor could not be created.") # Return the corrected report-type and tender specification return report_type, tender_specification
### =================================================================================================================== ### 4. End of script ### ===================================================================================================================