Source code for viiapackage.reporting.helper_functions.viia_get_uo_report_data

### ===================================================================================================================
###   FUNTION: Get data for the UO report
### ===================================================================================================================
# Copyright ©VIIA 2024

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

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

# 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


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

[docs]def get_uo_report_data(project: ViiaProject, extra_object_parts: 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. - extra_object_parts (list of str): List of names of extra 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, extra_object_parts): if not project.project_information.get(measure_type, None): object_deel_id = project.get_myviia_object_deel_id() measures = get_measure_func(object_deel_id=object_deel_id, token=project.token) if extra_object_parts: for object_part_name in extra_object_parts: for objectpart in project.project_information['objectdelen']: if objectpart['naam'] == object_part_name: measures.extend(get_measure_func(object_deel_id=objectpart['id'], token=project.token)) break 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 {} # 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('tijdsperiode', 'ONBEKENDE TIJDSPERIODE') # Collect the current date current_date = datetime.now() date_dict = { 1: 'januari', 2: 'februari', 3: 'maart', 4: 'april', 5: 'mei', 6: 'juni', 7: 'juli', 8: 'augustus', 9: 'september', 10: 'oktober', 11: 'november', 12: 'december'} context['datum'] = f"{current_date.day} {date_dict[current_date.month]} {current_date.year}" # 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=general_info.get('object_adressen', [])) context['adres'] = address_string context['plaats'] = municipality # Collect the AD references for the NCG ad_nrs = [] for address in general_info.get('object_adressen', []): 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, extra_object_parts) # Get UO fase measures get_measures('uo_measures', myviia_get_uo_measure, project, extra_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 ### ===================================================================================================================