Source code for viiapackage.reporting.helper_functions.viia_get_uo_report_data

### ===================================================================================================================
###   FUNCTION: Get data for the UO report
### ===================================================================================================================
# Copyright ©VIIA 2025

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

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

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject
from viiapackage.database import myviia_get_eng_measure, myviia_get_uo_measure
from viiapackage.strengthening import GMCMeasures
from viiapackage.reporting.helper_functions.viia_get_address_info import viia_get_address_info
from viiapackage.reporting.helper_functions.viia_report_date import viia_report_date


### ===================================================================================================================
###   2. Function to collect the data required for the UO report
### ===================================================================================================================

[docs]def get_uo_report_data( project: ViiaProject, address_id: Optional[int] = None, object_part_names: Optional[List[str]] = None) -> dict: """ This function will generate dictionary keys for UO report data that can later be used as jinja tags for templating. Input - project (obj): VIIA project object containing collections of fem objects and project variables. - address_id (int): ID of the selected address in MYVIIA database. Default value is None. - object_part_names (list of str): List of names of object parts to include in the report. Default value is None. Output - Dictionary of jinja tags assigned to corresponding info. """ def get_measures(measure_type, get_measure_func, project, selected_object_parts): if not project.project_information.get(measure_type, None): measures = [] for object_part in selected_object_parts: measures.extend(get_measure_func(object_deel_id=object_part['id'], token=project.token)) context[measure_type] = measures measure_description = GMCMeasures().get_strengthening_measures(project) for measure in context[measure_type]: measure['description'] = measure_description.get(measure['name'], {}).get('description_nl', '') else: context[measure_type] = project.project_information[measure_type] # Collect the general info which is retrieved from MYVIIA at project initialisation general_info = project.project_information # Check if general info is retrieved from MYVIIA if 'id' not in general_info: project.write_log( f"WARNING: No general information is retrieved from MYVIIA database for this object. General information " f"is not replaced in the UO report.") return {} # Check address id input if not address_id: project.write_log( f"WARNING: No address id is provided as input. General information is not replaced in the design note.") return {} # Include complete object if object_part_names and 'Gehele object' not in object_part_names: object_part_names.append('Gehele object') else: object_part_names = ['Gehele object'] # Collect address to include based on user input for address selected_address = [address for address in general_info.get('object_adressen', []) if address['id'] == address_id] # Collect object parts to include based on user input for object-parts selected_object_parts = \ [object_part for object_part in general_info.get('objectdelen', []) if object_part['naam'] in object_part_names] # Collect the data for the template of the UO-report context = {} # Find project info to use in report context['objectnaam'] = project.project_information.get('objectnaam', '') context['projectnaam'] = project.project_information['opdracht_id'].get('projectnaam', '') if (object_nr := project.project_information.get('objectnummer_viia', None)) and \ 'TVA' in [deliverable['deliverable_id']['deliverable'] for deliverable in project.object_part['deliverables']]: context['documentnr_va_bureau'] = f'VIIA_{object_nr}_TVA' else: context['documentnr_va_bureau'] = 'Documentnr VA-bureau' context['npr_versie'] = project.project_information.get('npr_versie', 'ONBEKENDE NPR') context['tijdsperiode'] = project.project_information.get('reference_period', 'ONBEKENDE TIJDSPERIODE') # Collect the current date context['datum'] = viia_report_date() # Collect the address(es) and related info for the object address_string, address_list, dossier_nrs, postcode, municipality = \ viia_get_address_info(project=project, myviia_data_object_address=selected_address) context['adres'] = address_string context['plaats'] = municipality # Collect the AD references for the NCG ad_nrs = [] for address in selected_address: if address['dossiernummer_og']: ad_nrs.append(address['dossiernummer_og']) context['ad_nr'] = ', '.join(ad_nrs) # Get the engineering measures get_measures('engineering_measures', myviia_get_eng_measure, project, selected_object_parts) # Get UO fase measures get_measures('uo_measures', myviia_get_uo_measure, project, selected_object_parts) # Gather all the measure data all_measures = [ {'eng_measure_name': measure['name'], 'eng_measure_id': measure['id'], 'description': measure['description']} for measure in context['engineering_measures']] for uo_measure in context['uo_measures']: all_measure = next( (measure for measure in all_measures if measure['eng_measure_id'] == uo_measure['eng_measure_id']), None) if all_measure and uo_measure.get('status') in ['copied', 'modified']: all_measure['uo_measure_name'] = uo_measure['name'] all_measure['description'] = uo_measure['description'] elif all_measure and uo_measure.get('status') == 'removed': all_measure['uo_measure_name'] = '' elif all_measure is None and uo_measure.get('status') == 'new': all_measures.append({ 'eng_measure_name': '', 'eng_measure_id': uo_measure['eng_measure_id'], 'uo_measure_name': uo_measure['name'], 'description': uo_measure['description']}) context['all_measures'] = all_measures # Remove the removed measures from the uo measure list context['uo_measures'] = [measure for measure in context['uo_measures'] if measure['status'] != 'removed'] return context
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================