Source code for viiapackage.reporting.helper_functions.get_a1_info_from_myviia

### ===================================================================================================================
###   FUNCTION: Collect A1 analysis data from MYVIIA for NLTH objects
### ===================================================================================================================
# Copyright ©VIIA 2024

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

# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, Dict, Union

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


### ===================================================================================================================
###   2. Function to retrieve and handle data from MYVIIA
### ===================================================================================================================

[docs]def viia_get_a1_info_from_myviia(project: ViiaProject, language: str = 'EN') -> Dict[str, Union[str, float]]: """ This function generates dictionary with data that can be used in reporting the results of the A1 analysis for NLTH. 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 - Dictionary of jinja tags assigned to corresponding info which is retrieved from A1 analysis on MYVIIA. """ # Collect data from MYVIIA, expects possible multiple entries a1_results = [] if 'test-' != project.name[:5]: a1_results = myviia_get_a1_results(object_deel_id=project.get_myviia_object_deel_id(), token=project.token) # If no data present or no data could be retrieved if not a1_results: project.write_log( "WARNING: A1 results could not be retrieved from MYVIIA. They will not be automatically filled in during " "reporting.") if language == 'NL': return {'mass_of_building': 'ONBEKEND'} else: return {'mass_of_building': 'UNKNOWN'} # If data was retrieved filter for latest date entry and then by ID latest_a1 = sorted(a1_results, key=lambda d: (d['date'], d['id']))[-1] return {'mass_of_building': latest_a1['weight_of_building'] / project.gravitational_acceleration}
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================