### ===================================================================================================================
### Functions to collect data from MYVIIA for reference objects
### ===================================================================================================================
# Copyright ©VIIA 2024
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General imports
from __future__ import annotations
import math
from typing import TYPE_CHECKING, List
# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.fem_tools import fem_convert_integer_list_to_string_diana
# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
from viiapackage.viiaStatus import ViiaProject
from viiapackage.database import myviia_get_all_eng_database, myviia_get_selected_reference_objects, \
myviia_get_spectra
### ===================================================================================================================
### 2. Function to retrieve and handle data from MYVIIA
### ===================================================================================================================
[docs]def viia_get_ref_info_from_myviia(project: ViiaProject) -> List[dict]:
"""
This function will generate dictionary keys for reference object data that can later be used as jinja tags for
templating.
.. note:: Currently only available in Dutch.
Input
- project (obj): VIIA project object containing collections of fem objects and project variables.
Output
- Dictionary of jinja tags assigned to corresponding info.
"""
# Collect the referenced objects from MYVIIA
if 'objectdelen' in project.project_information.keys():
sel_reference_objects = myviia_get_selected_reference_objects(
object_deel_id=project.get_myviia_object_deel_id(), token=project.token)
else:
sel_reference_objects = None
if not sel_reference_objects:
project.write_log(f"WARNING: No Reference objects have been selected on MYVIIA.")
return []
# Get all engineering database records from MYVIIA
eng_database = myviia_get_all_eng_database(token=project.token)
context = [
database_entry for database_entry in eng_database
if database_entry['object_deel']['id'] in
[sel_object['ref_object_deel_id'] for sel_object in sel_reference_objects]]
# Retrieve information from 'object_deel' dict in each ref object, and then remove the rest ofthe dict
for ref_object in context:
ref_object['objectnummer'] = ref_object['object_deel']['viia_object_id']['objectnummer_viia']
ref_object['objectnaam'] = ref_object['object_deel']['viia_object_id']['objectnaam']
ref_object['objectdeel_naam'] = f"{ref_object['objectnummer']} - {ref_object['object_deel']['naam']}"
ref_object['year_of_construction'] = ref_object['object_deel']['viia_object_id']['oorspronkelijk_bouwjaar']
ref_object['object_id'] = ref_object['object_deel']['viia_object_id']['id']
ref_object['typology'] = ref_object['object_deel']['viia_object_id']['object_cluster_id']['typologie']
ref_object['objectadres'] = ref_object['objectnaam'].split(ref_object['objectnummer'])[-1]
if ref_object['objectadres'][0] == ',':
ref_object['objectadres'] = ref_object['objectadres'][1:]
# Retrieve and convert MYVIIA spectra per ref object
myviia_spectra = myviia_get_spectra(object_id=ref_object['object_id'], token=project.token)
ref_object['spectra'] = {}
for spectrum in myviia_spectra:
ref_object['spectra'][spectrum['reference_period']] = {
'ags': spectrum['ags'],
'p': spectrum['p'],
'tb': spectrum['t_b'],
'tc': spectrum['t_c'],
'td': spectrum['t_d']}
ref_object['spectra'][spectrum['reference_period']]['plateau'] = round(
ref_object['spectra'][spectrum['reference_period']]['ags'] *
ref_object['spectra'][spectrum['reference_period']]['p'], 4)
ref_object['spectra'][spectrum['reference_period']]['spec_disp'] = round(
ref_object['spectra'][spectrum['reference_period']]['ags'] *
ref_object['spectra'][spectrum['reference_period']]['p'] * 0.59 * 9.807 * (
ref_object['spectra'][spectrum['reference_period']]['td'] *
ref_object['spectra'][spectrum['reference_period']]['tc']) / ((2 * math.pi) ** 2), 4)
ref_object.pop('object_deel')
# Return the collected data
return context
### ===================================================================================================================
### 3. End of script
### ===================================================================================================================