Source code for viiapackage.reporting.helper_functions.viia_get_general_info

### ===================================================================================================================
###   FUNCTION: Get general info
### ===================================================================================================================
# Copyright ©VIIA 2024

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

# General imports
from __future__ import annotations
from typing import TYPE_CHECKING
from copy import deepcopy
from datetime import datetime
import math
import yaml

# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.fem_tools import fem_convert_integer_list_to_string_diana
from rhdhv_fem.tools.NPR9998_webtool import _lat_lng_to_rd

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject
from viiapackage.viiaLoads import _get_viia_importance_factor
from viiapackage.reporting.helper_functions.viia_get_address_info import viia_get_address_info


### ===================================================================================================================
###   2. viia_get_general_info
### ===================================================================================================================

[docs]def viia_get_general_info(project: ViiaProject, language: str = 'en') -> dict: """ This function will generate dictionary for general info that can later be used as jinja tags for templating. Data is mainly collected from MYVIIA webtool or derived from model. Input - project (obj): VIIA project object containing collections of fem objects and project variables. - language (str): Select the language to use for collecting general info. Default value is 'en' collecting the context in English. Output - Returns dictionary for jinja tags assigned to corresponding info. """ def _unkown_geo(item): if item is None or item == '': return 'Enter initials geotechnical advisor' return item # 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 engineering report.") return {} # Collect addresses related to object object_addresses = general_info.get('object_adressen', []) # Find if the name of the objectpart is the same as one of the addresses # If yes, only keep the address corresponding to the object part # If no, the objectpart name is not related to an address, so all addresses are outputted for adres in object_addresses: full_address = f"{adres['straatnaam']} {adres['huisnummer']} {adres['plaatsnaam']}" if full_address == general_info.get('objectdeel'): object_addresses = [adres] # 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=object_addresses) # 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'} datum = f"{current_date.day} {date_dict[current_date.month]} {current_date.year}" if general_info.get('spectra', None) is not None: spectra = {} for spectrum in general_info['spectra']: spectra[spectrum['reference_period']] = { 'ags': spectrum['ags'], 'p': spectrum['p'], 'tb': spectrum['t_b'], 'tc': spectrum['t_c'], 'td': spectrum['t_d']} # Add plateau to the spectrum info spectra[spectrum['reference_period']]['plateau'] = round( spectra[spectrum['reference_period']]['ags'] * spectra[spectrum['reference_period']]['p'], 4) # Add spectral displacement to the spectrum info spectra[spectrum['reference_period']]['spec_disp'] = round( spectra[spectrum['reference_period']]['ags'] * spectra[spectrum['reference_period']]['p'] * 0.59 * 9.807 * (spectra[spectrum['reference_period']]['td'] * spectra[spectrum['reference_period']]['tc']) / ((2 * math.pi) ** 2), 4) else: spectra = None # Get the x, y coordinates of 'rijksdriehoeksstelsel' (RD) rd_x, rd_y = _lat_lng_to_rd( lat=project.project_information['gps']['latitude'], lng=project.project_information['gps']['longitude']) # Get the version of the basis of design upr_name = 'ERROR: Unknown basis of design' upr_version = 'ERROR: Unknown version of basis of design' upr_doc = 'ERROR: Unknown doc nr BOD' if 'upr_versie' in project.object_part and project.object_part['upr_versie']: bod = project.object_part['upr_versie'] if 'NLTH-REF' in bod['upr_versie']: upr_name = 'Uitgangspuntenrapport Engineering NLTH - REF' upr_doc = 'VIIA_QE_R2191' elif 'NLTH' in bod['upr_versie']: if bod['versie'] < 7: upr_name = 'Uitgangspuntenrapport Versterkingsadvies NLTH' else: upr_name = 'Basis of Design Retrofit Advice NLTH' upr_doc = 'VIIA_QE_R376' if 'T' in bod['datum']: bod['datum'] = bod['datum'].split('T')[0] upr_version = f"Version {bod['versie']}.0, dated {bod['datum']}" consequence_class = general_info.get('consequence_class', None) importance_factor = _get_viia_importance_factor(project=project, consequence_class=consequence_class) a_g_d = None if spectra and 2475 in spectra and 'ags' in spectra[2475]: a_g_d = format(importance_factor * spectra[2475]['ags'], '.4f') context_nl = { 'datum': datum, 'dossier_nr': fem_convert_integer_list_to_string_diana(dossier_nrs), 'object_nr': general_info.get('objectnummer_viia', None), 'adres': address_string, 'adressen': address_list, 'postcode': f"{postcode[:4]} {postcode[4:]}", 'woonplaats': municipality, 'gemeente': general_info.get('gemeente_id', {}).get('naam', None), 'gebouwtype': general_info.get('object_cluster_id', {}).get('typologie', None), 'bouwjaar': general_info.get('oorspronkelijk_bouwjaar', None), 'plaatsnaam': municipality, 'tijdsperiode': general_info.get('reference_period', general_info.get('tijdsperiode', None)), 'dataset': general_info.get('dataset', None), 'PGA': general_info.get('pga', None), 'gebruiksfunctie': general_info.get('hoofd_gebruiksfunctie', None), 'building_type_simple': general_info.get('building_type_simple', None), 'erfgoedstatus': general_info.get('erfgoed_status', None), 'archeologische_waarde': general_info.get('archeologische_waarde', None), 'asbestverdacht': general_info.get('asbestverdacht', None), 'NPR_versie': general_info.get('npr_versie', None), 'NPR_year': int(general_info.get('npr_versie', "99999").split(':')[-1] or 99999), 'NEN_cluster': general_info.get('cluster_nen', None), 'gevolgklasse': consequence_class, 'importance_factor': importance_factor, 'rd_x': round(rd_x), 'rd_y': round(rd_y), 'latitude': project.project_information['gps']['latitude'], 'longitude': project.project_information['gps']['longitude'], 'spectra': spectra, 'a_g_d': a_g_d, 'hoofdconstructeurs': ', '.join(general_info['team'].get('hoofdconstructeurs_initialen', [])), 'structural_engineers': ', '.join(general_info['team'].get('constructeurs_initialen', [])), 'geotechnicus': _unkown_geo(general_info['team'].get('geotechnicus_initialen', None)), 'redacteur': general_info['team'].get('redacteur_initialen', None), 'projectleider': ', '.join(general_info['team'].get('projectleiders_initialen', [])), 'projectleider_opname': general_info['team'].get('projectleider_opname_initialen', None), 'hoofdinspecteur': general_info['team'].get('hoofdinspecteur_initialen', None), 'upr_versie': upr_version, 'upr_naam': upr_name, 'upr_doc': upr_doc, 'geotechnische_analyse': general_info.get('geotechnical_analysis', 'Unknown'), 'objectnaam': general_info.get('objectnaam', None) } missing_keys = [key for key in context_nl if not context_nl[key]] if missing_keys: project.write_log(f"WARNING: General information for [{', '.join(missing_keys)}] is missing on MYVIIA.") trans_bool = {'NL': {'True': 'Ja', 'False': 'Nee'}, 'EN': {'True': 'Yes', 'False': 'No'}} # Read yaml with template references with open(project.viia_settings.project_specific_package_location / 'general' / 'translations.yaml') as f: translations = yaml.load(f, Loader=yaml.FullLoader) # Initialise the translation dictionary context_en = deepcopy(context_nl) # Translate Dutch to English for key in context_en.keys(): if key in translations.keys() and context_en[key] in translations[key].keys(): context_en[key] = translations[key][context_en[key]] # Transform Boolean data for key in context_nl.keys(): if isinstance(context_nl[key], bool): context_nl[key] = trans_bool['NL'][str(context_nl[key])] for key in context_en.keys(): if isinstance(context_en[key], bool): context_en[key] = trans_bool['EN'][str(context_en[key])] if language == 'nl': return context_nl return context_en
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================